9

I want my users to be able to subscribe to a recurring payment (using the express checkout api) The first payment needs to be billed immediately that the user subscribes, and I need to know that they have been successfully billed before granting them access.

Is there a straight forward way to do this?

I've tried, creating a recurring payment profile with an INITAMT set, however, it's not clear that the user is being billed (when using the sandbox), and there is no txn_id (or the equivalent) being returned to suggest that billing has been done. I do get an IPN confirmation however that comes "some time" after creating the profile, which makes it difficult to offer a great user experience.

I've tried adding a one time payment, authenticating that with DoExpressCheckoutPayment, then setting up the recurring profile if the one-off payment works, however the Authentication also fails and at this points I've given up (although there may still be some legs in this approach).

Anyway, I thought I'd ask the experts here. Is there a simple way to setup a recurring payment, one payment per month, first payment billed now() and have the first payment confirmed via the API without having to wait an unknown amount of time for an IPN confirmation message?

mark
  • 1,769
  • 3
  • 19
  • 38

4 Answers4

12

This can be done as you require, I've tested it and it works. The key is that you need to process both a standard digital goods payment as well as a recurring payment using the same Express Checkout flow, i.e. The user will be asked to pay a once-off, as well as approve a subscription. You would want to set the s

  1. Follow the instructions for setting up the payment: https://developer.paypal.com/webapps/developer/docs/classic/express-checkout/ht_ec-basicDigGoodsPayment-curl-etc/

  2. Add the fields specified for recurring payment: https://developer.paypal.com/webapps/developer/docs/classic/express-checkout/ht_ec-recurringPaymentProfile-curl-etc/

  3. Process 'DoExpressCheckoutPayment' and if successful, 'CreateRecurringPaymentsProfile' with a start date of your first 'renewal' date.

You should now have both transaction id for the one-off payment, as well as a profile id for the recurring payment.

skieter
  • 449
  • 4
  • 6
  • 2
    To elaborate, just add `L_BILLINGTYPE0=RecurringPayments` and `L_BILLINGAGREEMENTDESCRIPTION0=[insert your description]` to the same `SetExpressCheckout` parameters you would include to prepare for a `DoExpressCheckoutPayment` API call. Then you can first call `DoExpressCheckoutPayment`, then `CreateRecurringPaymentsProfile` using the same token for each. – Shaun Dychko Feb 26 '15 at 19:01
3

I would stick to your first option of using INITAMT to process the first payment, but set FAILEDINITAMTACTION to CancelOnFailure.

This way, if the initial payment is not successful, the profile will immediatly be set to Suspended status instead of Active.

Then, within your login system or whatever you're using to protect your subscriber content, you can use GetRecurringPaymentsProfileDetails to obtain the current status of the subscription profile. If it's anything other than "Active" you can give the user a message accordingly and deny them access to the content.

Drew Angell
  • 25,968
  • 5
  • 32
  • 51
  • Hi Andrew thanks, the problem I'm having with INITAMT is that very often (actually pretty much always) the the profile status is set to Pending and (i'm assuming) Paypal is waiting to bill the amount. That leaves me back in the position where I have to say, thanks your subscription with be enabled "sometime in the future" which i'm trying to avoid. I can't believe the use case of "bill the user for month 1 now and confirm" isn't supported though? – mark Nov 27 '12 at 10:44
  • As I said, using FAILEDINITAMTACTION with CancelOnFailure with set it to Suspended instead of Pending if the payment fails. If it works it will immediately be Active. I've been using recurring payments on my USBSwiper site for years and I've followed this method without any issues. – Drew Angell Nov 27 '12 at 16:53
  • Strange, it doesn't do that for me. It returns as Pending regardless of CancelOnFailure. I assumed that pending meant Paypal hadn't tried to bill the initial amount yet and so it couldn't have failed (if you see what I mean). – mark Nov 27 '12 at 20:11
  • @Andrew OK this is strange, this is the second post I see you say the same thing, but it contradicts the others posting about this. Did you debug the workflow that CreateRecurringPaymentsProfile returns Active right away? The profile always take more than 1 minute for me before it changes, I even check it on the paypal recurring payment page – albattran May 02 '17 at 22:10
  • I'd have to see your request and try to reproduce your issue. I've been using recurring payments for years and I get active profiles back instantly. – Drew Angell May 03 '17 at 06:26
2

When the profile is first created, PayPal sends an IPN named "recurring_payment_profile_created". This IPN contains a field "initial_payment_txn_id". You can use GetTransactionDetails to look up this ID and determine whether that transaction is Completed. Ensure that you mark that transaction ID as processed so that your code doesn't double-ship if/when the IPN for that transaction is sent (if that is relevant to you). This example is similar to how we approach this in our IPN listener (written in Ruby against PayPal's official Merchant SDK gem):

case params[:txn_type]
  when 'recurring_payment_profile_created'
    # The profile has been created.  Perform any action, if necessary...

    initial_txn = params[:initial_payment_txn_id]
    return if ProcessedTransaction.exists?(initial_txn)

    request = api.build_get_transaction_details({
        :TransactionID => initial_txn
    })

    resp = api.get_transaction_details(request)
    if resp.success? and resp.PaymentTransactionDetails.PaymentInfo.PaymentStatus == 'Completed'
        # The initial payment is completed, perform the action...
        # Add this ID to your ProcessedTransaction table so you don't double-process...
    end
  # other 'when' statements for other transaction types, etc go here
end
A. Wilcox
  • 1,782
  • 2
  • 12
  • 18
1

The only solution I've found (which is poor) is to accept up to a 24 hour delay in being notified that the first month's subscription has been billed. We're now investigating Google checkout and braintree payments as alternatives to paypal so we can migrate away from it.

mark
  • 1,769
  • 3
  • 19
  • 38