Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* PaypalServerSDKLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
package com.paypal.sdk.controllers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.paypal.sdk.ApiHelper;
import com.paypal.sdk.Server;
import com.paypal.sdk.exceptions.ApiException;
import com.paypal.sdk.exceptions.ErrorException;
import com.paypal.sdk.http.request.HttpMethod;
import com.paypal.sdk.http.response.ApiResponse;
import com.paypal.sdk.models.Order;
import com.paypal.sdk.models.OrderAuthorizeResponse;
import com.paypal.sdk.models.OrdersAuthorizeInput;
import com.paypal.sdk.models.OrdersCaptureInput;
import com.paypal.sdk.models.OrdersConfirmInput;
import com.paypal.sdk.models.OrdersCreateInput;
import com.paypal.sdk.models.OrdersGetInput;
import com.paypal.sdk.models.OrdersPatchInput;
import com.paypal.sdk.models.OrdersTrackCreateInput;
import com.paypal.sdk.models.OrdersTrackersPatchInput;
import io.apimatic.core.ApiCall;
import io.apimatic.core.ErrorCase;
import io.apimatic.core.GlobalConfiguration;
import io.apimatic.coreinterfaces.http.request.ResponseClassType;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
/**
* This class lists all the endpoints of the groups.
*/
public final class OrdersController extends BaseController {
/**
* Initializes the controller.
* @param globalConfig Configurations added in client.
*/
public OrdersController(GlobalConfiguration globalConfig) {
super(globalConfig);
}
/**
* Creates an order. Merchants and partners can add Level 2 and 3 data to payments to reduce
* risk and payment processing costs. For more information about processing payments, see <a
* href="https://developer.paypal.com/docs/checkout/advanced/processing/">checkout</a> or <a
* href="https://developer.paypal.com/docs/multiparty/checkout/advanced/processing/">multiparty
* checkout</a>.<blockquote><strong>Note:</strong> For error handling and troubleshooting, see
* <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#create-order">Orders
* v2 errors</a>.</blockquote>.
* @param input OrdersCreateInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ApiResponse ordersCreate(
final OrdersCreateInput input) throws ApiException, IOException {
return prepareOrdersCreateRequest(input).execute();
}
/**
* Creates an order. Merchants and partners can add Level 2 and 3 data to payments to reduce
* risk and payment processing costs. For more information about processing payments, see <a
* href="https://developer.paypal.com/docs/checkout/advanced/processing/">checkout</a> or <a
* href="https://developer.paypal.com/docs/multiparty/checkout/advanced/processing/">multiparty
* checkout</a>.<blockquote><strong>Note:</strong> For error handling and troubleshooting, see
* <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#create-order">Orders
* v2 errors</a>.</blockquote>.
* @param input OrdersCreateInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
*/
public CompletableFuture> ordersCreateAsync(
final OrdersCreateInput input) {
try {
return prepareOrdersCreateRequest(input).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for ordersCreate.
*/
private ApiCall, ApiException> prepareOrdersCreateRequest(
final OrdersCreateInput input) throws JsonProcessingException, IOException {
return new ApiCall.Builder, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/checkout/orders")
.bodyParam(param -> param.value(input.getBody()))
.bodySerializer(() -> ApiHelper.serialize(input.getBody()))
.headerParam(param -> param.key("Content-Type")
.value("application/json").isRequired(false))
.headerParam(param -> param.key("PayPal-Request-Id")
.value(input.getPayPalRequestId()).isRequired(false))
.headerParam(param -> param.key("PayPal-Partner-Attribution-Id")
.value(input.getPayPalPartnerAttributionId()).isRequired(false))
.headerParam(param -> param.key("PayPal-Client-Metadata-Id")
.value(input.getPayPalClientMetadataId()).isRequired(false))
.headerParam(param -> param.key("Prefer")
.value(input.getPrefer()).isRequired(false))
.headerParam(param -> param.key("accept").value("application/json"))
.withAuth(auth -> auth
.add("Oauth2"))
.httpMethod(HttpMethod.POST))
.responseHandler(responseHandler -> responseHandler
.responseClassType(ResponseClassType.API_RESPONSE)
.apiResponseDeserializer(
response -> ApiHelper.deserialize(response, Order.class))
.nullify404(false)
.localErrorCase("400",
ErrorCase.setReason("Request is not well-formed, syntactically incorrect, or violates schema.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("401",
ErrorCase.setReason("Authentication failed due to missing authorization header, or invalid authentication credentials.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("422",
ErrorCase.setReason("The requested action could not be performed, semantically incorrect, or failed business validation.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase(ErrorCase.DEFAULT,
ErrorCase.setReason("The error response.",
(reason, context) -> new ErrorException(reason, context)))
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Shows details for an order, by ID.<blockquote><strong>Note:</strong> For error handling and
* troubleshooting, see <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#get-order">Orders v2
* errors</a>.</blockquote>.
* @param input OrdersGetInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ApiResponse ordersGet(
final OrdersGetInput input) throws ApiException, IOException {
return prepareOrdersGetRequest(input).execute();
}
/**
* Shows details for an order, by ID.<blockquote><strong>Note:</strong> For error handling and
* troubleshooting, see <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#get-order">Orders v2
* errors</a>.</blockquote>.
* @param input OrdersGetInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
*/
public CompletableFuture> ordersGetAsync(
final OrdersGetInput input) {
try {
return prepareOrdersGetRequest(input).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for ordersGet.
*/
private ApiCall, ApiException> prepareOrdersGetRequest(
final OrdersGetInput input) throws IOException {
return new ApiCall.Builder, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/checkout/orders/{id}")
.queryParam(param -> param.key("fields")
.value(input.getFields()).isRequired(false))
.templateParam(param -> param.key("id").value(input.getId())
.shouldEncode(true))
.headerParam(param -> param.key("accept").value("application/json"))
.withAuth(auth -> auth
.add("Oauth2"))
.httpMethod(HttpMethod.GET))
.responseHandler(responseHandler -> responseHandler
.responseClassType(ResponseClassType.API_RESPONSE)
.apiResponseDeserializer(
response -> ApiHelper.deserialize(response, Order.class))
.nullify404(false)
.localErrorCase("401",
ErrorCase.setReason("Authentication failed due to missing authorization header, or invalid authentication credentials.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("404",
ErrorCase.setReason("The specified resource does not exist.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase(ErrorCase.DEFAULT,
ErrorCase.setReason("The error response.",
(reason, context) -> new ErrorException(reason, context)))
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Updates an order with a `CREATED` or `APPROVED` status. You cannot update an order with the
* `COMPLETED` status.<br/><br/>To make an update, you must provide a `reference_id`. If you
* omit this value with an order that contains only one purchase unit, PayPal sets the value to
* `default` which enables you to use the path:
* <code>\"/purchase_units/{@literal @}reference_id=='default'/{attribute-or-object}\"</code>. Merchants
* and partners can add Level 2 and 3 data to payments to reduce risk and payment processing
* costs. For more information about processing payments, see <a
* href="https://developer.paypal.com/docs/checkout/advanced/processing/">checkout</a> or <a
* href="https://developer.paypal.com/docs/multiparty/checkout/advanced/processing/">multiparty
* checkout</a>.<blockquote><strong>Note:</strong> For error handling and troubleshooting, see
* <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#patch-order">Orders
* v2 errors</a>.</blockquote>Patchable attributes or
* objects:<br/><br/><table><thead><th>Attribute</th><th>Op</th><th>Notes</th></thead><tbody><tr><td><code>intent</code></td><td>replace</td><td></td></tr><tr><td><code>payer</code></td><td>replace,
* add</td><td>Using replace op for <code>payer</code> will replace the whole <code>payer</code>
* object with the value sent in
* request.</td></tr><tr><td><code>purchase_units</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].custom_id</code></td><td>replace, add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].description</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].payee.email</code></td><td>replace</td><td></td></tr><tr><td><code>purchase_units[].shipping.name</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.email_address</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.phone_number</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.options</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.address</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.type</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].soft_descriptor</code></td><td>replace,
* remove</td><td></td></tr><tr><td><code>purchase_units[].amount</code></td><td>replace</td><td></td></tr><tr><td><code>purchase_units[].items</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].invoice_id</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].payment_instruction</code></td><td>replace</td><td></td></tr><tr><td><code>purchase_units[].payment_instruction.disbursement_mode</code></td><td>replace</td><td>By
* default, <code>disbursement_mode</code> is
* <code>INSTANT</code>.</td></tr><tr><td><code>purchase_units[].payment_instruction.payee_receivable_fx_rate_id</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].payment_instruction.platform_fees</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].supplementary_data.airline</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].supplementary_data.card</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>application_context.client_configuration</code></td><td>replace,
* add</td><td></td></tr></tbody></table>.
* @param input OrdersPatchInput object containing request parameters
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ApiResponse ordersPatch(
final OrdersPatchInput input) throws ApiException, IOException {
return prepareOrdersPatchRequest(input).execute();
}
/**
* Updates an order with a `CREATED` or `APPROVED` status. You cannot update an order with the
* `COMPLETED` status.<br/><br/>To make an update, you must provide a `reference_id`. If you
* omit this value with an order that contains only one purchase unit, PayPal sets the value to
* `default` which enables you to use the path:
* <code>\"/purchase_units/{@literal @}reference_id=='default'/{attribute-or-object}\"</code>. Merchants
* and partners can add Level 2 and 3 data to payments to reduce risk and payment processing
* costs. For more information about processing payments, see <a
* href="https://developer.paypal.com/docs/checkout/advanced/processing/">checkout</a> or <a
* href="https://developer.paypal.com/docs/multiparty/checkout/advanced/processing/">multiparty
* checkout</a>.<blockquote><strong>Note:</strong> For error handling and troubleshooting, see
* <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#patch-order">Orders
* v2 errors</a>.</blockquote>Patchable attributes or
* objects:<br/><br/><table><thead><th>Attribute</th><th>Op</th><th>Notes</th></thead><tbody><tr><td><code>intent</code></td><td>replace</td><td></td></tr><tr><td><code>payer</code></td><td>replace,
* add</td><td>Using replace op for <code>payer</code> will replace the whole <code>payer</code>
* object with the value sent in
* request.</td></tr><tr><td><code>purchase_units</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].custom_id</code></td><td>replace, add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].description</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].payee.email</code></td><td>replace</td><td></td></tr><tr><td><code>purchase_units[].shipping.name</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.email_address</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.phone_number</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.options</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.address</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].shipping.type</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>purchase_units[].soft_descriptor</code></td><td>replace,
* remove</td><td></td></tr><tr><td><code>purchase_units[].amount</code></td><td>replace</td><td></td></tr><tr><td><code>purchase_units[].items</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].invoice_id</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].payment_instruction</code></td><td>replace</td><td></td></tr><tr><td><code>purchase_units[].payment_instruction.disbursement_mode</code></td><td>replace</td><td>By
* default, <code>disbursement_mode</code> is
* <code>INSTANT</code>.</td></tr><tr><td><code>purchase_units[].payment_instruction.payee_receivable_fx_rate_id</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].payment_instruction.platform_fees</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].supplementary_data.airline</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>purchase_units[].supplementary_data.card</code></td><td>replace,
* add,
* remove</td><td></td></tr><tr><td><code>application_context.client_configuration</code></td><td>replace,
* add</td><td></td></tr></tbody></table>.
* @param input OrdersPatchInput object containing request parameters
* @return Returns the Void wrapped in ApiResponse response from the API call
*/
public CompletableFuture> ordersPatchAsync(
final OrdersPatchInput input) {
try {
return prepareOrdersPatchRequest(input).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for ordersPatch.
*/
private ApiCall, ApiException> prepareOrdersPatchRequest(
final OrdersPatchInput input) throws JsonProcessingException, IOException {
return new ApiCall.Builder, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/checkout/orders/{id}")
.bodyParam(param -> param.value(input.getBody()).isRequired(false))
.bodySerializer(() -> ApiHelper.serialize(input.getBody()))
.templateParam(param -> param.key("id").value(input.getId())
.shouldEncode(true))
.headerParam(param -> param.key("Content-Type")
.value("application/json").isRequired(false))
.withAuth(auth -> auth
.add("Oauth2"))
.httpMethod(HttpMethod.PATCH))
.responseHandler(responseHandler -> responseHandler
.responseClassType(ResponseClassType.API_RESPONSE)
.nullify404(false)
.localErrorCase("400",
ErrorCase.setReason("Request is not well-formed, syntactically incorrect, or violates schema.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("401",
ErrorCase.setReason("Authentication failed due to missing authorization header, or invalid authentication credentials.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("404",
ErrorCase.setReason("The specified resource does not exist.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("422",
ErrorCase.setReason("The requested action could not be performed, semantically incorrect, or failed business validation.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase(ErrorCase.DEFAULT,
ErrorCase.setReason("The error response.",
(reason, context) -> new ErrorException(reason, context)))
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Payer confirms their intent to pay for the the Order with the given payment source.
* @param input OrdersConfirmInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ApiResponse ordersConfirm(
final OrdersConfirmInput input) throws ApiException, IOException {
return prepareOrdersConfirmRequest(input).execute();
}
/**
* Payer confirms their intent to pay for the the Order with the given payment source.
* @param input OrdersConfirmInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
*/
public CompletableFuture> ordersConfirmAsync(
final OrdersConfirmInput input) {
try {
return prepareOrdersConfirmRequest(input).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for ordersConfirm.
*/
private ApiCall, ApiException> prepareOrdersConfirmRequest(
final OrdersConfirmInput input) throws JsonProcessingException, IOException {
return new ApiCall.Builder, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/checkout/orders/{id}/confirm-payment-source")
.bodyParam(param -> param.value(input.getBody()).isRequired(false))
.bodySerializer(() -> ApiHelper.serialize(input.getBody()))
.templateParam(param -> param.key("id").value(input.getId())
.shouldEncode(true))
.headerParam(param -> param.key("Content-Type")
.value("application/json").isRequired(false))
.headerParam(param -> param.key("PayPal-Client-Metadata-Id")
.value(input.getPayPalClientMetadataId()).isRequired(false))
.headerParam(param -> param.key("Prefer")
.value(input.getPrefer()).isRequired(false))
.headerParam(param -> param.key("accept").value("application/json"))
.withAuth(auth -> auth
.add("Oauth2"))
.httpMethod(HttpMethod.POST))
.responseHandler(responseHandler -> responseHandler
.responseClassType(ResponseClassType.API_RESPONSE)
.apiResponseDeserializer(
response -> ApiHelper.deserialize(response, Order.class))
.nullify404(false)
.localErrorCase("400",
ErrorCase.setReason("Request is not well-formed, syntactically incorrect, or violates schema.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("403",
ErrorCase.setReason("Authorization failed due to insufficient permissions.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("422",
ErrorCase.setReason("The requested action could not be performed, semantically incorrect, or failed business validation.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("500",
ErrorCase.setReason("An internal server error has occurred.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase(ErrorCase.DEFAULT,
ErrorCase.setReason("The error response.",
(reason, context) -> new ErrorException(reason, context)))
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Authorizes payment for an order. To successfully authorize payment for an order, the buyer
* must first approve the order or a valid payment_source must be provided in the request. A
* buyer can approve the order upon being redirected to the rel:approve URL that was returned in
* the HATEOAS links in the create order response.<blockquote><strong>Note:</strong> For error
* handling and troubleshooting, see <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#authorize-order">Orders
* v2 errors</a>.</blockquote>.
* @param input OrdersAuthorizeInput object containing request parameters
* @return Returns the OrderAuthorizeResponse wrapped in ApiResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ApiResponse ordersAuthorize(
final OrdersAuthorizeInput input) throws ApiException, IOException {
return prepareOrdersAuthorizeRequest(input).execute();
}
/**
* Authorizes payment for an order. To successfully authorize payment for an order, the buyer
* must first approve the order or a valid payment_source must be provided in the request. A
* buyer can approve the order upon being redirected to the rel:approve URL that was returned in
* the HATEOAS links in the create order response.<blockquote><strong>Note:</strong> For error
* handling and troubleshooting, see <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#authorize-order">Orders
* v2 errors</a>.</blockquote>.
* @param input OrdersAuthorizeInput object containing request parameters
* @return Returns the OrderAuthorizeResponse wrapped in ApiResponse response from the API call
*/
public CompletableFuture> ordersAuthorizeAsync(
final OrdersAuthorizeInput input) {
try {
return prepareOrdersAuthorizeRequest(input).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for ordersAuthorize.
*/
private ApiCall, ApiException> prepareOrdersAuthorizeRequest(
final OrdersAuthorizeInput input) throws JsonProcessingException, IOException {
return new ApiCall.Builder, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/checkout/orders/{id}/authorize")
.bodyParam(param -> param.value(input.getBody()).isRequired(false))
.bodySerializer(() -> ApiHelper.serialize(input.getBody()))
.templateParam(param -> param.key("id").value(input.getId())
.shouldEncode(true))
.headerParam(param -> param.key("Content-Type")
.value("application/json").isRequired(false))
.headerParam(param -> param.key("PayPal-Request-Id")
.value(input.getPayPalRequestId()).isRequired(false))
.headerParam(param -> param.key("Prefer")
.value(input.getPrefer()).isRequired(false))
.headerParam(param -> param.key("PayPal-Client-Metadata-Id")
.value(input.getPayPalClientMetadataId()).isRequired(false))
.headerParam(param -> param.key("PayPal-Auth-Assertion")
.value(input.getPayPalAuthAssertion()).isRequired(false))
.headerParam(param -> param.key("accept").value("application/json"))
.withAuth(auth -> auth
.add("Oauth2"))
.httpMethod(HttpMethod.POST))
.responseHandler(responseHandler -> responseHandler
.responseClassType(ResponseClassType.API_RESPONSE)
.apiResponseDeserializer(
response -> ApiHelper.deserialize(response, OrderAuthorizeResponse.class))
.nullify404(false)
.localErrorCase("400",
ErrorCase.setReason("Request is not well-formed, syntactically incorrect, or violates schema.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("401",
ErrorCase.setReason("Authentication failed due to missing authorization header, or invalid authentication credentials.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("403",
ErrorCase.setReason("The authorized payment failed due to insufficient permissions.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("404",
ErrorCase.setReason("The specified resource does not exist.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("422",
ErrorCase.setReason("The requested action could not be performed, semantically incorrect, or failed business validation.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("500",
ErrorCase.setReason("An internal server error has occurred.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase(ErrorCase.DEFAULT,
ErrorCase.setReason("The error response.",
(reason, context) -> new ErrorException(reason, context)))
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Captures payment for an order. To successfully capture payment for an order, the buyer must
* first approve the order or a valid payment_source must be provided in the request. A buyer
* can approve the order upon being redirected to the rel:approve URL that was returned in the
* HATEOAS links in the create order response.<blockquote><strong>Note:</strong> For error
* handling and troubleshooting, see <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#capture-order">Orders
* v2 errors</a>.</blockquote>.
* @param input OrdersCaptureInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ApiResponse ordersCapture(
final OrdersCaptureInput input) throws ApiException, IOException {
return prepareOrdersCaptureRequest(input).execute();
}
/**
* Captures payment for an order. To successfully capture payment for an order, the buyer must
* first approve the order or a valid payment_source must be provided in the request. A buyer
* can approve the order upon being redirected to the rel:approve URL that was returned in the
* HATEOAS links in the create order response.<blockquote><strong>Note:</strong> For error
* handling and troubleshooting, see <a
* href="https://developer.paypal.com/api/rest/reference/orders/v2/errors/#capture-order">Orders
* v2 errors</a>.</blockquote>.
* @param input OrdersCaptureInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
*/
public CompletableFuture> ordersCaptureAsync(
final OrdersCaptureInput input) {
try {
return prepareOrdersCaptureRequest(input).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for ordersCapture.
*/
private ApiCall, ApiException> prepareOrdersCaptureRequest(
final OrdersCaptureInput input) throws JsonProcessingException, IOException {
return new ApiCall.Builder, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/checkout/orders/{id}/capture")
.bodyParam(param -> param.value(input.getBody()).isRequired(false))
.bodySerializer(() -> ApiHelper.serialize(input.getBody()))
.templateParam(param -> param.key("id").value(input.getId())
.shouldEncode(true))
.headerParam(param -> param.key("Content-Type")
.value("application/json").isRequired(false))
.headerParam(param -> param.key("PayPal-Request-Id")
.value(input.getPayPalRequestId()).isRequired(false))
.headerParam(param -> param.key("Prefer")
.value(input.getPrefer()).isRequired(false))
.headerParam(param -> param.key("PayPal-Client-Metadata-Id")
.value(input.getPayPalClientMetadataId()).isRequired(false))
.headerParam(param -> param.key("PayPal-Auth-Assertion")
.value(input.getPayPalAuthAssertion()).isRequired(false))
.headerParam(param -> param.key("accept").value("application/json"))
.withAuth(auth -> auth
.add("Oauth2"))
.httpMethod(HttpMethod.POST))
.responseHandler(responseHandler -> responseHandler
.responseClassType(ResponseClassType.API_RESPONSE)
.apiResponseDeserializer(
response -> ApiHelper.deserialize(response, Order.class))
.nullify404(false)
.localErrorCase("400",
ErrorCase.setReason("Request is not well-formed, syntactically incorrect, or violates schema.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("401",
ErrorCase.setReason("Authentication failed due to missing authorization header, or invalid authentication credentials.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("403",
ErrorCase.setReason("The authorized payment failed due to insufficient permissions.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("404",
ErrorCase.setReason("The specified resource does not exist.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("422",
ErrorCase.setReason("The requested action could not be performed, semantically incorrect, or failed business validation.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("500",
ErrorCase.setReason("An internal server error has occurred.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase(ErrorCase.DEFAULT,
ErrorCase.setReason("The error response.",
(reason, context) -> new ErrorException(reason, context)))
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Adds tracking information for an Order.
* @param input OrdersTrackCreateInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ApiResponse ordersTrackCreate(
final OrdersTrackCreateInput input) throws ApiException, IOException {
return prepareOrdersTrackCreateRequest(input).execute();
}
/**
* Adds tracking information for an Order.
* @param input OrdersTrackCreateInput object containing request parameters
* @return Returns the Order wrapped in ApiResponse response from the API call
*/
public CompletableFuture> ordersTrackCreateAsync(
final OrdersTrackCreateInput input) {
try {
return prepareOrdersTrackCreateRequest(input).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for ordersTrackCreate.
*/
private ApiCall, ApiException> prepareOrdersTrackCreateRequest(
final OrdersTrackCreateInput input) throws JsonProcessingException, IOException {
return new ApiCall.Builder, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/checkout/orders/{id}/track")
.bodyParam(param -> param.value(input.getBody()))
.bodySerializer(() -> ApiHelper.serialize(input.getBody()))
.templateParam(param -> param.key("id").value(input.getId())
.shouldEncode(true))
.headerParam(param -> param.key("Content-Type")
.value("application/json").isRequired(false))
.headerParam(param -> param.key("PayPal-Auth-Assertion")
.value(input.getPayPalAuthAssertion()).isRequired(false))
.headerParam(param -> param.key("accept").value("application/json"))
.withAuth(auth -> auth
.add("Oauth2"))
.httpMethod(HttpMethod.POST))
.responseHandler(responseHandler -> responseHandler
.responseClassType(ResponseClassType.API_RESPONSE)
.apiResponseDeserializer(
response -> ApiHelper.deserialize(response, Order.class))
.nullify404(false)
.localErrorCase("400",
ErrorCase.setReason("Request is not well-formed, syntactically incorrect, or violates schema.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("403",
ErrorCase.setReason("Authorization failed due to insufficient permissions.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("404",
ErrorCase.setReason("The specified resource does not exist.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("422",
ErrorCase.setReason("The requested action could not be performed, semantically incorrect, or failed business validation.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("500",
ErrorCase.setReason("An internal server error has occurred.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase(ErrorCase.DEFAULT,
ErrorCase.setReason("The error response.",
(reason, context) -> new ErrorException(reason, context)))
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
/**
* Updates or cancels the tracking information for a PayPal order, by ID. Updatable attributes
* or
* objects:<br/><br/><table><thead><th>Attribute</th><th>Op</th><th>Notes</th></thead><tbody></tr><tr><td><code>items</code></td><td>replace</td><td>Using
* replace op for <code>items</code> will replace the entire <code>items</code> object with the
* value sent in request.</td></tr><tr><td><code>notify_payer</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>status</code></td><td>replace</td><td>Only patching
* status to CANCELLED is currently supported.</td></tr></tbody></table>.
* @param input OrdersTrackersPatchInput object containing request parameters
* @throws ApiException Represents error response from the server.
* @throws IOException Signals that an I/O exception of some sort has occurred.
*/
public ApiResponse ordersTrackersPatch(
final OrdersTrackersPatchInput input) throws ApiException, IOException {
return prepareOrdersTrackersPatchRequest(input).execute();
}
/**
* Updates or cancels the tracking information for a PayPal order, by ID. Updatable attributes
* or
* objects:<br/><br/><table><thead><th>Attribute</th><th>Op</th><th>Notes</th></thead><tbody></tr><tr><td><code>items</code></td><td>replace</td><td>Using
* replace op for <code>items</code> will replace the entire <code>items</code> object with the
* value sent in request.</td></tr><tr><td><code>notify_payer</code></td><td>replace,
* add</td><td></td></tr><tr><td><code>status</code></td><td>replace</td><td>Only patching
* status to CANCELLED is currently supported.</td></tr></tbody></table>.
* @param input OrdersTrackersPatchInput object containing request parameters
* @return Returns the Void wrapped in ApiResponse response from the API call
*/
public CompletableFuture> ordersTrackersPatchAsync(
final OrdersTrackersPatchInput input) {
try {
return prepareOrdersTrackersPatchRequest(input).executeAsync();
} catch (Exception e) {
throw new CompletionException(e);
}
}
/**
* Builds the ApiCall object for ordersTrackersPatch.
*/
private ApiCall, ApiException> prepareOrdersTrackersPatchRequest(
final OrdersTrackersPatchInput input) throws JsonProcessingException, IOException {
return new ApiCall.Builder, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
.path("/v2/checkout/orders/{id}/trackers/{tracker_id}")
.bodyParam(param -> param.value(input.getBody()).isRequired(false))
.bodySerializer(() -> ApiHelper.serialize(input.getBody()))
.templateParam(param -> param.key("id").value(input.getId())
.shouldEncode(true))
.templateParam(param -> param.key("tracker_id").value(input.getTrackerId())
.shouldEncode(true))
.headerParam(param -> param.key("Content-Type")
.value("application/json").isRequired(false))
.withAuth(auth -> auth
.add("Oauth2"))
.httpMethod(HttpMethod.PATCH))
.responseHandler(responseHandler -> responseHandler
.responseClassType(ResponseClassType.API_RESPONSE)
.nullify404(false)
.localErrorCase("400",
ErrorCase.setReason("Request is not well-formed, syntactically incorrect, or violates schema.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("403",
ErrorCase.setReason("Authorization failed due to insufficient permissions.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("404",
ErrorCase.setReason("The specified resource does not exist.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("422",
ErrorCase.setReason("The requested action could not be performed, semantically incorrect, or failed business validation.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase("500",
ErrorCase.setReason("An internal server error has occurred.",
(reason, context) -> new ErrorException(reason, context)))
.localErrorCase(ErrorCase.DEFAULT,
ErrorCase.setReason("The error response.",
(reason, context) -> new ErrorException(reason, context)))
.globalErrorCase(GLOBAL_ERROR_CASES))
.build();
}
}