Save payment method
To save a payment method for the future use you need to generate paymentToken
when you create or confirm the payment and then save it on your server. This process is often called tokenization.
Tokenization protects sensitive data through a process of replacing the data with a non-sensitive equivalent, known as a token. The token has no external significance or value. It’s a reference — or identifier — that through a tokenization system, maps back to the sensitive data. This process securely collects sensitive card information and prevents data theft.
1. Generate payment token
When you create a payment Server-side
- cURL
- Node.js
- PHP
curl --request POST 'https://api.monei.com/v1/payments' \
--header 'Authorization: pk_test_3c140607778e1217f56ccb8b50540e00' \
--header 'Content-Type: application/json' \
--data-raw '{
"amount": 110,
"currency": "EUR",
"orderId": "14379133960355",
"generatePaymentToken": true,
"callbackUrl": "https://example.com/checkout/callback",
"completeUrl": "https://example.com/checkout/complete"
}'
const {Monei} = require('@monei-js/node-sdk');
const monei = new Monei('pk_test_36cf3e8a15eff3f5be983562ea6b13ec');
monei.payments.create({
amount: 110,
currency: 'EUR',
orderId: '14379133960355',
generatePaymentToken: true,
callbackUrl: 'https://example.com/checkout/callback',
completeUrl: 'https://example.com/checkout/complete'
});
$monei = new Monei\MoneiClient('pk_test_36cf3e8a15eff3f5be983562ea6b13ec');
$monei->payments->create([
'amount' => 110,
'currency' => 'EUR'
'orderId' => '14379133960355',
'generatePaymentToken' => true,
'callbackUrl' => 'https://example.com/checkout/callback',
'completeUrl' => 'https://example.com/checkout/complete'
]);
Check all available request parameters.
note
To retrieve the payment token for future use without charging your customer, create a payment with the following parameters:
{
"amount": 0,
"currency": "EUR",
"orderId": "14379133960355",
"transactionType": "VERIF",
"generatePaymentToken": true,
"callbackUrl": "https://example.com/checkout/callback",
"completeUrl": "https://example.com/checkout/complete"
}
When you confirm a payment Server-side
- cURL
- Node.js
- PHP
curl --request POST 'https://api.monei.com/v1/payments/26d1f09c42bb59a29b06e280f9553cd5/confirm' \
--header 'Authorization: pk_test_3c140607778e1217f56ccb8b50540e00' \
--header 'Content-Type: application/json' \
--data-raw '{
"paymentToken": "7cc38b08ff471ccd313ad62b23b9f362b107560b",
"generatePaymentToken": true
}'
const {Monei} = require('@monei-js/node-sdk');
const monei = new Monei('pk_test_36cf3e8a15eff3f5be983562ea6b13ec');
monei.payments.confirm({
paymentToken: '7cc38b08ff471ccd313ad62b23b9f362b107560b',
generatePaymentToken: true
});
$monei = new Monei\MoneiClient('pk_test_36cf3e8a15eff3f5be983562ea6b13ec');
$monei->payments->confirm(
'832b77d1a4b372349a7ae0bb1b2af059',
[
'paymentToken' => '7cc38b08ff471ccd313ad62b23b9f362b107560b',
'generatePaymentToken' => true
]
);
Check all available request parameters.
When you submit a payment form Client-side
You can pass generatePaymentToken: true
when you submit a payment form. This is useful for allowing your customers to select if they want to save payment method for future use.
<form
action="https://secure.monei.com/payments/{{payment_id}}/confirm"
method="post"
id="payment-form"
>
<div class="card-field">
<div id="card-input">
<!-- A MONEI Card Input Component will be inserted here. -->
</div>
<!-- Used to display card errors. -->
<div id="card-error"></div>
</div>
<label>
<!-- A checkbox to save payment method -->
<input type="checkbox" name="generatePaymentToken" value="true" />
save payment method
</label>
<button type="submit" id="payment-button">Submit payment</button>
</form>
Check card payment method integration for more details.
2. Obtain and store payment token
After the payment is completed the customer is redirected to the completeUrl
with payment_id query parameter, you can obtain permanent paymentToken
by calling get payment endpoint.
Store this paymentToken
in your database along with customer information. Next time the customer does a purchase, create a payment with this token to skip payment form. Keep in mind that the customer will still need to complete 3d secure verification.
note
MONEI will not return paymentToken in the HTTP POST request to the callbackUrl for security reasons. You have to call get payment endpoint to retrieve the token. Generated paymentToken does not expire and should only be used server-side.