PayPal Express Checkout - Webhook PAYMENT.SALE.COMPLETED - paypal

I was searching a while and also read the paypal docs but I am unable to find an answer to my question. I created a recurring payment with Paypal Express Checkout. Everything is working fine, but now I need to know a little bit more about webhooks.
Assume a user registered and created a recurring subscription. The set-up fee is 0,00€ and the first payment will be in one week. After the first payment, the billing cycle will be every week. Now about my webhook question: I guess I need to use the PAYMENT.SALE.COMPLETED webhook am I right? As soon as I get paid every week, the PAYMENT.SALE.COMPLETED webhook will fire for every successfull payment and therefore add a new entry inside my database. Am I right? Or do I need to use another webhook for recurring payments?
Is there someone who uses this webhook in combination of a recurring subscription? Would be great if someone can help me out understanding if PAYMENT.SALE.COMPLETED is the correct webhook for recurring subscriptions.

Yes, PAYMENT.SALE.COMPLETED is sent after every successful billing event for a subscription.
Here is an example timeline of a subscription sale on my website:
2021-07-30 13:17:13.143: PAYMENT.SALE.COMPLETED - first payment
2021-07-30 13:17:10.679: BILLING.SUBSCRIPTION.ACTIVATED
2021-07-30 13:16:15.032: BILLING.SUBSCRIPTION.CREATED - this came after the one above, so make sure you can handle that
2021-08-30 11:13:05.321: PAYMENT.SALE.COMPLETED with "state"=>"completed" - second recurring payment
2021-09-08 14:34:44.816: PAYMENT.SALE.COMPLETED with "state"=>"completed","payment_hold_status"=>"RELEASED" - this is the release of the second recurring payment
If the recurring payment fails, you will receive BILLING.SUBSCRIPTION.PAYMENT.FAILED. Paypal retries the payment 3 times. See the attribute next_payment_retry_time which is set to null after the 3rd and final failed payment attempt.
You can configure your billing plan to automatically suspend a subscription after x number of failed payments (note: set this to be 1+ because 0 keeps is always active) and/or automatically add the outstanding payments to the next billing cycling.
Screenshot below:

I don't believe you have any choice for which webhook PayPal will send you. I am fighting with this right now because PAYMENT.SALE.COMPLETED is the one they send me, but it doesn't contain enough data for me to match it up with a customer or a shopping cart. I want them to return CHECKOUT.ORDER.COMPLETED instead, but there doesn't seem to be a way to make that happen.

Related

Is the INVOICING.INVOICE.SCHEDULED automatically created?

I've implemented PayPal gateway in my application, and I'm looking for a way to send a notification to my customer when an upcoming renewal is coming.
Unfortunately in the documentation I didn't find a depth explaination about INVOICING.INVOICE.SCHEDULED but I'm guessing should be the same as invoice.upcoming of Stripe which is triggered when a recurring payment is going to be renewed.
My question is: INVOICING.INVOICE.SCHEDULED is sended by PayPal automatically when a recurring payment is going to be renewed?
Invoicing and Subscriptions are two separate PayPal products. I would not expect an Invoicing webhook in relation to a Subscription recurring payment.
The subscription webhooks are listed here: https://developer.paypal.com/docs/integration/direct/webhooks/event-names/#subscriptions
If you are looking for one that happens "in advance" of a scheduled payment, I am not aware of one.

PayPal Subscriptions - Tracking Refund

I'm not a developer, but a project manager. So please excuse my lack of proper language.
We are trying to figure out how to handle subscription refunds and then limit account access on the site.
Here's a scenario. Member signs up for an annual subscription to gain certain capabilities in the account. 3 months into it member decides to cancel and requests a refund. Normally, if no refund is issued, subscription is good until the end of the billing period, at which point account is deactivated.
In our case, if a refund is issued, account should be deactivated immediately. Question: is it possible to set this up as part of PayPal Subscriptions? Some type of call from PayPal to our system that will trigger account deactivation.
Thank you.
We recommend using IPN (Instant Payment Notifications) to be asynchronously notified of any events, in this case of those related to existing subscription/recurring payments.
https://developer.paypal.com/webapps/developer/docs/classic/ipn/gs_IPN/
If you enable IPN notifications you will receive a POST of PayPal in the following events (among others):
When a recurring profile is cancelled.
When a refund has been made to a previous completed transaction.
This way, you can set up your IPN script to keep the subscription “open” in your side for the remainder of the month even if the profile has been cancelled, or to deactivate it if the last month has been refunded.
For more information about IPN variables:
https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/

Paypal Recurring api for find next recurring payment occure

i has been implemented paypal recurring subscription plan in php and paypal recurring also charge via paypal as per recurring periods. but my system didnt find out next recurring was charged or not so how could i know next recurring payment has been charged using paypal api.
i want to help for to upgrade next expire date after next recurring payment changed.
As I understood, you want to see if the user paid or not and change expiration date according to that.
The solution is Webhooks. In your PayPal Application section click on add webhook and choose PAYMENT.SALE.COMPLETED and enter the URL that you want to listen to this event where PayPal will send a post request to this URL when you get a new payment completed.
In the page that corresponds to the URL you entered, you have to do the followings:
Verify that the call is from PayPal, not from another source (in case you are using PHP you can check this: PHP verify Paypal webhook signature)
Parse the data sent from PayPal by reading the body content, not the POST data
Verify that the event is what you need, in this case PAYMENT.SALE.COMPLETED
Verify the amount you received and the currency
Make sure that you have not processed this transaction before and this is too important
If everything is valid, you can save the transaction and do whatever you want, in your case extending the expiry date.
If I understand you correctly, you need to configure Instant Payment Notification (IPN). PayPal's server will POST transaction data to a listener script you have on your server so you can process things accordingly. It happens in real-time.
When working with recurring payments you'll get an IPN when a profile is created, canceled, or suspended, and you'll also get notifications when payments for profiles are completed, failed, etc. You can update your system or send out email notifications accordingly based on the IPN data you get.

Do Paypal recurring payments have unique txn_ids?

I'm using the Paypal "Subscription" button. I have an IPN handler and overall I think I've got it all figured out. My last problem is that apparently there's no good way to test a recurring payment (except to wait for the cycle to occur). This issue is discussed here: [question]: Testing Paypal subscription IPN
I don't really need to test this recurring payment but I do need to know if every recurring payment will have it's own txn_id or if every payment in a subscription shares the same ID.
Thanks!
Yes, each recurring payment cycle will create a new transaction with its own transaction ID.
You'd link these transactions together via their recurring payments profile ID.

PayPal Subscription Payment Failed

When a subscription payment fails, PayPal will retry for n times.
What transaction type (subscr_cancel or subscr_eot) is sent back via IPN, after all retries fail?
The specifics depend on the PayPal product you're using, although the logic works similar(`ish) across both Website Payments Standard subscription buttons and Express Checkout Recurring Payments (via the CreateRecurringPaymentsProfile API):
This depends on whether you've set MAXFAILEDPAYMENTS or not. If MAXFAILEDPAYMENTS > 0 is set, it will cancel the subscription after n number of attempts and you'll receive a subscr_cancel. If you have it set to MAXFAILEDPAYMENTS=0, you'll get recurring_payment_skipped and the recurring payment will be marked as having an outstanding balance. If you specify AUTOBILLOUTAMT=AutoBillAmt, the outstanding balance will be added to the next billing cycle.
I would suggest taking a look at https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables#id091EB0901HT which lists all IPN variables, including the ones for recurring payments.
Paypal returns subscr_failed for this case, and the possible return values are:
subscr_signup: subscription sign-up.
subscr_cancel: subscription cancellation.
subscr_failed: subscription payment failure.
subscr_payment: subscription payment.
subscr_eot: subscription’s end-of-term.
subscr_modify: subscription modification.
Please click here for further clarification.