Validate whether payment was a success or failure - session

I am looking to use PayPal to accept a payment through my website. I am looking at the Smart Payment button option. If the payment is successful I need to update something in my website DB. How can I determine whether the payment was successful or not? I cant see anything the API docs.
I also need to retain user context with a PHP session ID. How can I pass that to the paypal site and ensure it is returned with the success / fail indicator?

Use Paypal IPN to receive payment notifications. Setup a server endpoint to respond to IPN requests and update your DB etc...
To maintain state, you will need to include a hidden input filed in your Smart Payment Button with a name of custom and a value of your choice (session id).
Setup a IPN endpoint ie: /checkout/ipn, to receive Paypal notifications. Capture the session ID with $_POST['custom'];

I ended up using the Braintree API for this use case. Ther Brantree API returns a unique payment identifier (payment Nonce) which you can then validate by submitting a call back to the Braintree API to ensure the payment was actually received properly.

Related

Issue regarding paypal IPN in codeignitor

I am integrating PayPal payment gateway in my code ignitor website. and I am using this ref
https://www.codexworld.com/paypal-payment-gateway-integration-in-codeigniter/
All things are successfully done but payments transaction data is not saved into the database.
I have set the IPN URL in the sandbox business account. And in the IPN history page, It showing IPN was sent successfully. but IPN data not received on my website.
I also test IPN using the IPN simulator. When I put my base URL like https://www.earlyyearz.com/ then IPN was sent successfully. but when I give the path of my IPN function
https://www.earlyyearz.com/payments/ipn then it was saying IPN not sent.
does anyone can help me to fix this.
thanks in advance.
Add logging to your IPN function so you can see what is happening when it receives the data. If your IPN function does not respond with an HTTP 200-level status, PayPal will mark the IPN as not having been received.
IPN is an extremely old service that was not designed for modern web integrations. If this is a new integration, first ask yourself why you are using IPN to begin with (you shouldn't need it for a normal PayPal checkout with server API captures)
But if you really do need asynchronous notifications (again, you shouldn't need them), use webhooks instead of IPN.

Joomla- payment integration

I want to create own plugin for payment integration in joomla.
I am using hdfc bank details.
How to create form and call it.
how to handle request and response.
Here is what you need to do:
When the user submits a payment, then you should, in your controller, use curl to submit the payment to the bank.
Once you submit the payment, you have 2 options, depending on how the bank's API works:
You can immediately get the response from the bank when issuing the curl_exec method OR
In the curl call, you will specify which page the bank will post to on success and on failure (typically, it'll be the same page but with a different task), and you also specify the merchant transaction ID. The bank will then load the "response" page on success and will post back its response (you can get the information using $_POST).
Note that in most scenarios, you only need to worry about the first method (getting the response immediately from the bank). The second method is typically used by PayPal and is referred to as IPN (Instant Payment Notification), but it might be the case that your bank uses some kind of IPN to notify you of payment success.

Regarding uable to trigger Paypal REST API webhook events from developer sandbox

What is wrong with my Paypal sandbox account process
to receive webhook notifications? We are unable to receive webhook event on
my URL.
URL working with "Webhooks simulator". Please let me know what
should I do for receive webhook event on above URL.
Webhooks simulator sends sample payloads for the events you configured. It does not send a notification on triggering of an actual event.
If you are getting notification via Webhooks Simulator, it means the URL configured by you is able to intercept POST requests.
Now for the "Paypal sandbox account unable to process to receive Webhook notifications" part, please check if the transaction is actually created at https://developer.paypal.com/developer/dashboard/sandbox/ . If the transaction you are looking for is not present there, there won't be any notification generated. In case transaction is present there and still you are not getting any notifications, please share debug id.
Here is a silly thing that I overlooked in the documentation and only found out after contacting support.
After you've followed the approval url and gave your approval, dit you execute the payment with the REST API?
https://developer.paypal.com/docs/api/payments/#payment_execute
Webhooks are only called after you've executed the payment.
The confusing part is; there is no webhook being called, when a user approves or cancels a payment. There is only a redirect back to a return url or cancel url. So you either need to monitor the redirect back to your site and trigger the execute call then, or find another way (like polling the payment) to see the status change before calling the execute call.

Confirming Paypal subscription with Codeigniter PayPal IPN Library

I'm using PayPal IPN Library to process a subscription payment. The Library logs to a database the IPN answer. The return URL is a "processing" page that checks at timed intervals for the "SUCCESS" status at ipn_log table. But I cant identify the current transaction row on this table. How can I confirm the payment has succeded? I can get the POST variables on the return URL, but none of them is registered on the database. Is there a variable that is returned by the IPN and also sent by POST to the return URL? Something like the transaction id? Maybe Im going the wrong way on this and there is another aproach to confirm the payment status.
Got it. The "custom" field added to the button form makes the trick. Saving it to the database is enough to keep track of the process

How to cancel an order when a payment gateway page timesout in magento

i have integrated a 3rd party payment gateway into magento. It handels a successful transaction or a failed transaction perfectly.
But what if when the user is at the payment gateway page and it times out or when at the payment gateway page the user closes the page and returns back to the site later or user simply hits the back button,
how do i cancel the order then?
Should i use some observer to do this?
If so could you suggest to which events do i need to fire the observer?
the issue i am facing is that when a user is redirected to a payment gateway and he/she hits the back button and comes back to the site, the order is still created, which ideally should have been canceled.
Thanks.
Your validation methods should not be session aware and should process any feedback (and validate before you process) in any case. You also need a monitoring service that times out orders without a response after some time if you need them to be disabled in timely fashion.
However if user hits back button there is really nothing you can do as the feedback from payment gateway never gets sent on user action. I know some payment gateways issue automatic post from the server no matter what you have to investigate if this can be also possible with your payment gateway.

Resources