Skip to main content

Save card

Learn how to enable save card functionality for later use.

You can provide your mobile app users with the ability to save their card information securely for future use. This allows users to choose a preferred payment method, reducing their need to enter card information repeatedly. This is a nice-to-have, but optional feature for your app.

The following gif is a demonstration of this feature in a mobile app.

Enabling save card

To enable save card functionality in your app, do the following:

info
  • Dojo understands that each app is built differently. The steps listed serve as a good reference to build this feature into your app.
  • user and customer might be used interchangeably in this guide except for customer API endpoints.

Step 1: Ensure you have a customer ID

  • If you don’t have a Dojo user to link to your backend user, create a new one using POST /customers.
  • If you already have a customerId, retrieve it.
info
  • Don't create a new customer for each transaction. This avoids customers from accessing their saved cards.

Step 2: Authorize your app to retrieve customer’s saved cards

For mobile SDK to retrieve information about saved cards for a specific user, you must create and pass a customer secret using POST /customers/{customerId}/create-secret.

info
  • To create a customer secret, ensure you have a customerId from step 1 and, your API Key.
  • You must always create a customer secret in your backend and then pass it to your app.
  • Never store sensitive data such as API Keys inside your app.
  • Customer secret is short-lived, hence Dojo recommends creating a new one each time your app might need to access stored payment methods.

The following code samples demonstrate how to create a customer secret.

create-customer-secret.py
# The sandbox API key passed in 'authorization' is public.
# Don't submit any personally identifiable information in any requests made with this key.
# Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
# for secure testing.

import http.client
import json

conn = http.client.HTTPSConnection("api.dojo.tech")
payload = ''
headers = {
'Version': '2024-02-05',
'Content-Type': 'application/json',
'Authorization': 'Basic sk_sandbox_c8oLGaI__msxsXbpBDpdtwJEz_eIhfQoKHmedqgZPCdBx59zpKZLSk8OPLT0cZolbeuYJSBvzDVVsYvtpo5RkQ'
}
conn.request("POST", "/customers/cust_sandbox_6g-HvPv6VkG_Q_PXCpJqmw/create-secret", payload, headers) #"/customers/{customer-secret id you created}/create-secret
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
conn.close()

Step 3: Create a payment intent linked to the customerId

When creating a payment intent, pass the customerId to the payment intent request body.

"customer": {
"customerId": "cust_sandbox_9WibJ2zeMU2C9gkRnDgs1g"
}

Step 4: Initiate payment flow in the app

Pass the paymentIntentId and customer secret to your app. Then, pass them to the SDK to start the checkout process.

create-customer-secret.kts
// Get the PaymentHandler
val dojoPayUI =
DojoSDKDropInUI.createUIPaymentHandler(this) { result ->
// Handle result
Toast.makeText(this, result.name, Toast.LENGTH_SHORT).show()
}

// On "Pay" tapped
dojoPayUI.startPaymentFlow(
DojoPaymentFlowParams(
paymentId = "<paymentIntentId>",
clientSecret = "<secret>"// Customer secret key
)
)

Step 5: Receive payment status

Once payment is completed, the app receives a notification with a numerical code representing the result. Visit the status codes reference for more information about what each code means. Additionally, your backend will receive a notification via Webhook.