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.

1. Generate payment token

When you create a payment Server-side

POST https://api.monei.net/v1/payments
curl --request POST 'https://api.monei.net/v1/payments' \
--header 'Authorization: pk_test_3c140607778e1217f56ccb8b50540e00' \
--header 'Content-Type: application/json' \
--data-raw '{
"amount": 110,
"currency": "EUR",
"orderId": "14379133960355",
"generatePaymentToken": true,
"callbackUrl": "https://mysite.com/checkout/callback",
"completeUrl": "https://mysite.com/checkout/complete"
}'

Check all available request parameters.

When you confirm a payment Server-side

POST https://api.monei.net/v1/payments/:id/confirm
curl --request POST 'https://api.monei.net/v1/payments/26d1f09c42bb59a29b06e280f9553cd5/confirm' \
--header 'Authorization: pk_test_3c140607778e1217f56ccb8b50540e00' \
--header 'Content-Type: application/json' \
--data-raw '{
"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.

checkout.html
<form
action="https://secure.monei.net/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 Accept a card payment integration for more details.

2. Obtain and store payment token

After the payment is completed a customer is redirected to the completeUrl with payment_id query parameter, you can obtain permanent paymentToken by calling get payment endpoint.

MONEI will notify you about a payment status by sending an HTTP POST request to the callbackUrl. The request body will contain full payment object in JSON format including permanent paymentToken.

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

Generated paymentToken does not expire and should only be used server-side.