# 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[​](#1-generate-payment-token "Direct link to 1. Generate payment token")

### When you create a payment `Server-side`[​](#when-you-create-a-payment-server-side "Direct link to when-you-create-a-payment-server-side")

<!-- -->

* cURL
* Node.js
* PHP

POST https\://api.monei.com/v1/payments

```
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"

}'
```

server.js

```
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'

});
```

server.php

```
$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](https://docs.monei.com/apis/rest/.md).

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`[​](#when-you-confirm-a-payment-server-side "Direct link to when-you-confirm-a-payment-server-side")

* cURL
* Node.js
* PHP

POST https\://api.monei.com/v1/payments/:id/confirm

```
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

}'
```

server.js

```
const {Monei} = require('@monei-js/node-sdk');

const monei = new Monei('pk_test_36cf3e8a15eff3f5be983562ea6b13ec');

monei.payments.confirm({

  paymentToken: '7cc38b08ff471ccd313ad62b23b9f362b107560b',

  generatePaymentToken: true

});
```

server.php

```
$monei = new Monei\MoneiClient('pk_test_36cf3e8a15eff3f5be983562ea6b13ec');

$monei->payments->confirm(

  '832b77d1a4b372349a7ae0bb1b2af059',

  [

    'paymentToken' => '7cc38b08ff471ccd313ad62b23b9f362b107560b',

    'generatePaymentToken' => true

  ]

);
```

Check all available [request parameters](https://docs.monei.com/apis/rest/payments-confirm/.md).

### When you submit a payment form `Client-side`[​](#when-you-submit-a-payment-form-client-side "Direct link to 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.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](https://docs.monei.com/payment-methods/card/.md) integration for more details.

## 2. Obtain and store payment token[​](#2-obtain-and-store-payment-token "Direct link to 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](https://docs.monei.com/apis/rest/payments-get/.md) endpoint.

Store this `paymentToken` in your database along with customer information. Next time the customer does a purchase, [create a payment](https://docs.monei.com/apis/rest/payments-create/.md) 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](https://docs.monei.com/apis/rest/payments-get/.md) endpoint to retrieve the token. Generated **paymentToken** does not expire and should only be used **server-side**.
