Tutorial: Make a non-sweeping variable recurring payment

Yapily Variable Recurring Payments is available as a Private Beta version.

Introduction

This tutorial explains how to create a UK domestic non-sweeping variable recurring payment with the Natwest Sandbox.

Note: All requests made to the Yapily API require basic authentication.


1. Select bank

To find which banks support non-sweeping variable recurring payments use GET institutions to retrieve the list of your supported institutions.

Request:

Copy
Copied
curl -L -X GET 'https://api.yapily.com/institutions/natwest-sandbox-vrp' \
  -u 'APPLICATION_KEY:APPLICATION_SECRET'

Response:

Copy
Copied
{
	"meta": {
		"tracingId": "acbb76db4ab8f4ac7f039d000456c13f",
		"count": 1
	},
	"data": [
		{
			"id": "natwest-sandbox-vrp",
			"name": "Natwest VRP Sandbox",
			"fullName": "Natwest VRP Sandbox",
			"countries": [
				{
					"displayName": "United Kingdom",
					"countryCode2": "GB"
				}
			],
			"environmentType": "LIVE",
			"credentialsType": "OPEN_BANKING_UK_AUTO",
			"media": [
				{
					"source": "https://images.yapily.com/image/e7bab90f-f77e-47c0-878f-3efa60b72205",
					"type": "logo"
				},
				{
					"source": "https://images.yapily.com/image/4c28e551-1a56-4631-be2c-260105ba687b",
					"type": "icon"
				}
			],
			"features": [
				"INITIATE_DOMESTIC_SCHEDULED_PAYMENT",
				"READ_DOMESTIC_SINGLE_REFUND",
				"ACCOUNT_REQUEST_DETAILS",
				"CREATE_DOMESTIC_PERIODIC_PAYMENT",
				"VARIABLE_RECURRING_PAYMENT_FUNDS_CONFIRMATION",
				"INITIATE_ACCOUNT_REQUEST",
				"OPEN_DATA_ATMS",
				"ACCOUNT_TRANSACTIONS_WITH_MERCHANT",
				"CREATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_SWEEPING",
				"ACCOUNT_PERIODIC_PAYMENTS",
				"ACCOUNT_DIRECT_DEBITS",
				"READ_DOMESTIC_SCHEDULED_REFUND",
				"ACCOUNT",
				"CREATE_SINGLE_PAYMENT_SORTCODE",
				"INITIATE_DOMESTIC_PERIODIC_PAYMENT",
				"ACCOUNTS",
				"ACCOUNT_BENEFICIARIES",
				"EXISTING_PAYMENT_INITIATION_DETAILS",
				"CREATE_BULK_PAYMENT",
				"INITIATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_NONSWEEPING",
				"CREATE_DOMESTIC_SCHEDULED_PAYMENT",
				"INITIATE_SINGLE_PAYMENT_SORTCODE",
				"EXISTING_PAYMENTS_DETAILS",
				"CREATE_DOMESTIC_SINGLE_PAYMENT",
				"INITIATE_DOMESTIC_SINGLE_PAYMENT",
				"ACCOUNT_TRANSACTIONS",
				"INITIATE_BULK_PAYMENT",
				"INITIATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_SWEEPING",
				"READ_DOMESTIC_PERIODIC_PAYMENT_REFUND",
				"CREATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_NONSWEEPING"
			]
		}
	]
}

Filter the list for all institutions that support the feature CREATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_NONSWEEPING.Then display these institutions in your application so the user can select which bank to make the payment from.

Once the user selects a bank, store the id of the institution to use in step 2.


2. Authorise

Execute create non-sweeping authorisation, including the institution ID, control parameters, initiation details and your callback URL.

Note: Yapily Connect customers must also provide payer details in the complianceData object to meet compliance requirements.

Request:

Copy
Copied
curl -L -X POST 'https://api.yapily.com/variable-recurring-payments/non-sweeping/consents' \
  -H 'Content-Type: application/json' \
  -u 'APPLICATION_KEY:APPLICATION_SECRET' \
  -d '{
      "applicationUserId": "variable-recurring-payment-tutorial",
      "institutionId": "natwest-sandbox-vrp",
      "callback": "https://display-parameters.com/",
      "controlParameters" : {
        "maxCumulativeNumberOfPayments" : "12",
        "maxCumulativeAmount" : {
            "amount" : "1200",
            "currency" : "GBP"
        },
        "maxAmountPerPayment" : {
            "amount" : "100",
            "currency" : "GBP"
        },
        "psuAuthenticationMethods" : ["SCA_NOT_REQUIRED"],
        "periodicLimits" : [
            {
                "frequency" : "MONTHLY",
                "alignment" : "CALENDAR",
                "totalMaxAmount" : {
                    "amount" : "100",
                    "currency" : "GBP"
                },
                "maxNumberOfPayments" : "2"
            },
            {
                "frequency" : "YEARLY",
                "alignment" : "CALENDAR",
                "totalMaxAmount" : {
                    "amount" : "1200",
                    "currency" : "GBP"
                },
                "maxNumberOfPayments" : "12"
            }
        ]
      },
      "initiationDetails": {
        "paymentIdempotencyId": "{uniqueValue}",
        "reference": "Subscription",
        "contextType": "BILL",
        "payee": {
            "name": "NETFLIX",
            "accountIdentifications": [
                {
                    "type": "SORT_CODE",
                    "identification": "{sortCode}"
                },
                {
                    "type": "ACCOUNT_NUMBER",
                    "identification": "{accountNumber}"
                }
            ]
        }
      },
      "complianceData": {
        "payer": {
            "type": "INDIVIDUAL",
            "individual": {
                "name": "John Doe",
                "birthDate": "2000-08-12"
            }
        }
      }
   }'

Response:

Copy
Copied
{
  "meta": {
    "tracingId": "611f74cb4f3205d983ebb2fca59d0847"
  },
  "data": {
    "id": "9a14e525-044d-4bfe-8c02-e0167fe4fd77",
    "applicationUserId": "variable-recurring-payment-tutorial",
    "institutionId": "natwest-sandbox-vrp",
    "status": "AWAITING_AUTHORIZATION",
    "createdAt": "2021-03-22T12:29:49.515Z",
    "featureScope": [
        "EXISTING_PAYMENTS_DETAILS",
        "EXISTING_PAYMENT_INITIATION_DETAILS",
        "VARIABLE_RECURRING_PAYMENT_FUNDS_CONFIRMATION",
        "CREATE_DOMESTIC_VARIABLE_RECURRING_PAYMENT_NONSWEEPING"
    ],
    "state": "dp2d4d33-1b9f-4f60-b6bc-2159f83f3c88",
    "institutionConsentId": "VRP-89b98300-7580-4af3-b163-786243c4a124",
    "authorisationUrl": "{authorisationUrl}",
    "qrCodeUrl": "https://images.yapily.com/image/55b6b6bc-daa8-490c-89e1-243156868e00/1614763426?size=0",
    "controlParameters" : {
        "maxCumulativeNumberOfPayments" : "12",
        "maxCumulativeAmount" : {
            "amount" : "1200",
            "currency" : "GBP"
        },
        "maxAmountPerPayment" : {
            "amount" : "100",
            "currency" : "GBP"
        },
        "psuAuthenticationMethods" : ["SCA_NOT_REQUIRED"],
        "periodicLimits" : [
            {
                "frequency" : "MONTHLY",
                "alignment" : "CALENDAR",
                "totalMaxAmount" : {
                    "amount" : "100",
                    "currency" : "GBP"
                },
                "maxNumberOfPayments" : "2"
            },
            {
                "frequency" : "YEARLY",
                "alignment" : "CALENDAR",
                "totalMaxAmount" : {
                    "amount" : "1200",
                    "currency" : "GBP"
                },
                "maxNumberOfPayments" : "12"
            }
        ]
      },
      "initiationDetails": {
        "paymentIdempotencyId": "{uniqueValue}",
        "reference": "Subscription",
        "contextType": "BILL",
        "payee": {
            "name": "NETFLIX",
            "accountIdentifications": [
                {
                    "type": "SORT_CODE",
                    "identification": "{sortCode}"
                },
                {
                    "type": "ACCOUNT_NUMBER",
                    "identification": "{accountNumber}"
                }
            ]
        }
      }
  }
}

Redirect the user to the authorisationUrl returned in the response.

The user is then asked to login and authorise the payment with their bank. The Natwest sandbox credentials are CustomerNumber: 123456789012. When prompted to enter your PIN and Password, Natwest Sandbox will display the values to enter above each text box.

Upon completion, the user is redirected back to the callback URL supplied in the request. In this example, the callback is https://display-parameters.com/ which displays the parameters returned with the redirect.

Store the consentToken to use when confirming availability of funds in step 3 and creating the payment in step 4.


3. Confirm availability of funds

note

This is an optional step, however confirming the availability of funds in the payer account before executing the payment reduces the possibility of a failed payment due to lack of funds.

Confirm availability of funds specifying the reference and paymentAmount in the request body.

Request:

Copy
Copied
curl -L -X POST 'https://api.yapily.com/variable-recurring-payments/funds-confirmation' \
  -H 'Content-Type: application/json' \
  -H 'Consent: {consentToken}' \
  -u 'APPLICATION_KEY:APPLICATION_SECRET' \
  -d '{
    "reference": "Subscription",
    "paymentAmount": {
        "amount": 100,
        "currency": "GBP"
    }
  }'

Response:

Copy
Copied
{
  "meta": {
    "tracingId": "0cda48c70f3941148bbee775a65fa3d0"
  },
  "data": {
    "id": "6ae8b8be-d927-4346-a3e3-83dab57e2c9a",
    "reference": "Subscription",
    "paymentAmount": {
        "amount": 100.0,
        "currency": "GBP"
    },
    "fundsAvailable": {
        "fundsAvailable": true
    }
  }
}

fundsAvailable indicates whether the payer has sufficient funds available for the payment.

If the value is true proceed to step 4 to execute the payment.

If the value is false the payer has insufficient funds for the payment so the payment will fail if executed.


4. Create the payment

Create the non-sweeping variable recurring payment specifying the paymentIdempotencyId, psuAuthenticationMethod and paymentAmount in the request body.

Request:

Copy
Copied
curl -L -X POST 'https://api.yapily.com/variable-recurring-payments/payments' \
  -H 'Content-Type: application/json' \
  -H 'Consent: {consentToken}' \
  -u 'APPLICATION_KEY:APPLICATION_SECRET' \
  -d '{
    "paymentIdempotencyId": "{uniqueValue}",
    "psuAuthenticationMethod": "SCA_NOT_REQUIRED",
    "paymentAmount": {
        "amount": 100,
        "currency": "GBP"
    }  
  }'

Response:

Copy
Copied
{
    "meta": {
        "tracingId": "e1ce71c91d81460aa448a1e6656c5574"
    },
    "data": {
        "id": "b3af3f56-2ae0-4222-bc6d-9f2ac1c427e8",
        "paymentIdempotencyId": "{uniqueValue}",
        "institutionConsentId": "VRP-89b98300-7580-4af3-b163-786243c4a124",
        "status": "PENDING",
        "statusDetails": {
            "status": "PENDING",
            "statusUpdateDate": "2021-03-25T07:48:16.102Z",
            "isoStatus": {
                "code": "PDNG",
                "name": "Pending"
            }
        },
        "initiationDetails": {
            "payee": {
                "name": "NETFLIX",
                "accountIdentifications": [
                    {
                        "type": "ACCOUNT_NUMBER",
                        "identification": "{accountNumber}"
                    },
                    {
                        "type": "SORT_CODE",
                        "identification": "{sortCode}"
                    }
                ]
            }
        },
        "submissionDetails": {
            "reference": "Subscription",
            "payee": {
                "name": "NETFLIX",
                "accountIdentifications": [
                    {
                        "type": "ACCOUNT_NUMBER",
                        "identification": "{accountNumber}"
                    },
                    {
                        "type": "SORT_CODE",
                        "identification": "{sortCode}"
                    }
                ]
            },
            "paymentAmount": {
                "amount": 100.0,
                "currency": "GBP"
            }
        }
    }
}

The payment status, which describes the state of the payment, is returned in the response.

If the status is PENDING, you can use the payment id to poll the payment status until it transitions to COMPLETED or FAILED as in step 4.

For more information see payment status.


5. Confirm payment

note

This is an optional step, however we recommend monitoring the status of the payment when its PENDING to confirm if the institution accepts the payment initiation request.

You can confirm the status of the payment by polling the payment details using the payment id from step 4.

Execute get variable recurring payment details, specifying the paymentId in the path.

Request:

Copy
Copied
curl -L -X GET 'https://api.yapily.com/variable-recurring-payments/payments/{paymentId}/details' \
  -H 'Content-Type: application/json' \
  -H 'Consent: {consentToken}' \
  -u 'APPLICATION_KEY:APPLICATION_SECRET'

Response:

Copy
Copied
{
    "meta": {
        "tracingId": "e5c1c42aa94541598877999e892f7a8a"
    },
    "data": {
        "id": "b3af3f56-2ae0-4222-bc6d-9f2ac1c427e8",
        "paymentIdempotencyId": "{uniqueValue}",
        "institutionConsentId": "VRP-89b98300-7580-4af3-b163-786243c4a124",
        "status": "COMPLETED",
        "statusDetails": {
            "status": "COMPLETED",
            "statusUpdateDate": "2021-03-25T07:49:16.102Z",
            "isoStatus": {
                "code": "ACSC",
                "name": "AcceptedSettlementCompleted"
            }
        },
        "initiationDetails": {
            "payee": {
                "name": "NETFLIX",
                "accountIdentifications": [
                    {
                        "type": "ACCOUNT_NUMBER",
                        "identification": "{accountNumber}"
                    },
                    {
                        "type": "SORT_CODE",
                        "identification": "{sortCode}"
                    }
                ]
            }
        },
        "submissionDetails": {
            "reference": "Subscription",
            "payee": {
                "name": "NETFLIX",
                "accountIdentifications": [
                    {
                        "type": "ACCOUNT_NUMBER",
                        "identification": "{accountNumber}"
                    },
                    {
                        "type": "SORT_CODE",
                        "identification": "{sortCode}"
                    }
                ]
            },
            "paymentAmount": {
                "amount": 100.0,
                "currency": "GBP"
            }
        }
    }
}