Changes to Autobills in the FreshBooks API

As of january 1st freshbook will no longer be accepting raw cc data. You need to pass token instead of card number when you create recurring profile.

The new required flow follows this sequence:

  1. create a client
  2. send raw credit card data to our secured tokenization service, receive a token
  3. create a recurring profile with the token you received instead of a card number
  4. the recurring profile processes credit cards automatically as scheduled

PHP Code to create token:

$card_number = 'YOUR CARD NUMBER';
$card_name = 'YOUR NAME IN THE CARD';
$exp_month = 'EXPIRY MONTH - MM FORMAT';
$exp_year = 'EXPIRY YEAR - YYYY FORMAT';

$cc_info = json_encode(
array('cc_info' => array(
'card_number'=> $card_number,
'name' => $card_name,
'expiry_month' => $exp_month,
'expiry_year' => $exp_year
)
));
$tokenurl = "https://paid.freshbooks.com/gateway/stripe/tokenize";
$ch = curl_init($tokenurl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $cc_info);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($cc_info))
);
$tokenResponse = curl_exec($ch);
curl_close($ch);
$res = json_decode($tokenResponse, true);
if(isset($res['cc_token'])){
//success
$cc_token = $res['cc_token'];
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s