Merchant Account Services

Integrate the Authorize.Net Recurring Billing API with PHP

Establish subscriptions and recurring payments for your website

 

Author: Jim Conners

Rating: 10.0

Pages: 1|2|3|4|5|6|7|8|9

Assumptions

Naturally this article is not going to be a tutorial on using PHP or APIs in general. Several assumptions are made to keep this article focused on its main goal of showing you how to use PHP to work with the ARB API. Those assumptions are:

  • Basic Data Validation

    As always when dealing with user input as developers we must validate their input to make sure that not only it is not malicious but also is in a format that we expect. If you are unsure how to validate basic credit card information you can get some help in our article Integrate the Authorize.Net Payment Gateway with PHP.

  • Familiar With Object Oriented Development

    Just as we did in our previous article we will be writing our code in an object oriented syntax. This will allow this code to be modular and portable. In other words, reusable.

  • Familiar With the Authorize.Net Advanced API

    The Authorize.Net ARB API is most commonly used in conjunction with the Authorize.Net Advanced Integration Method (AIM). We covered how to use the AIM API in our article Integrate the Authorize.Net Payment Gateway with PHP. If you are unfamiliar with how to use that API read our article before continuing here.

Planning Our Transaction

Before we can use our class we need to understand the context in which it will be used. In the case of recurring billing there are two scenarios we will encounter:

  1. Instant Payment

    In this scenario we will want to capture an immediate payment and then schedule future payments for the same credit card. In these cases we won't try to establish a recurring billing subscription unless the original transaction is successful. If the original transaction is successful we know we have a valid credit card and can set up the recurring billing subscription without doing any further validation.

  2. Delayed Payment

    In this scenario we have no need to charge the user immediately and seek only to schedule future recurring payments. In this case we will need to not only validate the credit card passes basic validation (right number of digits, valid expiration date, etc.) but we will also want to verify the credit card is valid and legitimate. If we establish the recurring billing subscription with an invalid credit card we won't know until the first scheduled transaction is attempted. When establishing a recurring billing subscription Authorize.Net assumes that the credit card is valid. This is because there is no way for them to check if a credit card is valid so that leaves the responsibility for verifying this up to our programming.

What if the credit card expires before its first scheduled payment?

While Authorize.Net does not have the means to verify if a credit card is legitimate it can easily tell if a credit card will expire before its first scheduled payment. In cases where a recurring payment is scheduled to occur after the credit card has expired Authorize.Net will not establish the subscription. This makes sense as there is no point creating a subscription that we know will fail the very first time it is run. This is most likely to happen with annual subscriptions but can occur at any time.

But handling subscriptions that aren't set up automatically is a nightmare!!! You bet it is. So how do you handle this situation? The best advice we can give you is to catch these subscriptions before sending them off to Authorize.Net. Before attempting to establish the subscription alter the expiration date of the credit card to be two years into the future. This will allow the subscription to be established. It's ok if the subscription fails as it would have failed anyway because the credit card will expire before their next payment. But at least this way the failure is handled by Authorize.Net automatically and you are notified about it as you would be all failed transactions.

Getting Started | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Building Our Class