Payflow Pro is one of the secure, open payment gateway from PayPal. Using Payflow Pro, we can able to do create Authorization and do sales transaction, Refund transaction and Void transaction.Payflow pro Payment Gateway handles all major credit and debit cards. Payflow is integrated with major shopping carts and works with almost every processor.
API_Credentials | Descriptions |
---|---|
USER | If you set up one or more additional users on the account, this value is the ID of the user authorized to process transactions. If, however, you have not set up additional users on the account, USER has the same value as VENDOR. |
VENDOR | Your merchant login ID that you created when you registered for the account. Limitations: Sixty-four alphanumeric, case-sensitive characters |
PARTNER | The ID provided to you by the authorized PayPal Reseller who registered you for the Payflow SDK. If you purchased your account directly from PayPal, use PayPal. |
PWD | The password that you defined while registering for the account |
In this post, we will explain, how we can able to create a sale transaction, Recurring sale transaction and Refund transaction using ColdFusion. First create a folder called as 'Payflow' in your webroot. Inside of the folder, create following files Application.cfc, index.cfm and com/payapl.cfc.
In this file, we created a singleton PayPal object in OnRequestStart function to access the PayPal component's methods. We created object in Application scope to access to access to any files of this application.
component output="false" { | |
this.name = "paypal payflow API"; | |
public any function onRequestStart() { | |
APPLICATION.paypalObj = createobject("component","com.paypal").init(); | |
} | |
} |
This ColdFusion component has all neccessary functions for create transaction, create recurring transaction and refund transaction. We prefer to use modern cfscript
syntax instead of tag based syntax. For demonstrated purpose, we have just hardcoded PARTNER
& endPointURL
values in init() function. But we could pass these as arguments too. In each function, we provided proper hints
attributes, that will explain each arguments purpose as well as, it will be useful to create documentation of your ColdFusion components using DocBox ( another excellent open source project from Ortus solutions to create documentation from source code of ColdFusion components)
component output="false" displayname="Paypal payflow API CFC wrapper" { | |
public function init () { | |
VARIABLES.partner = "PayPal"; | |
VARIABLES.endPointURL = "https://pilot-payflowpro.paypal.com"; | |
return this; | |
} | |
public array function createPayment( | |
required string user hint = "Paypal payflow account username", | |
required string pwd hint = "Paypal payflow account password", | |
required string vendor hint = "Paypal payflow account vendorID", | |
required numeric cardType hint = "Credit card type", | |
required numeric acct hint = "Credit card number", | |
required numeric expMonth hint = "Credit card expire month", | |
required numeric expYear hint = "Credit card expire year", | |
required numeric cvv hint = "Credit card security number", | |
required numeric amt hint = "Transaction amount", | |
string currency = "USD" hint = "Transaction currency format", | |
string firstName = "mitrah" hint = "Card holder firstname", | |
string lastName = "soft" hint = "Card holder lastname", | |
string tender, | |
string trxtype, | |
string verbosity | |
) { | |
try { | |
arguments.partner = variables.partner; | |
arguments.expdate = "#arguments.expMonth##arguments.expYear#"; | |
return apiCall(parameters = arguments); | |
} catch(any e) { | |
return listToArray("Something went wrong. Please try again later"); | |
} | |
} | |
public array function refund( | |
required string user hint = "Paypal payflow account username", | |
required string pwd hint = "Paypal payflow account password", | |
required string vendor hint = "Paypal payflow account vendorID", | |
required string origid hint = "Approved transactionID", | |
required numeric amt hint = "Refund amount", | |
required string tender, | |
string trxtype | |
) { | |
try { | |
arguments.partner = variables.partner; | |
return apiCall(parameters = arguments); | |
} catch(any e) { | |
return listToArray("Something went wrong. Please try again later"); | |
} | |
} | |
public array function recurringBilling( | |
required string user hint = "Paypal payflow account username", | |
required string pwd hint = "Paypal payflow account password", | |
required string vendorID hint = "Paypal payflow account vendorID", | |
required string acct hint = "Credit card number", | |
required string payperiod hint = "Specifies Payment Occurs", | |
required string action hint = "Add, Modify, Cancel, Reactivate, Inquiry", | |
required string expMonth hint = "Credit card expire month", | |
required string expYear hint = "Credit card expire year", | |
required string amt hint = "Transaction amount", | |
required string tender hint = "Tender type", | |
string trxtype hint = "Recurring profile request", | |
string profilename hint = "User specified name", | |
string start hint = "Recurring billing start date", | |
string term hint = "Number of payments to be made over the life of the agreement", | |
string comment1 hint = "Payment comments" | |
) { | |
try { | |
arguments.partner = variables.partner; | |
return apiCall(parameters = arguments); | |
} catch(any e) { | |
return listToArray("Something went wrong. Please try again later"); | |
} | |
} | |
public array function apiCall( struct parameters ) { | |
var httpService = new http(url = VARIABLES.endPointURL, method = "POST"); | |
var encodeLists = "user,pwd,vendor,amt,billtofirstname,billtolastname"; | |
for (keys in parameters ) { | |
if( listFindNoCase(encodeLists, keys )) { | |
httpService.addParam( type = "formfield", name = keys, value = arguments.parameters[keys], encoded = false ); | |
} else { | |
httpService.addParam( type = "formfield", name = keys, value = arguments.parameters[keys] ); | |
} | |
}; | |
return listToArray(httpService.send().getPrefix().fileContent, "&" ); | |
} | |
} |
A sale transaction charges the specified amount against the account and marks the transaction for immediate fund transfer during the next settlement period.
Arguments | Description |
---|---|
TENDER | The method of payment. Values are :
|
TRXTYPE | Indicates the type of transaction to perform. Values are:
|
ACCT | Credit card or purchase card number. For the Pinless debit TENDER type, ACCT can be the bank account number. Limitations: This value may not contain spaces, non-numeric characters, or dashes. For example, ACCT=5555555555554444 |
EXPDATE | Expiration date of the credit card. Limitations: mmyy format. For example, 1008 represents November 2008 |
AMT | Amount (Default: U.S. based currency). |
CVV2 | A code that is printed (not imprinted) on the back of a credit card. Used as partial assurance that the card is in the buyer's possession. Limitations: 3 or 4 digits |
FIRSTNAME | Account holder's first name. |
LASTNAME | Account holder's last name. |
<cfscript> | |
createCharge = APPLICATION.paypalObj.createPayment( | |
user = "your account username", | |
pwd = "your account password", | |
vendor = "your account vendorID", | |
cardType = 0, | |
acct = "4111111111111111", | |
expMonth = "09", | |
expYear = "2020", | |
cvv = "123", | |
amt = "1", | |
currency = "USD", | |
firstName = "mitrah", | |
lastName = "soft", | |
tender = "C", | |
trxtype = "S", | |
verbosity = "HIGH" | |
); | |
writeDump(createCharge); | |
</cfscript> |
Explanation for few notable parts of the PayPal response is,
RESULT
.You can only refund a transaction that has not been settled. You need to include the original transaction ID obtained from the transaction's response. Using this endpoint, we can able to Refund the amount to your customer/client.
PayPal support both partial & full refunds. If we pass amount
to PayPal api endpoint, it will considered as partial refund & only that particular amount will be refunded. If we omit amount
parameter, then whole transaction amount will be refunded. For example, In the above sale transaction we are transfered $1 amount. If we would like to refun only $0.5 amount, then we need to pass the amount like $0.5 in the corresponding field. If we didn't pass the amount arguments means, the payflow automatically refund the whole $1.
<cfscript> | |
refund = APPLICATION.paypalObj.refund( | |
user = "our account username", | |
pwd = "our account password", | |
vendor = "your account vendorID", | |
origid = "transaction ID", | |
amt = "1", | |
tender = "C", | |
trxtype = "C" | |
); | |
writeDump(refund);abort; | |
</cfscript> |
Recurring Payments allows you to bill a buyer's credit card or PayPal account for a fixed amount of money on a fixed schedule. PayPal offers Payflow recurring payments with the Direct Payments (credit card processing) solutions.
Arguments | Descriptions |
---|---|
TRXTYPE | The transaction type R for recurring payments profile request. Character length and limitations: One alpha character. |
ACTION | The value A for creating a new recurring payments profile. Character length and limitations: One alpha character. |
TENDER | The tender type. Is one of the following values:
|
PROFILENAME | A unique name for referencing the recurring payments profile. Character length and limitations: 127 alphanumeric characters. |
EXPDATE | Credit card expiration date. Character length and limitations: Four numeric characters in the format MMYY. |
START | Beginning date for the recurring payments cycle used to calculate when payments should be made. Use tomorrow’s date or a date in the future. Character length and limitations: Eight numeric characters in the format MMDDYYYY. |
TERM | The total number of regular payment periods over the life of the agreement. If there are 36 monthly payments, for example, TERM is 36. Character length and limitations: Numeric. A value of 0 means that payments should continue until the profile is deactivated (suspended). |
PAYPERIOD | How often the regular payment occurs. On the PayPal website, PAYPERIOD is called payment cycle. Values are:
|
CURRENCY | One of the following three-character currency codes:
|
<cfscript> | |
createRecurringBill = APPLICATION.paypalObj.recurringBilling( | |
user = "your account username", | |
pwd = "your account password", | |
vendorID = "your account vendorID", | |
acct = "4111111111111111", | |
amt = "1", | |
expMonth = "09", | |
expYear = "2030", | |
term = "12", | |
start = "06252025", | |
payperiod = "DAYS", | |
trxtype = "R", | |
tender = "C", | |
action = "A", | |
profilename = "RegularSubscription", | |
comment1 = "My recurring payment" | |
); | |
writeDump(createRecurringBill); | |
</cfscript> |