When is the best time to create a PayPal Webhook? - php

I am using the PayPal API to create a Webhook, and not the Developer site. When is the best time to do this? Do I create the webhook before the payment is created, after the payment is created, or after the payment is executed? According to the API documentation, the webhook needs to be created only once in the lifetime of the app. What happens if a new webhook is created each time the app is used?
What I have:
processPayment: the payment details are defined, the payment is created, the user is redirected to PayPal.
executePayment: the user is returned from PayPal, the payment is executed.
On notify:
verifyPayment: calls a function to validate Webhook signature.
Post-processing in the Site's database.
P.S. Where/how is the webhook Id generated?

Webhook needs to be created before making a payment transaction if you want to get notified of the payment. If there are multiple Webhooks configured on your app and if you have same set of events subscribed on both, you would receive notifications on both Webhooks.
Thanks!

Related

PayPal Webhook Notification Billing Subscription PHP

I've implemented PayPal Billing subscription using PayPal-PHP-SDK, everything is working fine as expected, the user can cancel the subscription from the application with this code.
$agreementStateDescriptor = new AgreementStateDescriptor();
$agreementStateDescriptor->setNote("Suspending the Agreement.");
$agreement->suspend($agreementStateDescriptor, $apiContext);
But if the user cancel the subscription from his PayPal account, my application will not be notified for it, how it can be addressed? is there any webhook as Stripe or something.
https://github.com/paypal/PayPal-PHP-SDK/
Thanks
you need to create a Paypal webhook for your app.
Set an URL (accessible URL) i.e. yourdomain/paypal/resolver
then register event BILLING.SUBSCRIPTION.CANCELLED.
Once the user cancel the agreement from Paypal, the webhook for BILLING.SUBSCRIPTION.CANCELLED event is activated and send a request to your site.
FYI, the samples provided from this link http://paypal.github.io/PayPal-PHP-SDK/sample/ are pretty much useful

Unable to get the transaction id using Authorize.Net ARB

I am working on implementing Authorize.Net's Automated Recurring Billing API in Laravel Framework.
The scenario is I have a site, users sign up for our services and we charge them on monthly basis, and for that we have implemented automated recurring billing.
But I am unable to get the transaction id of successfully placed transactions.
ARB does not return a transaction ID when a payment is processed. It only establishes the recurring subscription. If you want transaction IDs of every successful subscription payment you will need to use one of two options available to you.
Webhooks
You can set up a webhook using the Webhooks API to be notified whenever a successful payment is made for a subscription. Although very little information is sent over with a webhook as it is best paired with the Transaction Details API, the transaction ID is one of the pieces of information sent with a webhook notification.
Silent Post
Silent Post is very similar to Paypal's IPN. Whenever a transaction is made Authorize.Net will send transaction details to a URL you specify which includes the transaction ID. Handling a Silent Post notification is easy as it looks exactly like a form submission.
Silent Post has been deprecated and will be going away so it is not recommended that you use this any more.
Disclosure: I wrote the articles about Webhooks and Silent Post.

PayPal REST API - No Webhook Event on canceled payments?

I am working with the PHP version of the PayPal REST API within Sandbox environment.
I was able to create and execute a payment, that was approved using a Sandbox PayPal Account. The payment was made using MANUAL_BANK_TRANSFER, meaning that there is not enough money on the PayPal Account. The user would have to transfer money to his PayPal account first. Thus the payment was created as Pending.
So far so good. After creating/approving the payment I logged into the PayPal account of the Sandbox user and canceled the payment. I assumed, that my system would get notified of this action via another Webhook Event. This was not the case. I received no event at all.
I created the Webhook Event as wildcard (all events) and the PAYMENT.SALE.PENDING event was received without any problem. Thus there should be no problem with receiving other events. But even one hour after the payment was canceled I have not received any event.
I assume that I should get notified of a canceled payment, but I don't know if this is really the case. The PayPal docu does not describe in detail which events will be triggered by which actions.
So, is there something wrong with my Webhook config or is there really no event on canceled payments?
When refunding a payment via the paypal-account/paypal-backend, you don't get notified via webhooks. Webhooks only work when the action was invoked via the REST-API. The only possible thing you could do is implementing an INP, but I haven't tested it if this will work.

PayPal REST API order workflow: Payment -> Sale -> Webhook?

I am trying to integrate the PayPal REST API into my Symfony 2 web app but I find hard to understand how exactly the complete workflow looks like:
The PayPal docs describe the following steps to accept a payment. One can use the PayPal Playground to simulate these steps:
Get an access token
Create a Payment object by querying the API
Redirect the user to the approval url received in the Payment response
After the user approved the payment on the PayPal page, he is redirected back to my page, using the success-link defined in the Payment object. Use the received information to execute the payment.
Payment is completed with status approved
From the docs: Once a payment is complete, it is referred to as a
sale. You can then look up the sale and refund it.
So far so good. BUT: Where are Webhooks used/fired in this workflow? I have defined a wildcard Webhook (accepting all possible events) in the PayPal Developer Dashboard.
My observation is, that my system receives the Webhook event 1-2 Minutes (!) after the user was redirected back to the success-link and after the payment was executed (Step 4).
Beside this long delay between executing the payment and receiving the Webhook, this workflow means, that I only receive the Webhook AFTER handling the success-link. This means, handling the success-link is absolutly necessary for the payment to be completed. Is this correct?
Do I need to use Webhooks?
I already asked this question a few days before and the answer by nifr is quite reasonable: One cannot trust the user to follow any redirect URL but should only rely on the Webhook events.
However this collides with the observations I described before, since I will never receive the Webhook without handling the redirect URL...
So, handling the PAYMENT.SALE.COMPLETED webhook event does not make a lot of sense, since this should already be done in when handling the redirect URL. Correct?
However, to handle updates on pending payments, handle refunds or reversed payments, etc. are only possible by listening on those events.
So the answer is: Only use Webhooks to get updates on payments made before. Correct?
So, the main questions are:
The 5-step process to accept payments does not say anything about using Webhooks. This does not seem to make a lot of sense, because without Webhooks one would miss update events, etc.? So, is it really possible to implement the complete payment workflow without Webhooks?
If yes, how are updates (refunds, pending, etc) handled in this case?
If no, what is the right strategy/time to fulfill the order since it take quite a long time to completly receive and handle the webhook?
i am still a newbie in PayPal world, but few days ago i integrated PayPal Plus REST API in an online Shop, and from my understanding i can tell that the workflow looks like:
create a Payment
redirect to PayPal
Payer could pay using PayPal account OR (using Bank Direct debit or Credit Card Payment without PayPal Account)
After completing the process on PayPal side, PayPal redirect the user back to your success URL.
till now the user is still not charged(you got no money). At the moment where you (in your success URL) do $payment->execute($paymentExecution,$api); , you ask Paypal to charge the amount from user. BUT also after this, you got no Money. Paypal have first to process the charging and notify you later via WebhookEvents.
the Webhook Notification (with that nasty delay) is especially important when the user pays per direct debit or Credit Card etc. Processing such Payments takes few seconds/minutes.
the redirectUrl ist absolutly necessary for charging/executing the Payment.
here on execution succeed, just to tell the user, that he finished his Job, and you can here save/capture the PaymentID/Transaction id for later usage/update via WebhookEvent Listener.
so i would recommend you to update your Database(Payment completed) only after receiving notofications via WebhookEvent Listener and not in the success RedirectUrl.

How can I send email to customer when recurring payment fails on Stripe?

I want my customers to get notified if the recurring payments fail on Stripe. They should be notified via email that Stripe has declined their Credit Card. I have read about webhooks but not quite sure how to use them. And also how can I know every time any card has been declined on Stripe.com?
The idea with webhooks is that you register a url with the remote party and once they have something to tell you they "call" that url passing it parameters.
With stripe you do that on their dashboard under webhook settings.
Then all you have to do is apply your logic in the url you supplied. If it is www.example.com/webhooks/stripe then you need a webhook controller with a stripe() method that will parse the data.
So in your stripe() method you wait for the charge.fail event (read Stripe's API) and once you get that you send the email and perhaps update your database as well.

Categories