PayPal Express Checkout Capture Funds - php

I have written and successfully processed paypal functions on my clients site. They just want to be able to finalize the bill after they have shipped the product as the cost is very hard to calculate as products vary in size, quantity, ect. I currently have it set up so that they authorize a payment after using express checkout API as I have set $paymentType = "Authorization"; in stead of sale as the paymentType. All orders are tracked and logged in the database of the clients site they get a list of what the customer ordered, shipping info, ect on the admin side of the site. Only problem is once they have completed the order they mark it done on their site they must log into paypal and finalize the order by capturing the funds. How would I go about to capture funds using the classic API? I have found how to do it using the rest api, but I'm not going to rewrite my site to do it.
From the research I have done I have found that you can do it as I stated with the rest api and nvp or merchant api, but I'm using Express Checkout in PHP. I haven't been able to find how to use PHP and capture the funds.
My current code set up looks like this
//Orders are listed out using an array of mysql databases
......
**Where I need assistance**
//Capture funds from Paypal here
//return status of successful via self posting form
....
//And then I have
//a get function that marks the order as completed in the database
To summarize my question is how would(if possible) using the classic api and express checkout capture funds from paypal? As you can see I have given some thought to this I'm just stuck and can't figure it out.

The DoCapture API is what you're looking for. You'll pass in the transaction ID you got back from the Express Checkout Authorization along with the amount you're capturing.

Related

PayPal API refunds through PayPal plugin on WordPress / WooCommerce

I am currently using the current PayPal plugin https://wordpress.org/plugins/woocommerce-paypal-payments/
I have used the PayPal API to render more than one PayPal button on a page as the above plugin does not allow you to do this.
After the PayPal transaction is approved, it runs a PHP function that creates a WooCommerce order and fills in the data from the PayPal transaction such as the refund ID and setting the correct payment gateway etc. This all goes through great, but when it comes to refunding with the above plugin it fails.
I have compared the CSV files from both the API implementation and standard checkout process and both seem to be bringing in the same data.
I have done a bit of research and it seems that if an order is placed through checkout with the plugin, it creates its own order id, which may link back to the correct refund ID from the transaction. I have contacted their plugin support, but they have been unable to tell me.
Any help on this issue would be greatly appreciated!
When that plugin creates an order, an invoice_id and custom_id are set on these lines in the code.
The invoice ID is later used when doing a refund.
If you backtrack through that code doing the refund, it first makes use of a GET API call to the PayPal Order endpoint, which happens within here.
I highlight the particular line where this GET call depends on some meta information with the PayPal Gateway Order ID.
As an aside, this refund process is not well implemented by this WooCommerce plugin. Refunds are ultimately done using a capture ID, and should not rely on the Orders endpoint being accessible to provide a GET response that includes that capture ID. It works well enough so long as the PayPal Orders endpoint retains a record of that Order ID (which is not forever, as it's not an accounting value), but this is wrong to rely on. Instead, the Capture ID (eq. to the PayPal transaction ID) is what should be stored at transaction completion/capture time (as meta), and that stored meta value can then later be directly used to use the v2/payments refund, with no GET API request to the Orders API endpoint. The Orders API endpoint is only meant to be used during checkout approval, it is incorrect to be relying on it for anything once an order capture is successfully completed.

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.

How can I make an automatic PayPal buy button?

I want my PHP web application to have the ability to save the user's PayPal details in their user account.
When they go to purchase items, rather than going through the standard PayPal form, it will automatically grab the user's PayPal details from their user account, and make the payment directly from my website. There is definitely a way to do this, as I have seen this feature on sites such as Freelancer.com
Thanks for the help! :)
No, you don't need Payments Pro for that. That would only be if you want to do it with direct credit cards. What you're after in general is called Reference Transactions, and when done with PayPal Express Checkout it uses Billing Agreements.
You'll use Express Checkout and/or Payments Pro (optional) to process an original authorization or sale transaction. Then, you can send that ID you get back in that original transaction along with a new amount in the DoReferenceTransaction API and that new amount will be instantly processed without any redirection or further authorization required.

PayPal REST API cross reference transaction with payment

I have managed to complete a PayPal payment using the REST PHP API. However, I want to know how to cross reference the REST transaction with the PayPal web user interface.
On the REST side I have payment id (getID()) received before the transaction is approved. It looks like 'PAY-5BH83448XN85470XXXXXXXXXXX'.
After the transaction is approved, I receive back at my redirect URL three other pieces of information:
- success=true
- token=EC-51Y92978Mxxxxxxxx
- PayerID=4Q7YVxxxxxxxx
When I log into PayPal and review the payment, none of these IDs match up with what is shown. The details for the payment show a Unique Transaction ID like #4PP59868EXXXXXXXX that does not match anything above.
How do I cross reference these different pieces of data?
The response to the payment call will contain a list of transactions, which contains a set of related resources. For a completed payment there will be a sale item, the id of the sale is the PayPal transaction id.
For ex (pseudo): payment.transactions[0].related_resources[sale].id
Sample here: https://developer.paypal.com/webapps/developer/docs/integration/direct/accept-credit-cards/

Categories