Skip to content

konfig-sdks/pay-pal-payment-java-sdk

Repository files navigation

Visit Paypal

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.

Requirements

Building the API client library requires:

  1. Java 1.8+
  2. Maven (3.8.3+)/Gradle (7.2+)

If you are adding this library to an Android Application or Library:

  1. Android 8.0+ (API Level 26+)

Installation

Maven users

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>

Gradle users

Add this dependency to your build.gradle:

// build.gradle
repositories {
  mavenCentral()
}

dependencies {
   implementation "com.konfigthis:pay-pal-payment-java-sdk:2.5"
}

Android users

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>

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/pay-pal-payment-java-sdk-2.5.jar
  • target/lib/*.jar

Getting Started

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();
    }
  }
}

Documentation for API Endpoints

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

Documentation for Models

Author

This Java package is automatically generated by Konfig

About

Making money fast, easy, and enjoyable. Empowering people and businesses worldwide to thrive. Visit PayPal Help Center for support, and explore job opportunities for all. Equal opportunity employer promoting diversity and well-being. PayPal's Java SDK for Payment API generated by Konfig (https://konfigthis.com/).

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors