We’ve been hard at work the last few weeks on making real, meaningful ground on CFPAYMENT, the open source ColdFusion payment processing library that generalizes many different gateways into a single, pluggable API. In the run-up to 1.0, I wanted to share some snippets to get you excited about using cfpayment for your next (or current!) e-commerce project:
<cfset config = {path = "braintree.braintree", username = "demo", password = "demo" } />
<cfset cfpayment = createObject("component", "cfpayment.api.core").init(config) />
<cfset gateway = cfpayment.getGateway() />
// create a money object to hold the amount in cents
<cfset money = cfpayment.createMoney(5000, "USD") />
// create an account to charge
<cfset account = cfpayment.createCreditCard() />
<cfset account.setAccount(4111111111111111) />
<cfset account.setMonth(10) />
<cfset account.setYear(10) />
<cfset account.setFirstName("John") />
<cfset account.setLastName("Doe") />
// authorize the card
<cfset response = gw.authorize(money = money, account = creditcard) />
// flag the authorization for settlement into your bank account
<cfset response = gw.capture(money = money, transactionid = response.getTransactionID()) />
// changed my mind, let's void it
<cfset response = gw.void(transactionid = response.getTransactionID()) />
Heard of PCI DSS? You can mitigate or avoid it altogether by using a remote storage system like Braintree’s Secure Vault:
// create a token
<cfset token = cfpayment.createToken(createUUID()) />
<cfset options = { store = token.getID() } />
// authorize and put the data into the vault
<cfset response = gw.authorize(money = money, account = account, options = options) />
// come back later and use that token to charge the card
<cfset response = gw.purchase(money = money, account = token) />
// changed my mind, delete it from the vault
<cfset response = gw.unstore(account = token) />
Don’t use Braintree? That’s OK, as of today, you could just as easily initialize the Core API to use iTransact or Skipjack without any change in your consumer code.
We’re working to add more payment gateways. The best source of these will come from people who have written integrations already or need to write one and want to benefit from the infrastructure of a community-supported and planned API that gives them flexibility in choosing their gateways and merchant accounts over the long road.