0

Docs provides HTTP requests as example to "Capture an authorized payment": https://developer.paypal.com/docs/archive/payments/authorize-and-capture-payments/

Checkout-Java-SDK has only examples for capturing an order: https://github.com/paypal/Checkout-Java-SDK/blob/develop/checkout-sdk-sample/src/main/java/com/paypal/CaptureIntentExamples/CaptureOrder.java

How to use Checkout-Java-SDK to achieve the same as the docs shows with the HTTP request? How to capture an authorized payment using PayPal Checkout-Java-SDK?

Marat
  • 39
  • 5

1 Answers1

1

If you need to use authorizations, see the AuthorizationIntentExamples directory in that project.

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • Hello, thank you for your answer. I've found the captureOrder function by your link, but I can't find there how to set the amount? Here: https://github.com/paypal/Checkout-Java-SDK/blob/develop/checkout-sdk-sample/src/main/java/com/paypal/AuthorizeIntentExamples/CaptureOrder.java – Marat May 14 '22 at 16:08
  • 1
    See the classes in https://github.com/paypal/Checkout-Java-SDK/tree/develop/checkout-sdk/src/main/java/com/paypal/payments , particularly CaptureRequest – Preston PHX May 14 '22 at 16:45
  • How to void (cancel) authorization? I've found AuthorizationsVoidRequest method, but it seems raw and path and header that belongs to com.paypal.http.HttpRequest not available without initialization of HttpRequest – Marat May 14 '22 at 18:21
  • I have found the void: AuthorizationsVoidRequest request = new AuthorizationsVoidRequest("AUTHORIZATION-ID"); HttpResponse response = client().execute(request); – Marat May 14 '22 at 19:04
  • in your answer above you said "If you need to use authorizations", do you mean authorizations might be avoided? – Marat May 17 '22 at 18:31
  • is it possible to do the authorization without order using Checkout-Java-SDK? – Marat May 17 '22 at 18:48
  • 1
    Orders are used to receive approval from a payer; without an order, there is no payment. To not use authorizations, the order should have intent:capture. This is the default. – Preston PHX May 17 '22 at 19:13
  • Is it an innovation of Checkout-Java-SDK? It seems that old SDK was able to use authorizations without orders – Marat May 17 '22 at 19:17
  • 1
    The v1 APIs and old SDK used payments for the approval process, instead of orders for the approval process. Different names, same process. – Preston PHX May 17 '22 at 19:20
  • I have found your answer on difference about v2/orders and v2/payments here: https://stackoverflow.com/questions/67476475 So v2/orders is for the payer approval process, but it allows to capture an order and to refund it, while v2/payments if for working with authorizations. I haven't found a way to void an order, is it only possible with v2/payments? So the difference between this two APIs is v2/orders works with order IDs, while v2/payments works with authorizations and among capture and refund also allows to void? – Marat May 17 '22 at 19:31
  • 1
    That's a separate conversation from what you had asked, since v1/payments and v2/payments are different things. Anyway, orders with intent capture should be captured immediately. If you are not going to capture immediately, use authorizations. – Preston PHX May 17 '22 at 19:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244821/discussion-between-marat-and-preston-phx). – Marat May 17 '22 at 19:39
  • So if I'm not going to capture immediately I need to use v2/payments, otherwise if I want to capture immediately I need to use v2/orders, right? – Marat May 17 '22 at 19:48
  • This link doesn't work, which one replaces it? https://developer.paypal.com/docs/checkout/reference/server-integration/ – Marat May 17 '22 at 21:26
  • 1
    ... v2/payments is for post-approval payment lifecycle tasks when the customer is not present, such as capturing an authorization or issuing a refund – Preston PHX May 17 '22 at 23:32
  • 1
    You can find a full stack example in node at https://developer.paypal.com/docs/checkout/standard/integrate/ , the backend can of course be implemented in any language. Using the SDKs is optional. The API reference is https://developer.paypal.com/docs/api/orders/v2/ – Preston PHX May 17 '22 at 23:33
  • 1
    Just be sure to use everything in https://developer.paypal.com/demo/checkout/#/pattern/server for the approval flow, since it has the proper error handling – Preston PHX May 17 '22 at 23:34
  • In this question https://stackoverflow.com/questions/62131346/ you said that there is no need for webhooks when using this server-side integration, is it means the same even if I don't want to capture immediately? – Marat May 18 '22 at 00:00
  • 1
    Correct........ – Preston PHX May 18 '22 at 00:09
  • Do you mean that webhooks is not needed at all in all situations? Are webhooks completely absolutely useless for PayPal? – Marat May 18 '22 at 00:11
  • 1
    No, webhooks are \*necessary* only for events that take place when you are not communicating via API, for example subscriptions, or being notified of refunds via the paypal.com interface , or some other exception such as a dispute. For everything else webhooks are optional, and generally a bad idea to rely on since they add complexity and potential points of failure and delay. Use the immediate API response whenever possible, such as after payer approval when capturing/authorizing an order, or when capturing an authorization, or doing a refund via API, etc. – Preston PHX May 18 '22 at 00:13
  • In other worlds if you can solve something with Checkout-Java-SDK do not try webhooks? What PayPal subscriptions is used for? Do you mean refunds and dispute by client side? – Marat May 18 '22 at 00:18
  • 1
    Right, don't use webhooks if the API response is already giving you the information you need. Refunds can happen on the PayPal end, if your software needs to be notified then implement webhooks – Preston PHX May 18 '22 at 00:20
  • May I ask for a full list of cases where I might need PayPal webhooks or PayPal subscriptions? – Marat May 18 '22 at 00:33
  • 1
    Subscriptions are for recurring payments that happen on a schedule. Webhook events are listed at https://developer.paypal.com/api/rest/webhooks/event-names/ -- if one of those events is something you desire/need to be notified of independent of immediate API responses you are already receiving, create (register) a webhook for it – Preston PHX May 18 '22 at 00:42