ballerinax/paypal.payments Ballerina library

2.0.0

Overview

PayPal is a global online payment platform enabling individuals and businesses to securely send and receive money, process transactions, and access merchant services across multiple currencies.

The ballerinax/paypal.payments package provides a Ballerina connector for interacting with the PayPal Payments API v2, allowing you to authorize payments, capture authorized payments, refund captured payments, void authorizations, and reauthorize expired authorizations in your Ballerina applications.

Setup guide

To use the PayPal Payments connector, you must have access to a PayPal Developer account.

Step 1: Create a business account

  1. Open the PayPal Developer Dashboard.

  2. Click on "Sandbox Accounts" under "Testing Tools".

    Sandbox accounts

  3. Create a Business account

    Note: Some PayPal options and features may vary by region or country; check availability before creating an account.

    Create business account

Step 2: Create a REST API app

  1. Navigate to the "Apps and Credentials" tab and create a new merchant app.

    Provide a name for the application and select the Business account you created earlier.

    Create app

Step 3: Obtain Client ID and Client Secret

  1. After creating your new app, you will see your Client ID and Client Secret. Make sure to copy and securely store these credentials.

    Credentials

Quickstart

To use the paypal.payments connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

Import the paypal.payments module.

Copy
import ballerinax/paypal.payments as paypal;

Step 2: Instantiate a new connector

  1. Create a Config.toml file and configure the obtained credentials in the above steps as follows:
Copy
clientId = "<test-client-id>"
clientSecret = "<test-client-secret>"
  1. Create a paypal:ConnectionConfig with the obtained credentials and initialize the connector with it.
Copy
configurable string clientId = ?;
configurable string clientSecret= ?;
Copy
final paypal:Client paypal = check new ({
    auth: {
        clientId,
        clientSecret
    }
}, serviceUrl);

Step 3: Invoke the connector operation

Now, utilize the available connector operations.

Capture an authorized payment

Copy
public function main() returns error? {
    paypal:CaptureRequest captureRequest = {
        amount: {
            currency_code: "USD",
            value: "100.00"
        },
        final_capture: true
    };
    
    paypal:Capture2 response = check paypal->/authorizations/[authorizationId]/capture.post(captureRequest);
}

Step 4: Run the Ballerina application

Copy
bal run

Examples

The PayPal Payments connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:

  1. Order creation: Process a complete product purchase from order creation through payment authorization, capture, and partial refunds.

  2. Subscription management: Simulate a recurring billing flow with subscription-style orders, monthly payments, plan switching, and pro-rated refunds.

Import

import ballerinax/paypal.payments;Copy

Metadata

Released date: 5 days ago

Version: 2.0.0

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.12.7

GraalVM compatible: Yes


Pull count

Total: 7

Current verison: 0


Weekly downloads


Source repository


Keywords

Paypal

Payments


Contributors

Other versions

See more...