Paypal NVP with IPN for confirmation - what ties them together - paypal

I am using PayPal with NVP API (using PHP) for express checkout. I am creating an invoice record in the database before redirecting the user to Paypal. In case the user doesn't return to my site after processing, I am using IPN to confirm the purchase and then update the invoice record that the payment is confirmed. I am still in the sandbox mode and trying to figure out how I will tie the transaction started with NVP to the confirmation I get with IPN.
I need to verify if the "PAYMENTREQUEST_n_INVNUM" sent in the NVP will come back as "invoice" in the IPN post.
It appears I cannot actually test this until I am live since the Sandbox IPN does not seem to be active with NVP initiated sandbox transactions - is this correct?
Thanks for your help.

You can test this in Sandbox. But if you're using "PayPal NVP", I assume you're using PayPal Express Checkout and calling the SetExpressCheckout and DoExpressCheckoutPayment API's.
If that's the case, you don't really need IPN, because a transaction will only be completed as soon as you call DoExpressCheckoutPayment.
In other words, buyers will always be redirected to the RETURNURL you specified in SetExpressCheckout, and the transaction is completed (or not) when you call DoExpressCheckoutPayment on this return page.
To get the invoice number, you could call GetExpressCheckoutDetails and supply the TOKEN you retrieved earlier (it's also appended to the GET of the RETURNURL).
Finally, check PAYMENTSTATUS=Completed in the DoExpressCheckoutPayment API response to see whether the transaction has completed or not.

Thank you Robert for the clarity on the process - especially useraction=commit.
I finally realized that I could turn on IPN in the Sandbox for my test seller and test NVP with IPN together. I was able to verify that PAYMENTREQUEST_0_INVNUM matches the 'INVOICE' parameter in the IPN POST.
I will use the custom field to pass customer email from my system in case they use a different email to log into paypal with, therefore allowing me to have email/invoice number pair for confirmation.

Related

Handle recurring payments with paypal

I'am having troubles about how to handle the paypal recurrent payment system.
I followed every instruction in the website, but once i create the profile, paypal puts it in pending, making me doubt about the reliability of the service itself.
I tried to look over the internet but i didn't really get how this should work...
i made the first call with SetExpressCheckout in order to create the request, when the token is returned, i send the token to the paypal page, the user confirms the payment, then i call the CreateRecurringPaymentsProfile method to confirm the operation (passing PAYERID and TOKEN and setting the AMT value for the first payment and the PROFILESTARTDATE as now +1 month for the future payments)
Now when i try to read the response from the last call (or if i go to the buyer/seller paypal account) i see that the payment is in pending and i have to wait an undefined amount of time before this payment is activated.
Now the real question is: can i trust the fact that even if the payment is in pending, i'll receive the payment and so i can set set the user as member or i have to check and wait until the status is 'active' with the GetRecurringPaymentsProfileDetails method?
PS: i'm doing this in the sandbox version, maybe the official version is a bit faster and more reliable?
Thank you!
In Sandbox as in Live when you call CreateRecurringPaymentsProfile you will also get the response in which it will give you the status of the profile (ActiveProfile or PendingProfile). When the status is in Penidng it means that the system is in process of creating the recurring payment profile. You can then check your IPN messages for an update. It is normal but obviously if you notice that all the profiles you create get into Pending and never activate then there could be a bug but should not be the case. In here is the PayPal technical guide for this API: https://developer.paypal.com/docs/classic/api/merchant/CreateRecurringPaymentsProfile_API_Operation_NVP/

Getting notification from PayPal on new subscriptions

While playing in sandbox and setting up recurring payments via SetExpressCheckout (as suggested in docs) I can successfully create BillingAgreement and recieve a token. Now after user follows a link like https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=[token goes here] , agrees to all terms and conditions etc., he is automatically redirected to returnUrl provided in SetExpressCheckout method, and additionally this token value is appended to the returnUrl.
So far so good. Now the question is - can I rely on the fact that returnUrl will be called at all times? F. e., what happens when for some reason user's browser refuses or fails to be redirected to the specified url?
As far as I can understand from PayPal documentation, you cannot use IPN to notify you of new subscriptions, initiated by user, though clearly IPNs would be an ideal option. I have tried to provide notifyUrl when I compose SetExpressCheckout request, but it is not being hit. Same IPN works fine for "pay" method which I use for one-time purchases.
I think you're missing a step in there. The recurring payments profile doesn't get created while the buyer is on the PayPal website -- you have to wait for the buyer to come back to your return URL, then call CreateRecurringPaymentsProfile to actually create the recurring payment. If you never call CreateRecurringPaymentsProfile, then no recurring payment gets created -- which is probably why you're not getting any IPNs.

PayPal express checkout handling "pending payments" with IPN

I cant find anny clear documentations about this.
If you use paypal express checkout, when a payment is pending what happens next?
Does paypal sends you by IPN an update if the states changes, do you have options?
Let say you do an DoExpressCheckoutPayment (with NVP)
and you get this:
&PAYMENTSTATUS=Pending
&PENDINGREASON= ECHECK //The payment is pending because it was made by an eCheck that has not yet cleared.
&REASONCODE=None
So you've made the payment and you want to wait until its cleared? What should you do next.
Update Some (external documentation) I found only sugest you could use (IPN?) to handle pending payments.
"If the Do Express Checkout Payment PENDINGREASON response is a value
other than none or completed , the payment is pending. Typically,
this means the customer has paid with aneCheck. In such a case, funds
are not guaranteed, and you should not ship or deliver items or
services until the payment has successfully completed. NOTE:
PayPal recommends that you block eChecks as a payment method if you
are unable tohandle pending state payments.To find out the status of a
pending payment, you can:
Submit an Inquiry transaction.
Check the status using PayPal Manager. See PayPal Manager online help
for details."
The paypal sandbox seems to have the option to check IPN messages for the express checkout type. The only correlation (if its ment to be used this way) between the DoExpressCheckoutPayment and the IPN seems you can use the "custom" field to keep track of a pending status. The txn_id (ipn) isn't given in DoExpressCheckoutPayment (nvp). Does any one have any experience with this?
The transaction ID is most certainly given in DoExpressCheckoutPayment, even if the PAYMENTSTATUS=Pending. A pending payment is still a transaction.
So yes, you would be notified via IPN when the transaction is completed. This typically takes a few working days.
Once it has completed, you can correlate the transaction from DoExpressCheckoutPayment to the IPN you will have received via the txn_id in the IPN.
Note: If you want to test a 'Pending' payment in the PayPal Sandbox, simply go to https://developer.paypal.com/ > Test account and click on 'Payment review' for the seller account you're testing with.
Once payment review is enabled on that seller account, any transactions it receives will be in a 'Pending' state.
Simply disable payment review to release the tranasctions afterwards.
I thought i'd add my two pence worth of thoughts to this.
I was getting a pending return status using Express Checkout via the dotNet SDK, according to the doc's and examples I should have been getting an 'approved' status.
I couldn't figure out why but it turned out to be because I was passing through a new currency, in our case 'GBP'. I had to log in as the facilitator sandbox account and decide what to do with the new currency.. convert it or setup a new balance in the currency. Once I did this, and set it as the default action, the pending return status no longer occurred.
hope that helps someone!
One thing not noted here and I haven't found anything else to confirm.. is that Paypal Express API doesn't support passing in the NOTIFYURL with the code. So you have to use the hardcoded IPN url set in your paypal account. This of course causes issues because you need a common callback file that can redirect to the individual payment options.
For example, if you are using Paypal Express AND Paypal Advanced.. Neither of those properly support a notifyurl passed in using the code. Paypal Advanced claims to, but it doesn't seem to work. So there needs to be a common IPN callback file that handles the redirection to each.
Unless someone else can confirm a working notify url for Express Checkout variable that can be passed in the code?

DNN and PayPal, how to sent email to customer after payment has been made

In my DNN website, using Paypal's Checkout button, when user has click the buy button and sent to Paypal. Make a payment and then redirect back to my site.
Question:
How can I get that customer email address (from Paypal) so that i can sent a conformation email to him/her from my DNN website?
thanks.
Two ways; you can either call the GetTransactionDetails API and supply the TRANSACTIONID as a parameter. 'EMAIL' will contain the buyer's (PayPal) email address.
Or you can use PayPal IPN to get notified through POST whenever a payment / action has been made.
GetTransactionDetails API doc is at https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetTransactionDetails
You can also have a look at TransactionSearch for past transactions.
In case you want to use IPN, just supply NOTIFYURL in your SetExpressCheckout and DoExpressCheckoutPayment call if you're using Express Checkout, or if you're using Website Payments Standard.
Remember to send the POST back to PayPal for validation at paypal.com/cgi-bin/webscr?cmd=_notify-validate and check for a VERIFIED / INVALID response.
Some sample code and docs for IPN is available at https://www.paypal.com/ipn/

Capturing payment; express checkout

Hi
I have paypal express checkout working on my site, when user buys something the transaction goes through and the merchant is able to capture payment by clicking on the capture button on the sandbox site. Problem is that I need 'capture status' returned to the site as I need to store it in database for future use, is there a way that paypal sends some notification whenever the payment is captured by the merchant.
Thanks
PayPal IPN: https://www.paypal.com/ipn
In short, include NOTIFYURL in your SetExpressCheckout and DoExpresscheckoutPayment call and you'll receive a POST on that URL when the transaction has been captured. Look for 'PAYMENTSTATUS', as that should read 'Complete'.
Don't forget to validate the POST by sending it back to https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate and checking for a VERIFIED / INVALID response.