Save Payment Methods For Later Use
Save payment methods for later use with GETTRX's SDK and APIs. Embed a form to collect payment details and link them to your customer for later use.
How it works:
- Collect Payment Method Details and Consent: Use GETTRX One JS SDK to capture and tokenize payment method details, ensuring explicit customer consent to save their payment method for future use.
- Create a Customer (
server-side
): Use GETTRX One's API to create the customer to save their payment method details to. - Save Payment Method Details (
server-side
): Use GETTRX One’s APIs to save the tokenized payment method details along with the customer.
Compliance:
When saving a customer’s payment information, it’s crucial to adhere to all applicable laws, regulations, and network rules. This is necessary if you intend to store a customer’s payment method for future transactions, like displaying it during the checkout process or charging them when they're not using your site or app.
Ensure your site or app includes clear terms that explain your intentions for saving payment details and provide an opt-in option for customers.You are permitted to use the saved payment method only for the specified purposes outlined in your terms. If you plan to charge a customer when they are not online or save their payment method for future use, it’s important to obtain explicit consent. For instance, include a “Save my payment method for future use” checkbox or button to capture this consent.
To charge a customer while they are offline, your terms should cover the following points:
- The customer’s authorization for you to initiate a payment or a series of payments on their behalf for specific transactions.
- The expected schedule and frequency of payments (e.g., scheduled installments, or subscription payments).
- The method for determining the payment amount.
- The cancellation policy if the payment method is linked to a subscription service.
Maintain a record of the customer’s written consent to these terms.
1. Collect Payment Method Details and Consent:
The GETTRX One JS SDK embeds a payment form on your page to securely collect payment method details and customer consent to save payment methods for future use. Once collected, GETTRX tokenizes the sensitive info and creates a PaymentToken
. Check out the code sample below to see how to create a PaymentToken
:
Tip:
Run the code sample locally to generate Payment Tokens for your account.
2. Create a Customer (server-side
):
server-side
):Once the PaymentToken
is created, create the customer to link to the saved payment method.
Use GETTRX One’s Create a Customer API to create a Customer
and save the Customer ID
for the next step.
curl --request POST \
--url https://api-dev.gettrx.com/payments/v1/customers \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'secretKey: sk_your_secret_key' \
--data '
{
"name": "John Doe"
}
'
3. Save Payment Method Details (server-side
):
server-side
):Once the PaymentToken
and the Customer
are created, the last step is to save the payment method by creating a SetupRequest
from your server.
Use GETTRX One’s Create a Payment Method API to create a SetupRequest
with the PaymentToken
created in your UI, the Customer
created in the previous step, and the usage
.
The usage
depends on how you'll use the saved payment method details in the future.
- Use
off_session
for payments when the customer isn't involved in the checkout process (like recurring payments). - Use
on_session
for payments when the customer is actively part of the checkout process and selects the saved payment method to complete the payment.
If the API request is successful you will receive a SetupRequest
object including the Payment Method ID
for future use. if it is not, you will receive an Error
response indicating why the transaction was not processed.
curl --request POST \
--url https://api-dev.gettrx.com/payments/v1/setup-requests \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'secretKey: sk_your_secret_key' \
--data '
{
"paymentToken": "pt_your_payment_token",
"customer": "cus_the_customer_ID_from_the_previous_step"
"usage": "off_session
}
'
Congratulations 🎉
You've successfully integrated GETTRX's SDKs and APIs for online payments. This means:
- Secure Payment Method Collection: You can securely collect payment method details with customer consent for future use.
- Streamlined Payments: Saved payment methods are automatically attached to customers and are ready to be used in the future.
Now that the integration is set up, you can focus on building a smooth payment experience for your users. Happy coding!
Updated 3 months ago