Automatically capture a order in PayPal - paypal

I'm integrating my application with PayPal and i found a problem.
I use PayPal REST API with intent: "CAPTURE".
After I create an order in paypal via /v2/checkout/orders POST endpoint and client pay for this order in https://www.sandbox.paypal.com/checkoutnow?token={TOKEN} website I don't receive any money or transaction on my PayPal business account.
When I check this order status it says that it is APPROVED but not COMPLETED, so i need to capture this order via v2/checkout/orders/{TOKEN}/capture POST endpoint. After capturing this order is has status: COMPLETED and i receive money.
Is It possible to automatically capture an order without any additional request to capture it?
Because when I use PayPal button It works automatically and I want to have the same result using REST API.

No, it's not possible. The capture step is required.
Whether you use a client-side integration: https://developer.paypal.com/demo/checkout/#/pattern/client
Or a front-end UI that calls server-side routes of yours: https://developer.paypal.com/demo/checkout/#/pattern/server
The capture step after approval (within onApprove) is always required.

Related

Integrating PayPal Smart Payment API with old Express Checkout API

We currently have a system in place to process PayPal payments. It is done using the Express Checkout API. The method DoAuthorization accepts a 17 char TransactionID as a parameter.
I'm trying to implement the new PayPal Smart Payment Buttons API. I have the flow programmed with the intent=AUTHORIZE but I can only grab the Authorization ID and Order ID (both 17 char values) from the Auth response once its completed.
When I try and authorize the order and pass one of the 2 values into the DoAuthorization method, returns with an error: TransactionID invalid (10609).
My question is it possible to use the Smart Payments API Authorization ID and Order ID and pass it into the Express Checkout DoAuthorization method and still make the 2 systems work?
Could it be possible that I'm getting the 10609 error because the intent=Authorize already authorizes the order and I need to call the DoCapture method?
It is possible to use the SPB user interface, but not its API (actually it's built on the v2/orders REST API)
You can't mix v2/order API payment setups, with classic captures.
So, so long as you are using classic API calls to capture (this is a very unfortunate requirement that I would advise eliminating ASAP, but it's in your question) -- then, you need to also keep using classic API calls to set up the payment.
See the server demo pattern: https://developer.paypal.com/demo/checkout/#/pattern/server
The createOrder portion will do an XHR fetch to your server, which will then call the classic SetExpressCheckout and return an EC token. SPB will use the classic EC token, but show its new UI.

Paypal webhook instead of return url

Here is my flow of the payment.
Create Payment and return Url for user to verify
Using above Url user opens Paypal account and accepts payment
After accepting payment Paypal returns to success url.
Execute payment (final stage of the sale)
My Question is if there exists any webhook triggered after step 2, before step 3. Right after user verifies payment in it's personal paypal page.
The reason to catch webhook is not to rely on success redirect url rather than use webhook.
The terms you are using do not match the keywords you've used here.
Are you working with REST APIs or are you working with PayPal Standard / Classic APIs?
If you're working with REST APIs, then the simple answer is yes, you should use the Webhooks to handle any automated processing. Specifically, take a look at the SALE Webhooks. That should give you what you're after.
If you're working with Standard / Classic, the answer is the same except that you would use IPN instead of Webhooks.

Paypal REST API and Chargebacks/Cancellations

I have been working paypal integration to an existing system of ours and successfully done tests on sandbox by using rest api and express checkouts.
Although documentation is detailed, I couldnt see anything about chargeback (i.e reverse transactions) and cancellations on rest api documentation page http://developer.paypal.com/docs/api/
So in case a user buys something successfully and the payment status becomes "completed", then there is a reverse transaction like chargeback, paypal will send a request to the return and cancel urls which are predefined while creating the related payment, or the client application has to check the payment statuses manually by rest calls? Or are there any other configs that I need to send while triggering the very first payment request?
You'll need to setup Instant Payment Notification (IPN) to handle that sort of thing.
IPN will automatically POST data about all transactions that hit your PayPal account to a URL you specify. This URL (a script) can receive the data and update your database, generate email notifications, or anything else you might want to automate based on the transactions.
You can handle all sorts of things with IPN. For chargebacks specifically, you would receive an IPN with the following params...
txn_type=new_case
case_type=chargeback
Of course, you'll get a bunch more parameters, too, but those would be how you can pick out the chargebacks and processing them accordingly.

How to test a PayPal capture API call with Sandbox

I have setup PayPal Sandbox test accounts, a Personal (buyer) and a Business (merchant).
I'd like to test a PayPal 'DoCapture' API Operation. The problem I'm encountering is that I need an AuthorizationID and don't know how to obtain it. If i run the 'DoExpressCheckoutPayment' API call, I do not get an AuthorizationID returned, using the merchant API credentials, though I do get an 'ACK' of success. Do I need to be using the buyer credentials with the 'DoExpressCheckOutPayment' call? I don't see the API credentials in the PayPal Sandbox profile for the Personal account.
Express Checkout example with authorization and capturing you can find here.
Short answer - according with DoCapture documentation
AuthorizationID ... This is the transaction ID returned from DoExpressCheckoutPayment...
According with DoExpressCheckout documentation you need field from response, attention, PaymentInfo#TransactionId
... this value is your AuthorizationID for use with the Authorization & Capture APIs.
This is what you need to do to implement the capture API.
Create Payment: set intent as authorize in its request to get payment Id
Show Payment Details: to get approval_url. The customer will use this URL to pay for the order.
Execute approved PayPal payment: Use this API after customer successfully pays for the order. This API returns authorization-id along with capture link.
Use Capture API: use the URL obtained from step 3 to capture.
Use this link and check payments API.
https://developer.paypal.com/docs/api/payments/#payment_execute
Hope this helps to someone who stumbles upon here.

Paypal Rest API : Difference between Paypal execute and auth-capture

I am developing a system in which I have to integrate paypal. In the backend the system itself uses an internal API(I do have many systems communicates to core like web, mobile app etc). Consider the case of web, I am planning to approve the payment using the Paypal Rest API, so the user will be redirected to Paypal and approves the payment and then the system communicates with the internal api and then the actual payment has to be completed.
When going through the docs, I can see Payment->Execute need to be done after the approval. Also I can see Authorize and, Capture later as in other payment systems. So I am confused with the significance of execute method?
When you create the payment, you can the intent of the payment to be 'sale', 'authorize' or 'order'. For each of these you need to call payment->Execute, but the difference is in what happens after
When set to sale, payment will immediately be processed and funds transferred as soon as possible.
When set to authorize, you get back an authorization_id. The funds will be on hold for 3 days within which you use that id to to a capture on the payment to have the transaction processed.
When set to order, you get back an order_id. The order does not put fund on hold, but you can call authorize against the order to put the funds on hold and later call capture on that order to process the transaction and transfer funds.