***

title: Use our gateway
icon: hand-holding-usd
published: true
intro: Create a payment plan to take repeat payments.
---------------------

For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://docs.payroc.com/full-stack-guides/take-payments/repeat-payments/llms.txt. For full documentation content, see https://docs.payroc.com/full-stack-guides/take-payments/repeat-payments/llms-full.txt.

A merchant can use our gateway to take repeat payments from their customers. To set up repeat payments from a customer, a merchant must complete the following steps:

1. Create a payment plan.
2. Save the customer’s details.
3. Use a subscription to assign the customer to the payment plan.
4. Take the payments.

A payment plan is a template that describes how the merchant takes payments from their customers, including the following information:

* Number of payments
* Length of the payment plan
* Amount for each payment
* How often payments are taken
* Initial costs
* Whether to automatically collect payments or manually collect payments

A merchant can create multiple payment plans and assign multiple customers to each plan. For example, if the merchant wants to allow customers to pay in weekly installments or in monthly installments, the merchant creates a payment plan for each installment schedule. The merchant can then offer customers a choice of payment plans, and then use subscriptions to assign customers to the plans that they choose.

If the merchant chooses to automatically collect payments, our gateway collects payments from each customer. If the merchant chooses to manually collect payments, they need to use their POS to collect the payments.

## Integration steps

To use our gateway to take regular payments, integrate with the following:

**Step 1.** Create a payment plan.\
**Step 2.** Create a secure token.\
**Step 3.** Create a subscription.\
**Step 4.** (Optional) Manually collect a payment from the customer.

## Before you begin

### Bearer tokens

Use our Identity Service to generate a Bearer token to include in the header of your requests. To generate a Bearer token, complete the following steps:

1. Include your API key in the x-api-key parameter in the header of a POST request.
2. Send your request to [https://identity.payroc.com/authorize](https://identity.payroc.com/authorize).

<Note>
  **Note:** You need to generate a new Bearer token before the previous Bearer token expires.
</Note>

#### Example request

```bash
curl --location --request POST  'https://identity.payroc.com/authorize' --header 'x-api-key: <api key>'
```

If your request is successful, we return a response that contains your Bearer token, information about its scope, and when it expires.

#### Example response

```json
{
  "access_token": "eyJhbGc....adQssw5c",
  "expires_in": 3600,
  "scope": "service_a service_b",
  "token_type": "Bearer"
}
```

### Headers

To create the header of each POST request, you must include the following parameters:

* **Content-Type:** Include application/json as the value for this parameter.
* **Authorization:** Include your Bearer token in this parameter.
* **Idempotency-Key:** Include a UUID v4 to make the request idempotent.

```bash
curl
-H "Content-Type: application/json"
-H "Authorization: <Bearer token>"
-H "Idempotency-Key: <UUID v4>"
```

### Errors

If your request is unsuccessful, we return an error. For more information about errors, see [Errors](/api/errors).

## Step 1. Create a payment plan

To create a payment plan, send a POST request to our Payment Plans endpoint:

| Endpoint   | Prefix     | URL                                                                                                                                                                                  |
| :--------- | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Test       | `api.uat.` | [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/payment-plans](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/payment-plans) |
| Production | `api.`     | [https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/payment-plans](https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/payment-plans)         |

<Note>
  **Note:** To allow merchants to add their own information to the payment plan, use custom fields. For more information about how to add custom fields, go to [Add custom fields to your integration](/guides/take-payments/add-custom-fields).
</Note>

### Request parameters

To create the body of your request, use the following parameters:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/payment-plans" selector="request.body" />

### Example request

<EndpointRequestSnippet endpoint="POST /processing-terminals/{processingTerminalId}/payment-plans" />

### Response fields

If your request is successful, we create the payment plan and return a response. The response contains the following fields:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/payment-plans" selector="response.body" />

### Example response

<EndpointResponseSnippet endpoint="POST /processing-terminals/{processingTerminalId}/payment-plans" example="createdPaymentPlan" />

## Step 2. Create a secure token

Before you can assign a customer to a payment plan, save their payment details and create a secure token.

To save the customer’s payment details, send a POST request to our Secure Tokens endpoint.

| Endpoint   | Prefix     | URL                                                                                                                                                                                  |
| :--------- | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Test       | `api.uat.` | [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/secure-tokens](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/secure-tokens) |
| Production | `api.`     | [https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/secure-tokens](https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/secure-tokens)         |

<Note>
  **Note:** We assign the secure token to the terminal that sent the request. Depending on the merchant’s account settings, other terminals within the merchant’s account can also use the secure token.
</Note>

### Request parameters

To create the body of your request, use the following parameters:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/secure-tokens" selector="request.body" />

### Example request

<EndpointRequestSnippet endpoint="POST /processing-terminals/{processingTerminalId}/secure-tokens" />

### Response fields

If your request is successful, we store the customer’s payment details and return a response. The response contains the following fields:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/secure-tokens" selector="response.body" />

### Example response

<EndpointResponseSnippet endpoint="POST /processing-terminals/{processingTerminalId}/secure-tokens" example="createdSecureToken" />

## Step 3. Create a subscription

To assign a customer to a payment plan, send a POST request to our Subscriptions endpoint. You can also use this request to personalize the payment plan for each customer, for example, provide a discount on each payment or add a one-off setup fee.

| Endpoint   | Prefix     | URL                                                                                                                                                                                  |
| :--------- | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Test       | `api.uat.` | [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions) |
| Production | `api.`     | [https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions](https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions)         |

### Request parameters

To create the body of your request, use the following parameters:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/subscriptions" selector="request.body" />

### Example request

<EndpointRequestSnippet endpoint="POST /processing-terminals/{processingTerminalId}/subscriptions" />

### Response fields

If your request is successful, we assign the customer to the payment plan and return a response. The response contains the following fields:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/subscriptions" selector="response.body" />

### Example response

<EndpointResponseSnippet endpoint="POST /processing-terminals/{processingTerminalId}/subscriptions" example="createdSubscription" />

## Step 4. (Optional) Manually collect a payment

The merchant can choose to let our gateway automatically collect payments, or the merchant can manually collect payments. If the merchant chooses to manually collect payments, you must send a request every time the merchant wants to collect a payment from the customer.

To manually collect a payment from a customer, send a POST request to the Subscriptions endpoint.

| Endpoint   | Prefix     | URL                                                                                                                                                                                                                              |
| :--------- | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Test       | `api.uat.` | [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions/\{subscriptionId}/pay](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions/\{subscriptionId}/pay) |
| Production | `api.`     | [https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions/\{subscriptionId}/pay](https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions/\{subscriptionId}/pay)         |

### Request parameters

To create the body of your request, use the following parameters:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/subscriptions/{subscriptionId}/pay" selector="request.body" />

### Example request

<EndpointRequestSnippet endpoint="POST /processing-terminals/{processingTerminalId}/subscriptions/{subscriptionId}/pay" />

### Response fields

If your request is successful, we take the payment from the customer and return a response. The response contains the following fields:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/subscriptions/{subscriptionId}/pay" selector="response.body" />

### Example response

<EndpointResponseSnippet endpoint="POST /processing-terminals/{processingTerminalId}/subscriptions/{subscriptionId}/pay" example="subscriptionPaymentResponse" />

## Test cases

Before you run test cases, read the [Payments](/test/test-your-integration/payments) page in Test Your Integration.

### Create a payment plan

Send a POST request to the following endpoint:

POST [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/payment-plans](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/payment-plans)

**Example response**

```json
{
	"paymentPlanId": "PaymentPlanTest",
	"processingTerminalId": "3204001",
	"name": "Davi Crisostomo",
	"description": "Payment Plan creation",
	"currency": "USD",
	"setupOrder": {
		"amount": 11000,
		"description": "Setup Amount"
	},
	"length": 24,
	"type": "manual",
	"frequency": "monthly",
	"onUpdate": "update",
	"onDelete": "complete"
}

```

### Create a secure token

Send a POST request to the following endpoint:

POST [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/secure-tokens](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/secure-tokens)

**Example response**

```json
{
	"secureTokenId": "MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA",
	"processingTerminalId": "3204001",
	"source": {
		"type": "card",
		"cardholderName": "",
		"cardNumber": "444433******1111",
		"expiryDate": "1226"
	},
	"token": "2967538502417872",
	"status": "cvv_validated"
}

```

### Create a subscription for a payment plan

Send a POST request to the following endpoint:

POST [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions)

**Example response**

```json
{
	"subscriptionId": "SubTest",
	"processingTerminalId": "3204001",
	"paymentPlan": {
		"paymentPlanId": "PaymentPlanTest",
		"name": "Davi Crisostomo",
		"link": {
			"rel": "self",
			"method": "GET",
			"href": "https://api.uat.payroc.com/v1/processing-terminals/3204001/payment-plans/PaymentPlanTest"
		}
	},
	"secureToken": {
		"secureTokenId": "MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA",
		"customerName": "",
		"token": "2967538502417872",
		"status": "cvv_validated",
		"link": {
			"rel": "self",
			"method": "GET",
			"href": "https://api.uat.payroc.com/v1/processing-terminals/3204001/secure-tokens/MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA"
		}
	},
	"name": "Davi Crisostomo",
	"description": "Create Subscription from ICC payment",
	"currency": "USD",
	"setupOrder": {
		"orderId": "TheOrderID",
		"amount": 11000,
		"description": "Desription of SETUPORDER"
	},
	"recurringOrder": {
		"amount": 11000,
		"description": "RECURRING Order price"
	},
	"currentState": {
		"status": "active",
		"nextDueDate": "2023-08-02",
		"paidInvoices": 0,
		"outstandingInvoices": 122
	},
	"startDate": "2023-08-02",
	"endDate": "2025-12-02",
	"length": 24,
	"type": "automatic",
	"frequency": "weekly",
	"pauseCollectionFor": 0
}

```

### Manually pay a subscription

Send a POST request to the following endpoint:

POST [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions/\{subscriptionId}/pay](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/subscriptions/\{subscriptionId}/pay)

**Example response**

```json
{
	"paymentId": "KOHM1D3EZH",
	"processingTerminalId": "3204001",
	"operator": "Davi Crisostomo",
	"order": {
		"orderId": "UniqueValueForOrderID",
		"dateTime": "2023-06-20T20:25:57.641+01:00",
		"description": "Subscription Payment - Manual",
		"amount": 11000,
		"currency": "USD"
	},
	"card": {
		"type": "Visa Credit",
		"entryMethod": "keyed",
		"cardNumber": "444433******1111",
		"expiryDate": "1226",
		"secureToken": {
			"secureTokenId": "MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA",
			"customerName": "",
			"token": "2967538502417872",
			"status": "cvv_validated",
			"link": {
				"rel": "self",
				"method": "GET",
				"href": "https://api.uat.payroc.com/v1/processing-terminals/3204001/secure-tokens/MREF_1a93f3a6-9029-419f-9e87-3e2db6f0ae85uA"
			}
		},
		"securityChecks": {
			"cvvResult": "M",
			"avsResult": "Y"
		}
	},
	"transactionResult": {
		"type": "sale",
		"status": "ready",
		"approvalCode": "OK24225",
		"authorizedAmount": 11000,
		"currency": "USD",
		"responseCode": "A",
		"responseMessage": "OK24225",
		"cardSchemeReferenceId": "nkMX2G7ZqPavgbYiYacQ"
	}
}
```