# Processing payment
These are the steps to be followed to process a payment.
# Payment object
Create the payment object with the parameters.
// Sample customer object
const customerObject = {
UserName: "XXXXXX@paytriot.co.uk",
CustomerName: "test",
EmailID: "tester@test.com",
Amount: 123.12,
PhoneNumber: "+123123123123",
Street: "Test",
City: "London",
Country: "United Kingdom",
ZipCode: "XXX XXX",
Currency: 1,
TransactionNumber: "txn123234",
MerchantURLs: "https://www.paytriot.co.uk/",
};
# Encrypting payment object
The encryption of the above created payment object is done with a token (Please get the token from Paytriot) as can be seen from the function shown below. The library used here is crypto-js (opens new window) and is recommended for most users.
function encryptString(customerObject, token) {
const key = CryptoJS.enc.Utf8.parse(token);
const iv = CryptoJS.enc.Utf8.parse(token);
const returnEncrypted = CryptoJS.AES.encrypt(
CryptoJS.enc.Utf8.parse(customerObject),
key,
{
iv: iv,
keySize: 128 / 8,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
}
);
return returnEncrypted;
}
# Create payment link
Use the above function to create the encrypted parameter and append it to the base url.
const stringParams = JSON.stringify(customerObject);
// Get the token from Paytriot
const token = "XXXXX";
// Call the function to encrypt
const encryptedParams = encryptString(stringParams, token);
// Use the BASE URL
const baseURL = "https://payment.paytriot.co.uk/MerchantPayment/Payment";
// Append all the together make the final payment URL
const paymentURL = baseURL + "?merchantpayment=" + encryptedParams;
Now redirect your customer to the paymentURL, so that they can complete the payment process.