PayPal PHP SDK, Getting the Payment Amount - php

I am using PayPal PHP SDK for processing PayPal payments.
A user adds items to my cart and then chooses to pay via PayPal. I construct a Paypal PAYMENT, send the PAYMENT to Paypal, the user logs in and approves the PAYMENT. The user is then redirected back to my website with the three $_GET parameters where I can then execute the PAYMENT.
All good so far.
According to the code, a PAYMENT holds an array of TRANSACTIONS. It seems each TRANSACTION holds an AMOUNT.
My Question: How do I retrieve what the user paid? If there are multiple TRANSACTIONS that can take place under one PAYMENT - how do I know which TRANSACTION'S AMOUNT to use?
(When I pass the initial PAYMENT to PayPal for approval, I do only provide one TRANSACTION, so I would assume when PayPal returns the approval back to my site, there will still be only one TRANSACTION, however, I do not want to assume this will always be the case!)

Related

Authorize.Net Paypal Express PHP API: Issue with transaction not updating in Authorize.Net , nor capturing correct amount

We've implemented the Paypal Express API through Authorize.Net in PHP (https://developer.authorize.net/api/reference/features/paypal.html). It was finished over a year ago, and has been working fine. What we realized recently, is that the when the Paypal authorization is updated in step 2 "Authorization Only, Continued", it is not updated in Authorize.Net . When a capture takes place, it only captures the original amount, despite Paypal having the correct, updated amount.
Here is our flow (following the Authorize.Net/Paypal API instructions):
We send a request to Authorize.Net/Paypal to create a transaction. Inside is the total cost of goods.
Paypal returns a secure link, onto which we redirect the user
Paypal redirects the user back to us with a token. We use the token to get shipping data for the user and to get the authorization/transaction ID.
We calculate tax based on shipping data and send the user to a confirm page for review.
When the user submits, we send the second authorization request (Authorization Only, Continued), as documented, using the gateway transaction ID to update the transaction with the new amount, etc.
Now the problem is, Authorize.Net still has the original amount (without the tax). When we run a capture on this transaction via the same API, for some reason it only captures the original amount, not the amount with the tax. We're making tons of transactions now, and not receiving the tax dollars for any of them.
Here is the same transaction in Paypal and Authorize.Net. Paypal's screen shows the authorization at $120, and the update at $130.xx with shipping.
And Authorize.Net shows it successfully captured at $120.
These are the same transaction, and we're only using the Authorize.Net Paypal Express API. How is Authorize.Net not getting the update? Why is it not capturing the full amount?
When we run a capture on this transaction via the same API, for some reason it only captures the original amount, not the amount with the tax.
You need to either:
Capture the second authorization, not the original transaction. This should be the correct solution.
Send a capture request that includes the details of the new amounts you are capturing.

paypal Preapproval API

we are trying to add a pre-approval paypal process to our website before a user can bid on any of our items for sale. We currently accomplished this using Authorize.net but want to now integrate paypal as well.
I have been doing some research and am trying to find out if paypal even offers such a solution. The main reason for adding this verification is of course to make sure an individual actually has the money to purchase the item, some items can range from $100-$100,000. Does paypal offer a pre approval process for those types of transactions?
https://developer.paypal.com/docs/classic/api/adaptive-payments/Preapproval_API_Operation/
The Preapproval API gives your application permissions to trigger payments on a user's behalf without further approval (no login required to submit payments with a preapproval ID). There is no guarantee funds will be available when you submit this payment. A transaction with a preapproval ID could simply fail like any other transaction.
It sounds like what you're looking is the Authorization and Capture process, which is probably what you're doing with Auth.net, too.
With PayPal you can run Authorizations from credit cards directly (exactly like you do with Auth.net) and you can also do it with Express Checkout, which would be PayPal login payments.

PayPal detect insufficient funds

We have a little problem in our system, we allow customers to pay using PayPal which is great!
But in the following situation we have this issue:
A customer pays us using PayPal.
We send the product to our customer when the transaction has completed.
A few days later, PayPal refuses to pay us because the customer have his PayPal account connected with his bank account. And the funds on that bank account is too low.
So, is there a way to let PayPal know us when this happens through API/URL call to our server ?
As Dagon mentioned, IPN is the best way to handle this.
You'll setup a listener script on your server, and every time a transaction happens on your PayPal account, the PayPal server will POST data about that account to your listener script. You'll get different parameters depending on the type of transaction that occurs. You can see a list of the types and parameters here.
You can build your email notifications, database updates, etc. into your IPN script to fully automate post-payment processing tasks.
So, in the example you've provided, what would happen is when the transaction first takes place the IPN would be triggered with a payment_status of Pending, and then you'd also see a parameter called pending_reason with a value of echeck. This tells you the payment was made, but it's an echeck which takes time to clear, so the status again is Pending instead of Completed.
A few days later when that payment does clear (or fails) you'd get another IPN with an updated payment_status. Only upon receiving an actual COMPLETED payment_status would you then would you deliver the order.
Again, this can all be automated within your IPN script.

Paypal api get success or failed

Ok so I have built my shopping cart system for my site that uses PayPal Parallel Payments to multiple sellers since the site allows users to sell thier own items and when a buyer buys stuff, they can buy from many sellers at once. I then figure out the payment to each seller including fee's and then send the user off to paypal where they would pay.
The part I am not sure of is do I create the order ID and update in the DataBase the order has been created but not paid for yet. Then when the users pays for it in paypal, I would update order in the Database it has been paid. At which point I would allow the user access to the content they paid for.
I guess I am asking how do I check to see if the user has payed in PayPal or if the transaction failed due to insufficient funds or something? Is there way to search by the order ID in paypal to see if the order has been paid for?
edit: I know I could use the return URL but that doesn't seem very safe?
Once a Payment is executed (payKey created, user has been redirected to PayPal, approved payment, and is redirected back to your return URL), you can then use the Adaptive Payments API to call and check the status of the payment to determine if the money has really moved.
Use the PaymentDetails call - the status should be COMPLETED if the payment was successful.

Committing payment on sellers website

I am working on a project which will be able to accept paypal payments. The sequence I am using is as follows:
My current development sites' payment steps:
The user goes to my site,
Chooses to pay for something,
Is redirected to paypal,
The payment is completed on paypal,
Then the user gets redirected back to my sites success url.
This works fine, as I use an IPN listener to update my database in the background when paypal decides to confirm the committed payment and let the user know accordingly.
However, a few days ago, I was doing some online shopping of my own, and paid using paypal. I noticed that when I paid, I was redirected to paypal, where I logged in and saw the paypal invoice. I clicked confirm, and I was redirected back to the sellers website, where I so a summary and was told to commit the purchase!!!
So basically, the sequence was something like this:
My shopping experience from a different sellers site:
I wanted to pay for the items,
I was redirected to paypal,
I was the invoice and confirmed the payment,
I was redirected to the sellers site,
I was was shown a confirmation of the order and was asked to commit the payment,
I committed the payment and was told that the order has been completed.
The difference, my site commits the purchase on the paypal website and I listen for a reponse from paypal using their IPN system, but this second site seems to commit the payment on the sellers actual website.
I thought, wow, that felt so much more reassuring from a user experience point of view.
How is that done?
Sounds like you're currently using Payments Standard and you want Express Checkout.
Express Checkout is very similar to Standard except that it's API based and the user gets returned to your site prior to finalizing the payment.
It consists of 3 API calls...
1) SetExpressCheckout - gets a token back from PayPal that you append to the end of a redirect URL that sends the person over to PayPal to login and review the payment.
2) GetExpressCheckoutDetails - This allows you to pull the payer details (name, phone, shipping address, etc.) back into your app from PayPal. This is an optional step.
3) DoExpressCheckoutPayament - this finalizes the payment. No money is moved until this API call happens, and it doesn't happen, of course, until the user is already back at your site and within your own app flow again.
You can still use IPN the way you are, but you could also things directly within the flow as well since you get instant responses back from the API, and you can setup your own review however you want to.

Categories