Recurring Payments Tutorial
Streamlined Integration of Recurring Payments and Vaulting with PayPal Using Pockyt Payments API.
This comprehensive tutorial will guide you through integrating recurring payments and vaulting features seamlessly into your application using PayPal and the Pockyt Payments API. By following these steps, you'll master the process of customer registration, secure payment transactions, and the implementation of vaulting for recurring payments.
Step 1: Customer Registration
Register Customer API Reference
To begin, let's register a customer and obtain a unique customerNo. Here's how you can do it:
Make a POST request to the /v1/customers/create endpoint with the provided request body using cURL.
Request:
{
"zip": "12345",
"firstName": "John",
"lastName": "Doe",
"customerCode": "CUST123",
"email": "[[email protected]](mailto:[email protected])",
"country": "US",
"city": "New York",
"dateOfBirth": "1990-01-01",
"phone": "555-123-4567",
"countryCode": "1",
"street": "123 Main St",
"street2": "Apt 4B",
"state": "NY",
"lang": "en",
"profileType": "individual",
"merchantNo": "MERCHANT123",
"storeNo": "STORE123",
"verifysign": "signature",
"company": "Example Company",
"mobileNumber": "555-987-6543"
}
You'll receive a response containing the registered customer's details along with their customerNo.
{
"result":
{
"firstName":"Test",
"lastName":"Test",
"customerCode":"test08242021",
"createdTime":"2021-08-24T17:50:18Z",
"customerNo":"2000300192493466077324",
"email":"[[email protected]](mailto:[email protected])"
},
"ret_msg": "success",
"ret_code": "000100"
}
Step 2: Secure-Pay with Vendor PayPal
Secure-Pay API Reference
Now, let's move on to initiating a secure payment request using PayPal as the vendor:
Create a request with essential parameters, including the customerNo, vendor as "paypal," creditType as "vault" and terminal as "YIP", along with the payment details.
{
"amount": "5.6",
"creditType": "vault",
"currency": "USD",
"customerNo": "2000305749483958992834",
"merchantNo": "202570",
"reference": "cw4bbc29f50334a2d7",
"settleCurrency": "USD",
"storeNo": "301945",
"terminal": "YIP",
"timeout": "120",
"vendor": "paypal",
"verifySign": "79dca0585a2e5e48535e744912c7aae6"
}
The response will provide transaction details, including the transactionNo and a PayPal client script URL for the checkout process.
{
"result":
{
"reference": "cw4bbc29f50334a2d7",
"createdAt": "2023-07-05T10:40:08Z",
"amount": "5.60",
"orderId": "9YJ8144710699722K",
"clientToken": > "eyJicmFpbnRyZWUiOnsiYXV0aG9yaXphdGlvbkZpbmdlcnByaW50IjoiY2I2ZTVhNWE3NGI0N2I2NzZhNDIyY2UzMWY3NGNmYmMwMzQ5ZTM2MTMyNDY0NTUzODJjZDI5YWIxN2UyMWNkMXxtZXJjaGFudF9pZD1yd3dua3FnMnhnNTZobTJuJnB1YmxpY19rZXk9NjNrdm4zN3Z0MjlxYjRkZiZjcmVhdGVkX2F0PTIwMjMtMDctMDVUMTA6NDA6MTEuMzk1WiIsInZlcnNpb24iOiIzLXBheXBhbCJ9LCJwYXlwYWwiOnsiaWRUb2tlbiI6bnVsbCwiYWNjZXNzVG9rZW4iOiJBMjFBQUk5VjRuSXV2NWRZT1U3V2xLREtvVmUwdVk3RzdYODA0eDNfS08ySmFuZF83cXk3SDZGckFGWFBnX04yMFpNWEk3VjRvVE0yTlRVaEtMV21kc2c1OVNvd0VMOEl3In19",
"transactionNo": "303146182585830961",
"currency": "USD",
"clientScript": "<https://www.paypal.com/sdk/js?client-id=ARjuyiItvW8OAc2bw8Iv1Q20HgDPLwu1dQ-nmzBRD7zpkF5lUoz2jFC0Hz2ZjfGbfDNCLGN744kDf1n3&merchant-id=AAMZ8HV6NNS6J&intent=capture&components=buttons">
},
"ret_code": "000100",
"ret_msg": "success"
}
Step 3: Display PayPal Checkout Script
Once you've obtained the transactionNo from the Secure-Pay response, you should display the PayPal client script URL on your merchant's checkout page.
Step 4: Payment Processing and Vault ID Retrieval
When the user confirms the payment on PayPal, it's time to process the payment and obtain a vaultId for future recurring payments:
Call the /order/v4/process API by providing the transactionNo and other necessary details.
{
"transactionNo": "303146182585830961",
"merchantNo": "202570",
"storeNo": "301945",
"verifySign": "79d38c56a319228faeca9d42f7fd674a",
"timestamp": "2023-07-05T10:41:04Z"
}
The response will include a vaultId that you can utilize for upcoming recurring payment.
{
"result":
{
"reference": "cw4bbc29f50334a2d7",
"amount": "5.60",
"supUserid": "[[email protected]](mailto:[email protected])",
"vaultId": "ca_af748cc62c334c75b83844e53b76e9b1",
"transactionNo": "303146182585830961",
"vendorId": "4WS71249P6788492V",
"currency": "USD",
"paymentTime": "2023-07-05T10:41:08Z",
"customerNo": "2000305749483958992834",
"status": "success"
},
"ret_msg": "success",
"ret_code": "000100"
}
Step 5: Implementing Future Recurring Payments
With the vaultId in hand, let's proceed to implement future recurring payments:
Make use of the /online/v4/secure-pay API once more, ensuring you set the creditType to "vault." Provide the customerNo and vaultId obtained earlier.
{
"amount": "299.98",
"creditType": "vault",
"currency": "USD",
"customerNo": "2000305749483958992834",
"merchantNo": "202570",
"reference": "1krxdd25urb6a32t1",
"settleCurrency": "USD",
"storeNo": "301945",
"terminal": "YIP",
"vaultId": "ca_af748cc62c334c75b83844e53b76e9b1",
"vendor": "paypal",
"verifySign": "38bb3afff2306647c100cc7bb5f2976a"
}
The response will confirm the success of the recurring payment and provide relevant transaction details.
{
"result":
{
"amount": "299.98",
"customerNo": "2000305749483958992834",
"paymentTime": "2023-07-05T10:59:29Z",
"reference": "1krxdd25urb6a32t1",
"status": "success",
"transactionNo": "303147339985810581",
"vaultId": "ca_af748cc62c334c75b83844e53b76e9b1"
},
"ret_code": "000100",
"ret_msg": "success"
}
Successfully Completing Recurring Payments
You've successfully implemented recurring payments and vaulting with PayPal using the Pockyt Payments API. Here's a quick recap of the steps:
- Register a customer and obtain their customerNo.
- Initiate a secure payment request with PayPal as the vendor.
- Display the PayPal client script URL on your checkout page.
- Process the payment, acquire the vaultId for future use.
- Implement recurring payments with the vaultId and customerNo.
- Receive confirmation and relevant details about the recurring payment.
Keep in mind that while this tutorial simplifies the process, you may need to adapt the steps and examples to match your specific programming environment and application structure.
Updated 12 months ago