Skip to content

ballerina-platform/module-ballerinax-paypal.invoices

Repository files navigation

Ballerina Paypal Invoices connector

Build GitHub Last Commit GitHub Issues

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.invoices package provides a Ballerina connector for interacting with the PayPal Invoicing API v2, allowing you to create, send, manage, and track invoices in your Ballerina applications.

Setup guide

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

Step 1: Import the module

Import the paypal.invoices module.

import ballerinax/paypal.invoices 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:
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.
configurable string clientId = ?;
configurable string clientSecret = ?;

configurable string serviceUrl = ?;
configurable string tokenUrl = ?;
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 invoice

public function main() returns error? {
    paypal:Invoice response = check paypal->/invoices.post({
        detail: {
            invoice_number: "INV-001",
            currency_code: "USD"
        },
        invoicer: {
            name: {
                given_name: "John",
                surname: "Doe"
            },
            email_address: "john.doe@example.com"
        },
        primary_recipients: [{
            billing_info: {
                name: {
                    given_name: "Jane",
                    surname: "Smith"
                },
                email_address: "jane.smith@example.com"
            }
        }],
        items: [{
            name: "Product/Service",
            quantity: "1",
            unit_amount: {
                currency_code: "USD",
                value: "100.00"
            }
        }]
    });
}

Step 4: Run the Ballerina application

bal run

Examples

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

  1. Record invoice: Create and record an invoice with PayPal for tracking and payment processing.

  2. Send and cancel invoice: Send invoices to recipients and manage invoice cancellations when needed.

Build from the source

Setting up the prerequisites

  1. Download and install Java SE Development Kit (JDK) version 21. You can download it from either of the following sources:

    Note: After installation, remember to set the JAVA_HOME environment variable to the directory where JDK was installed.

  2. Download and install Ballerina Swan Lake.

  3. Download and install Docker.

    Note: Ensure that the Docker daemon is running before executing any tests.

  4. Export Github Personal access token with read package permissions as follows,

    export packageUser=<Username>
    export packagePAT=<Personal access token>

Build options

Execute the commands below to build from the source.

  1. To build the package:

    ./gradlew clean build
  2. To run the tests:

    ./gradlew clean test
  3. To build the without the tests:

    ./gradlew clean build -x test
  4. To run tests against different environments:

    ./gradlew clean test -Pgroups=<Comma separated groups/test cases>
  5. To debug the package with a remote debugger:

    ./gradlew clean build -Pdebug=<port>
  6. To debug with the Ballerina language:

    ./gradlew clean build -PbalJavaDebug=<port>
  7. Publish the generated artifacts to the local Ballerina Central repository:

    ./gradlew clean build -PpublishToLocalCentral=true
  8. Publish the generated artifacts to the Ballerina Central repository:

    ./gradlew clean build -PpublishToCentral=true

Contribute to Ballerina

As an open-source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All the contributors are encouraged to read the Ballerina Code of Conduct.

Useful links

About

Ballerina Paypal Invoices connector

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 6