Paypal recurring payment response verification and match with paypal return page variable - paypal

I am working on a website to sell some advertisement concept online, where user can get the access of more options after opting a monthly subscription paying through recurring Paypal.
I have already implemented the recurring paypal functionality successfully except one thing. Like One can subscribe for the plan and monthly payments are deducted from the concerned account.
But I have no idea how to update my database after the first payment from the recurring paypal.
eg, a customer comes to the site, choose his options, went to paypal recurring part and made the transaction. Now I have one page , where the paypal returns the control, which is given on the return url. Now the problem is, in this page when I am updating the database, the paymanet status is pending.
Then after a while when the IPN response comes to the application, I wont able to update the earlier entry in my database, as I am not sure how to match these two entries, I mean upon which field the update query should be coded.

There's no point in updating the database at all until you get the money. When you get the money, the transaction contains everything you need to create or update the subscription.

Related

PayPal - Pass Customer ID from my website - Receive confirmation with same Customer ID from my website

I am working on a software service and am offering a monthly subscription for my software service.
I am currently working on the subscription part - and am wanting to implement a paypal monthly recurring payment solution.
I have spent quite a bit of time looking over PayPal documentation, and trying different buttons, webhooks, IPN methods etc.
The problem is that I am not sure what solution to use - because I am confused by the multiple options.
What is most important to me is - that when the customers fill out the form on my website - and are then directed PayPal to pay - I then want to know that specific Customer ID from my website has successfully paid.
I would like to know:
Which SPECIFIC option(s) PayPal has that I can pass Customer ID from my website of that customer - let's say a subscription ID from my site - and that PayPal will then send the customer back with my subscription ID, that I passed them on to PayPal with.
Which is the easiest option to do that with?
I simply want the customer to:
sign up at my site. (my part)
be issued a unique Customer ID from my website (my part)
click a PayPal payment/subscribe button (my part)
be sent to PayPal to pay for the subscription (paypal's part)
be returned to my site with the unique Customer ID from my website from my site - as well as a confirmation of payment from PayPal (paypal's part)
Please do not simply pass me to the general area of the development sections -
As I said - I have already been through all of that and find there is too much information.
Please direct me to a specific solution, or example, or tutorial that covers a solution that will fit what I need.
I would recommend using the Express Checkout API with Recurring Payments.
The best thing to do would be to create a local invoice record in your system, and then have a related customer ID associated with that invoice.
In the CreateRecurringPaymentsProfile request to PayPal you can include a PROFILEREFERENCE parameter, which would be the invoice ID you generated for that order in your system. Then all future payments related to that profile would include this same reference ID as part of its data, so if you're using IPN, for example, it would be included there.
When working with Express Checkout the user is always guaranteed to end up back on your site to finish the checkout flow, so you can simply save data in sessions during checkout and update things like your database, email receipts, etc. directly in your payment flow. Then you could use IPN to process the recurring payments after that, and again, it would include that same reference ID. In IPN this would come back as rp_invoice_id.

Should I remember the payment before getting it authorized?

I get it that Paypal SDK (backed by REST API) has three steps:
Create a payment
payment = Payment({...})
payment.create()
return redirect( redirect_url( payment))
The customer pays and authorizes payment from within Paypal
Redirect to our site where we execute payment, thus transferring money
Should I store the created payments at step 1? I would thus capture all payment attempts, whether successful or not. Or can I create a payment, and not remember it until step 3? That is, record only the successful payments (within their respective Invoices). Is there any reliability or security issue or other harm if I do not store it at step 1?
I suspect not being able to roll back failures.
In Paypal terms, they are of sale intent and are meant for payment of invoices for services rendered. Card data do not touch our servers, I am deferring to Paypal on handling it.
I use paypalrestsdk, Paypal's Python SDK.
Previously, it was tricky to get the PaymentId back when PayPal redirects the page back to your server to authorize you, as there was no way to get PaymentId on 3rd step
However, now, the PaymentId is returned back as a part of the URL as shown here in 3rd step :
http://localhost/Server-SDK/PayPal-PHP-SDK/sample/payments/ExecutePayment.php?success=true&paymentId=PAY-62998961VU1587338KR3AXWQ&token=EC-4YC2489096181311L&PayerID=REABK2UGK7PLW
As you can see it has paymentId which is the Id that you need to store.
So, to answer you dont need to store anything till 3rd step.
Additional Note:
However, if you have some complicated logic/service you want to provide. E.g. send them an email reminder(if you have their emailId), to remind them if they abandoned your card, etc. However, there are many ways to do that besides using these steps.

When to stop querying paypal api's for payment status?

Using the parallel payments paypal api. If user 1 makes a payment to user 2, I make a check using the api to make sure paypal returns the payment details as COMPLETED.
How long does paypal keep that COMPLETED payment record? Do they keep it indefinitely, or do they delete it after a while? I ask because I am at the stage of development where I need to decide if I should rely on paypal keeping that record indefinitely, or if I should create a record on my server that the payment has been completed, or if I should always check if the payment has been marked as COMPLETED by querying paypal?
The only reason why I "want" to check via paypal, is if the payment is ever returned to user1 as REFUNDED or PARITALLY_REFUNDED when paypal is queried using their apis. I would want to act accordingly in such situations.
It's not too much of an issue if the status is REFUNDED or PARTIALLY_REFUNDED as apparently people can't get refunds if they don't open a case with paypal before 45 days are up. I am more concerned about the REVERSED status, which can apparently happen any time, even after 45 days which is beyond paypal's control, as it is done by the credit card companies, if the user pays by credit card...
Using the PaymentDetails request I was able to pull my oldest Adaptive Payment transaction, which was over 60 days old and had no problems pulling it up using the transactionId field. It should be able to pull up payments as long as they are listed in the PayPal account (currently forever.)
This will work using the payKey field also if you are storing that instead of transactionId, however the transactionId is displayed in your PayPal account and is sent with IPN responses.

How to test buyer side of a Credit Card transaction on PayPal Website Payments Pro?

We are running an e-commerce web site on Ruby on Rails and for the processing of Credit Cards we use the ActiveMerchant plugin to interface to our PayPal Website Payments Pro account using our API credentials.
As part of the checkout process we first call the authorize function on our gateway object and then, after some further checks, we perform the capture part.
We have lately been experiencing a bug where an amount gets reserved twice on a customer's account: one charge being only the authorization and the second being the final purchase. So to the client it looks like we are billing him twice (once for authorization, once for final purchase) while we are actually receiving the money only once and the "second charge" on his account is simply an authorization that we don't clear for some reason. (This seems to happen particularly when PayPal FMF rejects our transaction and we re-process.)
I am trying to troubleshoot this by creating PayPal Sandbox Accounts for Buyer and for Seller. I am running through the code line by line via Rails Console and simulating different conditions to try and replicate the error. However, my successful Credit Card transactions only appear in my "seller"/"merchant" account and not in the "buyer" account on the PayPal Sandbox so I cannot see what the effect of my code sequence is having on a customer's card. This post seems to indicate that that is just the way things are and that it is indeed not possible to test the effect on Buyer Credit Card side. This post suggests using PayPal Express Checkout but that is not what we need on our site as we're specifically looking at Credit Card transactions here that are integrated to our site.
How can I test the effect of my code on a client's Credit Card? Is there perhaps something I missed in PayPal or is there maybe some mode/log/monitor in ActiveMerchant that I can use to see this? I need to find the line of code that is causing us to authorize twice.
If the initial transaction is being rejected by FMF, and then you reattempt another transaction this would cause a second hold on the buyers card as this would be a completely different transaction attempt. The bank may have approved the first transaction, but then the FMF filters declined it based on your settings. As far as the bank is concerned, it is still a valid charge that was approved. So when you run your second attempt, this will cause a second hold on the card for the same amount but for a different transaction.

Paypal IPN and transaction IDs

I currently have a simple Paypal button on my website where people enter some information which is saved into a database, and the button then takes them to paypal to pay £20 to join. The problem is there is no link between the website and paypal, so I have to manually cross check who has joined on the website against Paypal each time.
I've looked into Paypal IPN which looks ideal, but I can't work out how to match the transactions up.
i.e. IPN sends me a txn_id, but I don't have that at my end. I need a way to send a generate & save a unique ID per transaction, that goes to Paypal with the user, and Paypal then sends back to me via IPN.
I'm quite lost in Paypals shoddy docs, so any help from SO would help!
(Off topic rant: why to Paypal have so many domains: paypal.com, paypal-business.com, x.com, paypal-marketing.com,... Can they not spell phishing?!)
Pass YOUR id (like the DB row id) to Paypal with custom variable, you can cross reference it using the custom variable from IPN.
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables