Orange is my favorite color

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.

5 Comments

  1. John Allen said:

    on November 19, 2008 at 9:25 am

    Looks very slick.

  2. Sami Hoda said:

    on November 19, 2008 at 11:11 am

    Nice!

  3. Adam Tuttle said:

    on December 5, 2008 at 3:12 pm

    Impressive. Something you might consider adding is having the functions that normally return void return “this” instead, which would allow you to chain commands, similar to jQuery:

    account.setAccount(4111111111111111).setMonth(10).setYear(10).setFirstName(“John”).setLastName(“Doe”)

    And for what it’s worth, this wouldn’t break backwards compatibility. :)

  4. Brian said:

    on December 8, 2008 at 9:58 am

    @Adam – thanks for the suggestion. Mark M had suggested that earlier and I think I drug my feet; we’ll probably implement it in the model objects (cc, eft, etc) where that will cut down on repetitive lines of code. We’ll see if it makes sense in any other situations… my only concern with this approach is consistency but I’ll give it a go.

    Mark and I are both putting our systems into production soon so I figure that’ll be the test for 1.0 release. Thanks for the feedback!

  5. brian said:

    on December 10, 2008 at 2:25 pm

    @Adam – I committed the chaining code today to svn so your example above now works (and is covered in our unit tests):

    cc.setAccount(4111111111111111).setMonth(10).setYear(10).setFirstName(”John”).setLastName(”Doe”)

    Subversion is available from RIAForge at http://svn.riaforge.org/cfpayment/trunk

    Thanks again for the feedback…

{ RSS feed for comments on this post}