Omnipay callbacks from APIs like IPN and Silent Post? - php

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.

Related

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.

Paypal IPN needed?

I'm doing a project involving Paypal, more specifically with the NVP API in PHP. But I just can't seem to figure what to use the IPN feature for.
I mean, when the user has been redirected to Paypal to confirm the purchase, he is redirected back to my website's "Paypal-succes-page", when the transaction is complete. And just to be sure that he actually payed i could use the "PaymentDetails" operation.
Now where does IPN fit in this process? and what is the benefit of it?
Thanks
The integrate with PayPal's services you will notice there are three main channels (and IMO it's important to know this so you can decide the benefits for your application):
IPN: Instant Payment Notification
PDT: Payment Data Transfer
PayPal's API
To use PayPal's IPN you need to add a 'listener' script (example) and add the address to your PayPal account. Whenever an event occurs PayPal will send a message directly to your server via your listener and you then update your accounts appropriately. This is especially useful for running subscription services as events will occur in the background without user intervention and you can capture successful/failed recurring payments etc.
PayPal's PDT is a system for accepting data when a user is redirected back to your site from PayPal. For example, a user clicks 'Buy', they are directed to PayPal, enter information etc. Then, once the payment has been taken, they are redirected back to your site. PayPal can pass details about the transaction including whether it was successful or not so you can display the appropriate success/failed page from your site.
PayPal's API allows you to integrate more deeply with PayPal's services, and you would use this if you were managing payments directly from your site.
These services aren't mutually exclusive, so you can use any combination with your application.
I hope this helps
The IPN feature is a very useful feature which you should use to update your database in my opinion. Sure the user is redirected to your success-page after the purchase where you can validate the payment details.
But what if he closes (by accident or not) the browser before reaching your success page? You will never know the result of the transaction and you will never update your database or process his order accordingly.
When using the IPN you can be sure that the transaction result will always reach you because PayPal will keep on making an offline request to your IPN page until it has reached your servers.
Instant Payment Notification
The typical usage of the IPN is to validate the purchase and to let your script or management system know that the transaction is complete so your system can update any records you may have for your service.
But the most important part is that the transaction is validated.
IPN send all data about transaction to your server - price, items, contacts ... so you can check, if someone don't pay you only 1$ instead of 100$ and confirm your order. It prevets thiefs, cheaters, ... USE IT! ;)

Paypal Integration with PHP

I'm looking to implement a very simple Paypal integration whereby I can enter a valid Paypal Email address (recipient) and a dollar amount, and click "Pay." Ideally, it would send the money from my paypal account automatically via my API key.
I currently have Mass Pay set up with PHP, and it's working fine, except that it charges me 2% on every payment, and doesn't pass back the Transaction ID. It also kinda seems unnecessary since I don't need to pay multiple people at once.
Since I only need to do one transaction at a time, I'm wondering if anyone knows of a simpler Paypal API for single outgoing transactions from my account.
I've been reading the documentation all day and I've yet to find what I'm looking for.
Any advice is greatly appreciated!
PayPal has sample codes for integrating various PayPal features on it's website. This includes PHP take a look at the list of features and I'm sure what you are looking for is there.
Also from the paypal site:
PayPal receives the MassPay request and returns a response indicating
success or failure. If PayPal returns a successful response, then
PayPal processes the payments and, if you have Instant Payment
Notifications (IPN) enabled, PayPal sends a notification to the Notify
URL specified in your account profile. If you do not have IPN enabled,
you can view the details of the MassPay transaction in your PayPal
account.
This implies that in the case of mass pay you need to provide a URL where paypal sends payment notifications. Your program can probably check this url to figure out whether a payment has been made or not, I would suspect this would be the case for all payment integration. That being said I would print_r the the response from paypal, I'm sure something like a transaction id will probably be in there. In the case of DoAuthorization it does return the transaction id
In the case of mass pay it does return the transaction id if IPN is enabled

Categories