Search code examples
c#asp.netpayment-gatewayauthorize.netrecurring-billing

Recurring Payment With Authorize.Net


I am trying to implement Authorize.Net in an ASP.NET web form app and as I am new to it, was going through its official website and few other random sites to learn about it. The following links helped me a bit:

Recurring Bill

Recurring Bill Code Sample

So far, the following code snippet seems ok to implement as it has few configurations to set up and created a sandbox account to get it done:

 ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
 {
      name            = ApiLoginID,
      ItemElementName = ItemChoiceType.transactionKey,
      Item            = ApiTransactionKey,
 };

 paymentScheduleTypeInterval interval = new paymentScheduleTypeInterval();

 interval.length = intervalLength;                        // months can be indicated between 1 and 12
 interval.unit   = ARBSubscriptionUnitEnum.days;

 paymentScheduleType schedule = new paymentScheduleType
 {
     interval            = interval,
     startDate           = DateTime.Now.AddDays(1),      // start date should be tomorrow
     totalOccurrences    = 9999,                          // 999 indicates no end date
     trialOccurrences     = 3
 };

 #region Payment Information
 var creditCard = new creditCardType
 {
     cardNumber      = "4111111111111111",
     expirationDate  = "1028"
 };

I've a tricky requirement and one thing to confirm here. In the web app, if a user signs up in the website, then an amount of $1 will be charged with Authorize.Net api and if the user uses the website for more than three days after sign up, then it'll automatically redirect the user to a monthly subscription (So another fee will be charged here).

Is it something that can be handled with Authorize.Net and for recurring bill, do I require to save user credit card details in the website's database or something similar?


Solution

  • What you would want to do is:

    1. Create a customer payment profile (this allows you to collect their credit card information only once so you can use it again if you reach step 3)
    2. Using that payment profile, charge your initial $1.00 amount
    3. If they do not cancel after three days, using that payment profile, charge their first month's subscription payment. You do this as a "regular" transactions because subscriptions do not begin immediately.
    4. Create a subscription using their payment profile ID (so you do not have to store their credit card details yourself) with the start date set to 30 days out.

    Be sure to store their profile ID and payment profile ID for later reference. You will need it to charge their first subscription payment and to create their subscription (you will need to trigger these from your website, most likely through an automated process). At some point you will also need to update their credit card information once it expires.