Adyen is a single payments platform to accept payments anywhere, on any device. The Adyen API Wrapper for ColdFusion enables you to work with Adyen APIs and Hosted Payment Pages with ColdFusion / Lucee. You can refer further details in adyen payment official documentation.Adyen support SOAP, FORM and JSON format. we prefered to use JSON format, as it is easy & current industry standard.
Simple steps to work with Adyen & ColdFusion
- Step 1 : Create Test account in Adyen Sign Up
- Step 2 : After completed your sign up process you can login via Log In
- Step 3 : Then you should create password for the Test Account
- Step 4 : Use that credential in your application.cfc ( Needed place in your applications )
Demo
This is a simple demo code snippets for few of the most used Adyen payment gateway operations. In this demo, we implemented Payment methods, Create Payment, Capture, Refund and Cancel
Payment methods
Queries the available payment methods for a transaction based on the transaction context (like amount, country, and currency).Besides giving back a list of the available payment methods, the response also returns which input details you need to collect from the shopper.
Sample Request:
cfhttp( method="post", charset="utf-8", url="https://checkout-test.adyen.com/v32/paymentMethods", result="ApiResponse")public any function paymentMethods() {
cardData = {"merchantAccount" = variables.marchantAccount};
cfhttp(method="post", charset="utf-8", url="https://checkout-test.adyen.com/v32/paymentMethods", result="result") {
cfhttpparam(name="Content-Type", type="header", value="application/json");
cfhttpparam(name="Authorization", type="header", value="Basic #variables.authorization#");
cfhttpparam(type="body", value="#serializeJSON(cardData)#");
}
// For Invalid response
if( isjson(result.filecontent) and structKeyExists(deserializejson(result.filecontent), "paymentmethods") ){
return deserializejson(result.filecontent).paymentmethods;
}
else {
return [];
}
}Create payment :
Creates a payment with a unique reference (pspReference) and attempts to obtain an authorization hold. For cards, this amount can be captured or canceled later. We could save this pspReference in DB to make subsequent payments with out asking to enter the same card details once again. As we are not saving customer's credit card details, we are covering the PCI compliance too. Non-card payment methods typically don't support this and will automatically capture as part of the authorization.
Sample Request:
cfhttp(method="post", charset="utf-8", url="https://pal-test.adyen.com/pal/servlet/Payment/v30/authorise", result="ApiResponse")public any function CreatePayment( required number, required expiryMonth, required expiryYear, required holderName,
required cvc, required value, required currency, required reference ) {
// Creates Payment Request in Adyen, It will take 24 hours to be settled
var cardData = { "card"= { "number" = arguments.number, "expiryMonth" = arguments.expiryMonth,
"expiryYear" = arguments.expiryYear, "holderName" = arguments.holderName,
"cvc" = arguments.cvc },
"amount"= { "value": arguments.value, "currency"=arguments.currency },
"reference" = arguments.reference, "merchantAccount" = variables.marchantAccount};
cfhttp(method="post", charset="utf-8", url="https://pal-test.adyen.com/pal/servlet/Payment/v30/authorise", result="result") {
cfhttpparam(name="Content-Type", type="header", value="application/json");
cfhttpparam(name="Authorization", type="header", value="Basic #variables.authorization#");
cfhttpparam(type="body", value="#serializeJSON(cardData)#");
}
return result;
}Capture :
Captures the authorization hold on a payment, returning a unique reference for this request. Usually the full authorization amount is captured, however it's also possible to capture a smaller amount, which results in cancelling the remaining authorization balance.
Sample Request:
cfhttp(method="post", charset="utf-8", url="https://pal-test.adyen.com/pal/servlet/Payment/v30/capture", result="ApiResponse")public any function capturePayment(required originalReference,required value,required currency,required reference) {
// Capture amount from the created payment request.we can capture the payment before it Settle
cardData = { "originalReference" = arguments.originalReference,
"modificationAmount" = { "value": arguments.value,
"currency"=arguments.currency },
"reference" = arguments.reference,
"merchantAccount" = variables.marchantAccount };
cfhttp(method="post", charset="utf-8", url="https://pal-test.adyen.com/pal/servlet/Payment/v30/capture", result="result") {
cfhttpparam(name="Content-Type", type="header", value="application/json");
cfhttpparam(name="Authorization", type="header", value="Basic #variables.authorization#");
cfhttpparam(type="body", value="#serializeJSON(cardData)#");
}
return result;
}Refund :
Refunds a payment that has previously been captured, returning a unique reference for this request. Refunding can be done on the full captured amount or a partial amount. Multiple (partial) refunds will be accepted as long as their sum doesn't exceed the captured amount. Payments which have been authorized, but not captured, cannot be refunded.
Sample Request:
cfhttp(method="post", charset="utf-8", url="https://pal-test.adyen.com/pal/servlet/Payment/v30/cancel", result="ApiResponse")public any function Refundpayment(required originalReference,required reference) {
/* For some occassions we have to Refund the amount, the refund only available for Settled payment
or We can refund the amount which is captured for the authorised payment which is not settled yet. */
var cardData = { "originalReference" = arguments.originalReference,
"modificationAmount" = { "value": arguments.value,
"currency" = arguments.currency },
"reference" = arguments.reference,
"merchantAccount" = variables.marchantAccount };
cfhttp(method="post", charset="utf-8", url="https://pal-test.adyen.com/pal/servlet/Payment/v30/refund", result="result") {
cfhttpparam(name="Content-Type", type="header", value="application/json");
cfhttpparam(name="Authorization", type="header", value="Basic #variables.authorization#");
cfhttpparam(type="body", value="#serializeJSON(cardData)#");
}
return result;
}Cancel :
Cancel a payment if it has not been captured yet, or refunds it if it has already been captured. This is useful when it is not certain if the payment has been captured or not.
Sample Request:
cfhttp(method="post", charset="utf-8", url="https://pal-test.adyen.com/pal/servlet/Payment/v30/refund", result="ApiResponse")public any function CancelPayment(required originalReference,required reference) {
// Cancels the whole transaction. cant cancel the transaction which is in-progress
var cardData = { "originalReference" = arguments.originalReference,
"reference" = arguments.reference,
"merchantAccount" = variables.marchantAccount };
var apiURL = "https://pal-test.adyen.com/pal/servlet/Payment/v30/cancel";
cfhttp(method="post", charset="utf-8", url="#apiURL#", result="result") {
cfhttpparam(name="Content-Type", type="header", value="application/json");
cfhttpparam(name="Authorization", type="header", value="Basic #variables.authorization#");
cfhttpparam(type="body", value="#serializeJSON(cardData)#");
}
return result;
}