Call the Payments API to authorize payments, capture authorized payments, refund payments that have already been captured, and show payment information. Use the Payments API in conjunction with the Orders API. For more information, see the PayPal Checkout Overview.
Building the API client library requires:
- Java 1.8+
- Maven (3.8.3+)/Gradle (7.2+)
If you are adding this library to an Android Application or Library:
- Android 8.0+ (API Level 26+)
Add this dependency to your project's POM:
<dependency>
<groupId>com.konfigthis</groupId>
<artifactId>pay-pal-payment-java-sdk</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>Add this dependency to your build.gradle:
// build.gradle
repositories {
mavenCentral()
}
dependencies {
implementation "com.konfigthis:pay-pal-payment-java-sdk:2.5"
}Make sure your build.gradle file as a minSdk version of at least 26:
// build.gradle
android {
defaultConfig {
minSdk 26
}
}Also make sure your library or application has internet permissions in your AndroidManifest.xml:
<!--AndroidManifest.xml-->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>At first generate the JAR by executing:
mvn clean packageThen manually install the following JARs:
target/pay-pal-payment-java-sdk-2.5.jartarget/lib/*.jar
Please follow the installation instruction and execute the following Java code:
import com.konfigthis.client.ApiClient;
import com.konfigthis.client.ApiException;
import com.konfigthis.client.ApiResponse;
import com.konfigthis.client.PayPalPayment;
import com.konfigthis.client.Configuration;
import com.konfigthis.client.auth.*;
import com.konfigthis.client.model.*;
import com.konfigthis.client.api.AuthorizationsApi;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class Example {
public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.host = "https://api-m.sandbox.paypal.com";
// Configure OAuth2 client credentials for "application" OAuth flow
String clientId = System.getenv("CLIENT_ID");
String clientSecret = System.getenv("CLIENT_SECRET");
configuration.clientId = "clientId";
configuration.clientSecret = "clientSecret";
PayPalPayment client = new PayPalPayment(configuration);
String authorizationId = "authorizationId_example"; // The PayPal-generated ID for the authorized payment to void.
String invoiceId = "invoiceId_example"; // The API caller-provided external invoice number for this order. Appears in both the payer's transaction history and the emails that the payer receives.
String noteToPayer = "noteToPayer_example"; // An informational note about this settlement. Appears in both the payer's transaction history and the emails that the payer receives.
Money amount = new Money();
Boolean finalCapture = false; // Indicates whether you can make additional captures against the authorized payment. Set to `true` if you do not intend to capture additional payments against the authorization. Set to `false` if you intend to capture additional payments against the authorization.
PaymentInstruction paymentInstruction = new PaymentInstruction();
String softDescriptor = "softDescriptor_example"; // The payment descriptor on the payer's account statement.
String payPalRequestId = "payPalRequestId_example"; // The server stores keys for 45 days.
String prefer = "return=minimal"; // The preferred server response upon successful completion of the request. Value is:<ul><li><code>return=minimal</code>. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the <code>id</code>, <code>status</code> and HATEOAS links.</li><li><code>return=representation</code>. The server returns a complete resource representation, including the current state of the resource.</li></ul>
try {
Capture2 result = client
.authorizations
.capturePayment(authorizationId)
.invoiceId(invoiceId)
.noteToPayer(noteToPayer)
.amount(amount)
.finalCapture(finalCapture)
.paymentInstruction(paymentInstruction)
.softDescriptor(softDescriptor)
.payPalRequestId(payPalRequestId)
.prefer(prefer)
.execute();
System.out.println(result);
System.out.println(result.getStatus());
System.out.println(result.getStatusDetails());
System.out.println(result.getId());
System.out.println(result.getAmount());
System.out.println(result.getInvoiceId());
System.out.println(result.getCustomId());
System.out.println(result.getNetworkTransactionReference());
System.out.println(result.getSellerProtection());
System.out.println(result.getFinalCapture());
System.out.println(result.getSellerReceivableBreakdown());
System.out.println(result.getDisbursementMode());
System.out.println(result.getLinks());
System.out.println(result.getProcessorResponse());
System.out.println(result.getCreateTime());
System.out.println(result.getUpdateTime());
System.out.println(result.getSupplementaryData());
System.out.println(result.getPayee());
} catch (ApiException e) {
System.err.println("Exception when calling AuthorizationsApi#capturePayment");
System.err.println("Status code: " + e.getStatusCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
// Use .executeWithHttpInfo() to retrieve HTTP Status Code, Headers and Request
try {
ApiResponse<Capture2> response = client
.authorizations
.capturePayment(authorizationId)
.invoiceId(invoiceId)
.noteToPayer(noteToPayer)
.amount(amount)
.finalCapture(finalCapture)
.paymentInstruction(paymentInstruction)
.softDescriptor(softDescriptor)
.payPalRequestId(payPalRequestId)
.prefer(prefer)
.executeWithHttpInfo();
System.out.println(response.getResponseBody());
System.out.println(response.getResponseHeaders());
System.out.println(response.getStatusCode());
System.out.println(response.getRoundTripTime());
System.out.println(response.getRequest());
} catch (ApiException e) {
System.err.println("Exception when calling AuthorizationsApi#capturePayment");
System.err.println("Status code: " + e.getStatusCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}All URIs are relative to https://api-m.sandbox.paypal.com
| Class | Method | HTTP request | Description |
|---|---|---|---|
| AuthorizationsApi | capturePayment | POST /v2/payments/authorizations/{authorization_id}/capture | Capture authorized payment |
| AuthorizationsApi | reauthorizePayment | POST /v2/payments/authorizations/{authorization_id}/reauthorize | Reauthorize authorized payment |
| AuthorizationsApi | showDetails | GET /v2/payments/authorizations/{authorization_id} | Show details for authorized payment |
| AuthorizationsApi | voidPayment | POST /v2/payments/authorizations/{authorization_id}/void | Void authorized payment |
| CapturesApi | refundPayment | POST /v2/payments/captures/{capture_id}/refund | Refund captured payment |
| CapturesApi | showDetails | GET /v2/payments/captures/{capture_id} | Show captured payment details |
| RefundsApi | details | GET /v2/payments/refunds/{refund_id} | Show refund details |
- ActivityTimestamps
- Authorization
- Authorization2
- Authorization2AllOf
- AuthorizationAllOf
- AuthorizationStatus
- AuthorizationStatusDetails
- AuthorizationsCapturePayment403Response
- AuthorizationsCapturePayment404Response
- AuthorizationsCapturePayment422Response
- AuthorizationsCapturePaymentResponse
- AuthorizationsReauthorize400
- AuthorizationsReauthorize422
- AuthorizationsReauthorizePayment403Response
- AuthorizationsReauthorizePayment404Response
- AuthorizationsReauthorizePayment422Response
- AuthorizationsReauthorizePaymentResponse
- AuthorizationsShowDetails404Response
- AuthorizationsShowDetailsResponse
- AuthorizationsVoid422
- AuthorizationsVoidPayment403Response
- AuthorizationsVoidPayment404Response
- AuthorizationsVoidPayment409Response
- AuthorizationsVoidPayment422Response
- AuthorizationsVoidPaymentResponse
- Capture
- Capture2
- CaptureAllOf
- CaptureRequest
- CaptureRequestAllOf
- CaptureStatus
- CaptureStatusDetails
- CapturesRefund400
- CapturesRefund422
- CapturesRefundPayment401Response
- CapturesRefundPayment403Response
- CapturesRefundPayment404Response
- CapturesRefundPayment409Response
- CapturesRefundPayment422Response
- CapturesRefundPaymentResponse
- CapturesShowDetails404Response
- CapturesShowDetailsResponse
- CardBrand
- DisbursementMode
- Error403
- Error404
- Error409
- Error415
- Error422
- Error500
- Error503
- ErrorDetails
- ErrorLinkDescription
- ErrorLocation
- ExchangeRate
- INVALIDACCOUNTSTATUS
- INVALIDRESOURCEID
- LinkDescription
- MerchantPayableBreakdown
- Model400
- Model401
- Model403
- Model404
- Model409
- Model422
- Money
- NetAmountBreakdownItem
- NetworkTransactionReference
- PERMISSIONDENIED
- PREVIOUSREQUESTINPROGRESS
- PayeeBase
- PaymentInstruction
- PaymentInstruction2
- PlatformFee
- ProcessorResponse
- ReauthorizeRequest
- Refund
- RefundAllOf
- RefundRequest
- RefundStatus
- RefundStatusDetails
- RefundsDetails403Response
- RefundsDetails404Response
- RefundsDetailsResponse
- RelatedIds
- SellerProtection
- SellerReceivableBreakdown
- SupplementaryData
- SupplementaryPurchaseData
This Java package is automatically generated by Konfig
