Accept Payments and Save Payment Methods
Set up online payments and save payment methods with GETTRX's SDK and APIs. Embed a form, process payments securely, and link details to the customer.
How it works:
- Collect Payment Details and Consent: Use GETTRX One JS SDK to capture and tokenize payment 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 a customer and link their payment method details when you finalize the payment. - Finalize Payment (
server-side
): Use GETTRX One’s APIs to process payments with the tokenized details and include the customer to automatically save the payment method.
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 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 Details and Consent:
The GETTRX One JS SDK embeds a payment form on your page to securely collect payment 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. Finalize Payment (server-side
):
server-side
):Once the PaymentToken
and the Customer
are created, the last step is to complete the payment by creating a PaymentRequest
from your server.
Use GETTRX One’s Create a Payment API to create a PaymentRequest
with the PaymentToken
created in your UI, the Customer
created in the previous step, the currency
and an amount
.
If the API request is successful you will receive a PaymentRequest
object with all the payment details, 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/payment-requests \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'secretKey: sk_your_secret_key' \
--data '
{
"amount": 100,
"currency": "usd",
"paymentToken": "pt_your_payment_token",
"setupFutureUsage": "off_session,
"customer": "cus_the_customer_ID_from_the_previous_step"
}
'
We recommend you to save in your database the "payment method ID" and "customer ID" received in the payment-request response. This will allow you to easily retrieve it to run future transactions.
Congratulations 🎉
You've successfully integrated GETTRX's SDKs and APIs for online payments. This means:
- Secure Payment Collection: You can securely collect payment details with customer consent for future use.
- Streamlined Payments: Saved payment methods are automatically attached to customers while finalizing the payment.
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