Module paypal.orders

ballerinax/paypal.orders 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.orders package provides a Ballerina connector for interacting with the PayPal Orders API v2, allowing you to create, capture, authorize, and manage orders in your Ballerina applications.

Setup guide

To use the PayPal Orders 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.orders connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

Import the paypal.orders module.

Copy
import ballerinax/paypal.orders 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>"

serviceUrl = "<paypal-service-url>"
tokenUrl = "<paypal-token-url>"
  1. Create a paypal:ConnectionConfig with the obtained credentials and initialize the connector with it.
Copy
configurable string clientId = ?;
configurable string clientSecret = ?;

configurable string serviceUrl = ?;
configurable string tokenUrl = ?;
Copy
final paypal:Client paypal = check new ({
    auth: {
        clientId,
        clientSecret,
        tokenUrl
    }
}, serviceUrl);

Step 3: Invoke the connector operation

Now, utilize the available connector operations.

Create an order

Copy
public function main() returns error? {
    paypal:Order response = check paypal->/orders.post({
        intent: "CAPTURE",
        purchase_units: [{
                amount: {
                    currency_code: "USD",
                    value: "100.00"
                }
            }]
    });
}

Step 4: Run the Ballerina application

Copy
bal run

Examples

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

  1. Order lifecycle: Process a complete PayPal order from creation and updates through confirming and capturing payments.

  2. Manage shipping: Enrich an order with shipping details, add or update tracking information, and push shipment updates back to PayPal.

Import

import ballerinax/paypal.orders;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: 1375

Current verison: 0


Weekly downloads


Source repository


Keywords

Paypal

Payments

Orders


Contributors

Other versions

See more...