Search code examples
javascripte-commercesubscriptionauthorize.netaccept.js

How To Get Two Separate Nonces with Accept.js?


I'm using Authorize.Net Accept.js for a custom cart with subscriptions using the ARBCreateSubscriptionRequest API, where we pass it the payment nonce as an opaque data element.

Although this works, it has these 3 faults that occur on ARBCreateSubscriptionRequest (subscriptions) but do not occur on CreateTransactionRequest (single payments):

  • It does not confirm CVC (card code).
  • It does not confirm valid card expiration date.
  • It does not confirm available funds to start the subscription.

Working with Authorize.Net tech support, they confirmed that the proper procedure is to:

  1. Use CreateTransactionRequest to create the initial payment of the subscription, thereby giving an immediate response and getting around the listed problems above.
  2. Then, they said to follow this with a ARBCreateSubscriptionRequest where the start date is the next term of their subscription.

Granted, yes, even without a CreateTransactionRequest, but solely using ARBCreateSubscriptionRequest when the subscription initial payment kicks in 24 hours later, the card will fail and a webhook message can be sent to my cart to let me know to disable whatever I enabled. However, an immediate response would be more suitable and would certainly alleviate potential customer frustration and merchant frustration. Plus, if one is shipping something with the purchase, it is crucial for the merchant to know that the purchase worked.

So, for instance, let's say I charge $9 a month on a subscription. The first payment would be with CreateTransactionRequest for $9 for the current month. Then, create ARBCreateSubscriptionRequest with a delay to start on the first day of the next month, and an interval of every month. So, the customer gets processed (pass/fail) on the initial $9 immediately on purchase. Then, when the next month kicks in, their subscription engages for $9/month thereafter.

Okay, I understand this 100%. But here's where I'm not getting a clear answer in the docs or in a support ticket. The CreateTransactionRequest and the ARBCreateSubscriptionRequest both need their own unique payment nonce.

Key Problem: If Accept.js is used to generate a single nonce, how do I get two nonces? If I use Accept.js to generate the second nonce, does it invalidate the prior one? I'm confused and the documentation doesn't explain.


Solution

  • If you want to validate card information from an Accept.js nonce, process an initial transaction and then create a subscription, you might try the following sequence:

    1. Use createTransactionRequest with the nonce and set createProfile=true. The gateway will process your transaction including validating the card number, expiration and CCV. If successful, a customer profile is created.
    2. Use the customer profile to create your subscription.