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.subscriptions package provides a Ballerina connector for interacting with the PayPal Subscriptions API v1, allowing you to create, manage, and monitor subscription-based billing plans and subscriptions in your Ballerina applications.
To use the PayPal Subscriptions connector, you must have access to a PayPal Developer account.
-
Open the PayPal Developer Dashboard.
-
Create a business account.
Note: Some PayPal options and features may vary by region or country; check availability before creating an account.
- Navigate to the "Apps and Credentials" tab and create a new merchant app.
- Provide a name for the application and select the Business account created earlier.

-
After creating the app, you will see your Client ID and Client Secret. Copy and securely store these credentials.
To use the paypal.subscriptions connector in your Ballerina application, update the .bal file as follows:
Import the paypal.subscriptions module.
import ballerinax/paypal.subscriptions as paypal;-
Create a
Config.tomlfile and configure the obtained credentials and URLs:clientId = "<your-client-id>" clientSecret = "<your-client-secret>" serviceUrl = "<paypal-service-url>" tokenUrl = "<paypal-token-url>"
-
Create a
paypal:ConnectionConfigwith the credentials and initialize the connector:configurable string clientId = ?; configurable string clientSecret = ?; configurable string serviceUrl = ?; configurable string tokenUrl = ?; final paypal:Client paypal = check new ({ auth: { clientId, clientSecret, tokenUrl } }, serviceUrl);
public function main() returns error? {
paypal:PlanRequestPOST plan = {
product_id: "PROD-1234567890",
name: "Basic Subscription Plan",
status: "ACTIVE",
billing_cycles: [
{
frequency: {
interval_unit: "MONTH",
interval_count: 1
},
tenure_type: "REGULAR",
sequence: 1,
total_cycles: 0,
pricing_scheme: {
fixed_price: {
value: "10.00",
currency_code: "USD"
}
}
}
],
payment_preferences: {
auto_bill_outstanding: true,
setup_fee: {
value: "0.00",
currency_code: "USD"
},
setup_fee_failure_action: "CONTINUE",
payment_failure_threshold: 3
}
};
paypal:Plan response = check paypal->/plans.post(plan);
}bal runThe PayPal Subscriptions connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:
- Create and List Plans: Create a subscription plan and list all available plans.
- Monitor and Manage Subscription Status: Retrieve a subscription’s status and suspend or reactivate it based on its state.
- Manage Premium Subscription: Create a subscription plan, enroll a customer, and retrieve subscription details for a premium membership.
-
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_HOMEenvironment variable to the directory where JDK was installed. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
-
Export Github Personal access token with read package permissions as follows,
export packageUser=<Username> export packagePAT=<Personal access token>
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
To run the tests:
./gradlew clean test -
To build without the tests:
./gradlew clean build -x test -
To run tests against different environments:
./gradlew clean test -Pgroups=<Comma separated groups/test cases>
-
To debug the package with a remote debugger:
./gradlew clean build -Pdebug=<port>
-
To debug with the Ballerina language:
./gradlew clean build -PbalJavaDebug=<port>
-
Publish the generated artifacts to the local Ballerina Central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina Central repository:
./gradlew clean build -PpublishToCentral=true
As an open-source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All contributors are encouraged to read the Ballerina Code of Conduct.
- For more information, go to the
paypal.subscriptionspackage. - For example demonstrations of the usage, go to Ballerina By Examples.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.


