PayPal REST API - No Webhook Event on canceled payments? - php

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.

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.

When is the best time to create a PayPal Webhook?

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!

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.

Omnipay callbacks from APIs like IPN and Silent Post?

How can I capture paypal IPN and Authorize.net "Silent Post" messages?
I'm fine with how to make payments with Omnipay but I could not yet figure out how to listen to the callbacks from these APIs to detect changes for my payments.
For example Authorize.net processes it's credit card payments one time per day (late night for me) and then sends out it's messages via their so called "silent post" (its just a http POST) notifications. So the API call might be immediately "accepted" but I won't know for sure if everything is OK with the payment until I receive the callback.
So how do I set up Omnipay to listen to APIs that do these kind of delayed callbacks?
I'm aware that I'll need a callback URL like /payments/callback/ to load the right gateway to do something with the callback. But I could not yet figure out what method(s) from Omnipay I have to use for it.
Omnipay doesn't support notifications for existing payments. It automatically handles the first notification which is made directly after a payment, but doesn't yet have methods to handle notifications if you change the status of a payment (for example by refunding it from PayPal's control panel, it will not update in your database automatically).
Note this isn't needed for the initial payment. Especially with PayPal Express the payment is not confirmed until the customer returns to your site, so there is no chance of them closing the browser window and the payment being lost.
If you want to set up a notification endpoint and listen for events which happen after the payment is processed, you will need to add a new request type to Omnipay.

Categories