How to programmatically approve order using PayPal v2 orders API - paypal

I would like to use my sandbox mock customer credentials to programmatically approve 'order with intent to capture' I created earlier using the new v2 orders api.
My end goal is to have an end to end test where an order is created, approved, captured and refunded.

There is no PayPal method for programmatically approving an order. The two methods for approving an order are redirecting a user agent to the approval_url (legacy method), or using an in-context Smart Button (recommended).

Related

Paypal add custom_id directly in order url

Can I attach custom_id to paypal order link like that (&custom_id=${customId})? Or in order to add custom_id I MUST use paypal-js?
https://www.paypal.com/webapps/billing/plans/subscribe?plan_id=${plan_d}&custom_id=${customId}
It cannot be added to a URL, you need to create the subscription for every checkout attempt.
You can create the subscription using the JS SDK, which gives the best in-context approval flow (not redirecting away from your website, keeping it loaded in the background) -- or you can do so with the REST API and get a link for approval, which is an older flow.

Integrating Paypal Payment and Invoicing APIs

I have been manually issuing invoices to charge my clients for services using Paypal.
Now I am creating an interface to allow them to purchase the services automatically on my website.
I also want to show them a history of their purchases. However, I cannot show a history of paid invoices using the Transaction Search API; I need to use the Invoicing > Search Invoices API.
I have used the Paypal Payments API to manage the payment side of new products, which now correctly produces an itemised transaction and allows the customer to checkout. But this does not produce an invoice.
How can I simultaneously produce an invoice (i.e which can be retrieved by the Invoicing API to show previous payments) and allow the customer to pay it? It seems like the Invoicing API works around the idea of sending an invoice to client by email, but this is unnecessary. I want them to pay it immediately (and already have the Payment API setup for this).
So what would a useful workflow be?: Use my Paypal Payment API to receive and authorise the payment, and on authorisation, use the Invoicing API to produce an invoice which reflects this and then updates the invoice status to paid? Or am I missing something easier here?
The Invoicing API is not meant to be mixed or used with any other API. It is for generating invoices to be sent by email or in link form.
General ecommerce payment processing (without invoice links) is entirely separate, there is no crossover. You should ensure you are using the current v2/checkout/orders API to receive new payments, not older v1 APIs.
As far as displaying a list of previous purchases to your customers, you shouldn't reply on PayPal for this (except perhaps in the case of invoices since this is part of the point of offloading invoice management to PayPal). But for normal web purchases, PayPal is not a database -- it is a payment processing service. Keep track of all your own order information, and simply store PayPal transaction IDs when they complete for your own accounting records -- but the ID you reference with the customer should be your own unique order ID, which you can pass to PayPal in your purchase_units[0].invoice_id when you create an order for checkout approval.

Automatically capture a order in 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.

Using API or customer permission, Is it possible to get payment from customer account any time?

Using API or customer permission, Is it possible to get payment from customer account any time ?
Actually I have one cloth store,
When my custom make payment first time while purchasing something using paypal wallet/account, i will have set of permission from his paypal account,
Using that i need a functionality when that person buy second time, there account will be auto debited, using their saved paypal token
Is Paypal provide this type of any services or API ?
If yes then tell me some more details i.e. how it works and what is require for that i.e token, API key or any other.
You can refer to the link below for the details to see if this payment method meet your requirement.
https://developer.paypal.com/docs/integration/direct/billing-plans-and-agreements/?mark=billing%20agreement

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.