I have website where I use PayPal NVP sandbox. Sometimes after successful payment of user, PayPal get back to my return URL very slow. Unless PayPal returns to my website with details I am unable to check whether user has completed the order (For all attempt website adds order id to the database) or not and that destroys website's work principle.
What I need is that I want to retrieve the data of transaction without transaction id if possible. Maybe with custom field or something else. If I would be able to check the transaction details without transaction id , then I would be able to handle the requests by user accordingly. Or if there is a way to get a transaction id somehow with the help of another variable that also fine as I will make checking after finding out the transaction id.
Current PayPal Checkout integrations give an immediate response of success/failure. There is no need for any redirect away from your site, and there is no need to wait for asynchronous IPN or webhook messages. Don't use such things.
Follow the PayPal Checkout integration guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order' (see the optional step 5 in 'Add and modify the code'; you can use the Checkout-PHP-SDK). Both of these routes on your server should return/output only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.
Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
Related
i have IPN data sending back the correct info, i have the product id and i also have a text box for user's to write in their in-game-name in on my website.
im stuggling to attach the username input with the IPN product_id. what i want it to do is when the user clicks the paypal button, it process's the transaction and if approved the username entered from the website and product_id get placed into a array or something that i can later put into my database
im quite new to php and html please bare with me
When you create a PayPal transaction, pass a variable named custom with the values you want to store as part of the transaction.
For old-style HTML integrations that use no API or JS, this is documented here: https://developer.paypal.com/docs/paypal-payments-standard/integration-guide/Appx-websitestandard-htmlvariables/#payment-transaction-variables
IPN is very old and clunky. Crrent PayPal integrations don't use IPN at all, but rather two routes on your server that call the PayPal API -- one for 'Create Order' and one for 'Capture Order', documented here: https://developer.paypal.com/docs/business/checkout/server-side-api-calls/#server-side-api-calls
When you do that capture call you get an immediate response of success/failure and can update your database/system accordingly. Thus there is no need to wait around for PayPal to send you an IPN notification.
Those two routes on your server should return JSON data (and only JSON data) when called. The approval flow to pair with them is https://developer.paypal.com/demo/checkout/#/pattern/server
You can add POST data values to your fetch request.
I am implementing PayPal payment to my application.
I am using Laravel Framework and merchant-sdk-php package to handle NVP/SOAP API. I would accually prefer REST API, but i need customers to make Reference Transactions with various amount, in non regular time periods and as far as i know it's possible only with NVP/SOAP API.
The payment flow in shortcut:
1. Payer clicks "connect" button, which is to create billing agreement using "SetExpressCheckout" method. Amount is set to 0 and adding a Billing Agreement field to request. Customer is redirected to PayPal, log in to his account, agreeing to direct debit and finally redirected to my return url.
2. After response is come, return action is fired (the one, which is passed in returnurl field). Next using token from paypal resposne i use CreateBillingAgreement method to get "BillingAgreementID" which i store in database.
3. Using "BillingAgreementID" i make "DoReferenceTransaction" request. No prompt to login is occurring, everything is happening behind the scene. Finally i get response after transaction.
The thinks i want to know are:
1. Is there a way, to get an email address, which consumer used to log in when creating billing agreemenet? I want to show in application which PayPal account (related to mentioned email) is direct debit set to?
2. I want to make some action in databse both after "BillingAgreementID" and "DoReferenceTransaction". Is the response status "Success" and additionally in "DoReferenceTransaction" field "PaymentStatus" set to "Completed" enought to conclude, that transaction is fully completed, and i cant i.e. share some digital goods or should i wait for IPN from this request?
Thanks for all contributions!
Found solution to question 1.
After betting billing agreement id i had to make "GetBillingAgreementCustomerDetails" action. In response i got customer details including email.
Still watching for hint to second question
I have already done a small e-commerce with Paypal and it works, but I feel like it is done wrongly.
Because the page that handles the IPN response from Paypal can't read $_SESSION variables, before the user submits the form and is redirected to Paypal, I get all the cart items and store them in a table in the database and also I register a new order with the user information but with the status 0 ( not completed ).
Then, after the user pays and I get the IPN response, I check if the status is completed, check if the amount paid is correct, currency and the usual checks to make sure the payment is successful.
The problem with this approach is that if the user once redirected to Paypal, decide to leave/close the browser/Paypal tab, I will have a failed order registered in the database and I can't delete it but manually.
How can I handle this kind of situation, and is it correct to register the order/cart before the user pays ?
Thank you and sorry for the long post.
If you want to check if the transaction occurs rely on the IPN messages. Depending on which api you are using you have several way to customize the IPN message with useful information for you, ie:
using paypal custom field
define dynamically the IPN url with extra parameter ie www.yoursite.com/ipn?myvar=myval
That way you can have a hook between the payment and the actual user in your application.
Obiusly the php session attributes of the user is not available when the http post comes from paypal.
Payal say that IPN can take a while for orders to be relayed. I am wondering if there is a way with the other Paypal APIs to instantly fetch information about an order, the moment the user is redirected to the success URL of my site.
The problem is that only two variables seem to be relayed in the querystring to my success page: token and PayerID.
The reason I want to do this is I want to allow users to complete the checkout process without logging into my site, but then once the order is complete and they're sent to my success page, I want my site to be able to link them to their previous orders as well as this one, which would be extracted from my database.
Can this be done using token and/or PayerID? If so, how? (I'm using the PHP scripts that the Express checkout wizard provides)
IPN is generally pretty much real-time. There are times when it gets a little lagged and can be kind of slow, but it doesn't seem to happen all that much.
That said, the API calls along within your checkout will indeed return lots of good info in the actual response. Your URL only has the parameters you mentioned (token and Payer ID), however, the GetExpressCheckoutDetails response would have all the buyer info you need, and DoExpressCheckoutPayment will return the transaction ID, payment status, payer status, etc. So the DECP probably has the majority of what you're after.
You can use session variables to save GECD response data and DECP response data accordingly and then update your database, send out email notifications, etc. after calling DECP.
The thing is, the payment could end up being "pending" for various reasons. As such, IPN would still be the best way to handle this sort of thing so that you can update your DB and send out one notification for the pending payment being received, and then another update/email once that payment actually clears.
I've implemented a paypal transaction before but this one has a twist that I'm not quite sure what's the best way to handle it.
The basic idea is I want to create an account for the user when he provides some details and makes a payment via PayPal. Until BOTH the user details are filled out correctly AND the payment is made correctly, I shouldn't create an account for the user.
The setup I've done before was simply a paypal button that the user clicks, makes a payment, and gets forwarded back to just a generic page "your order will be processed and shipped" so there was no pre-order form involved.
This one is different though because
before PayPal, I need to collect initial user data
after PayPal, I need to create the new user account and use in it the user data collected from the pre-paypal form
I'm sure there's a logical way to implement this, but I'm not quite sure what's the flow I should follow to do it.
I use the Zend framework by the way, which shouldn't matter but just in case Zend has an easier way to help me with what I'm trying to do.
I do the following (though I do this in ASP.NET):
User fills out form
Info is saved in Order table in db with a unique invoice number
Invoice number is passed to PayPal, along with the IPN Notify URL, when you do the redirect
User is sent to Paypal to pay and then comes back to a generic Success page
Behind the scenes, Paypal makes a call to the IPN Notify url once processing is complete. This page receives your invoice number which PP returns with its call, and then does the account creation processing for that order after retrieving the details from the db. [This is a page with no UI, since only PP is hitting it.]
An email is sent from that process which notifies the customer that their account has been created and gives them the details.
This is a simplified version of the process, but hits the highlights. You can check out PayPal's page about IPN, and do a search on google for IPN integration with PHP.