[Drupal] Implementing Authorize.Net ARB in Drupal commerce

| | 2 min read

In Drupal, drupal_commerce module can be integrated with authnet_arb module by which we can implement Auhorize.Net subscription or recurring billing. Before integration we have make some hack on the sandbox module to make it effectively work with drupal_commerce and bug free.

In Drupal organization hacking module and generating a patch is more oftenly done by all drupal contributors.
Basically to be a good drupal contributor before hacking a set of code we need to have clear idea of
what is the cause of problem and why we need to fix it. Hence we can look on the problem,
whenever creating ARB subscription or an API request is been to happen SDK will check for
sandbox boolean value is true or false. Since authnet_arb is a sandbox module
its not checking whether the payment method is been set as sandbox and then set the SDK sandbox
boolean as proper. So we have to hack the sandbox module for this to work properly before each API
request is to created or generated. Here come the sample code needed to set sandbox boolean of SDK.

    $request = new AuthorizeNetARB($settings['login'], $settings['tran_key']);
    if ($settings['sandbox']) {
    } else {

Another feature we needed while implementing Authorize.Net ARB is the
option for update subscription details such as credit card.
authnet_arb sandbox module doesn't provide
this update feature, instead they says it need to be implemented.
Here I havehack that also as follow:

    function authnet_arb_update_subscription ($update_values) {

      $settings = authnet_arb_settings();
      require_once authnet_arb_sdk_path().'/AuthorizeNet.php';

      $subscription = new AuthorizeNet_Subscription;
      $subscription->billToFirstName = $update_values['first_name'];
      $subscription->billToLastName = $update_values['last_name'];
      $subscription->billToAddress = $update_values['thoroughfare'] . ' ' . $update_values['premise'];
      $subscription->billToCity = $update_values['locality'];
      $subscription->billToState = $update_values['administrative_area'];
      $subscription->billToZip = $update_values['postal_code'];
      $subscription->billToCountry = 'US';

      $subscription->creditCardCardNumber = $update_values['card_number'];
      $subscription->creditCardExpirationDate = $update_values['expiration_date'];

      $request = new AuthorizeNetARB($settings['login'], $settings['tran_key']);
      if ($settings['sandbox']) {
      } else {
      $response = $request->updateSubscription($update_values['subscription_id'], $subscription);
      return $response;

There is one more feature need to implement delete subscription.
That you can try and publish as an article like this. That's all enjoy coding and hacking.