-
Notifications
You must be signed in to change notification settings - Fork 1
Examples and documentations for the ballerina Payapal Connector #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
15b7a1a
Added readme files and examples
pamaljayasinghe 3832f2f
changed mock_service bal file
pamaljayasinghe f6fc46b
added extra space after the end of the code file
pamaljayasinghe fb35513
examples ballerina.toml file updated
pamaljayasinghe 201bb65
updated is live server to false
pamaljayasinghe 1eedc8b
deleted unnecessary files
pamaljayasinghe 466d85a
all issues fixed
pamaljayasinghe 4576afc
add symlinks to examples
pamaljayasinghe e442bb0
Fixed all issues
pamaljayasinghe 8e130a1
everything fixed
pamaljayasinghe 4a2fa62
fixed service url
pamaljayasinghe b63e358
fixed readme ballerina file
pamaljayasinghe f72e2e7
default values added and other issues fixed
pamaljayasinghe 17d802d
default value changed to false
pamaljayasinghe 1e7137a
updated test bal file
pamaljayasinghe a95c01f
readme file issue fixed
pamaljayasinghe a0c447d
readme file changed
pamaljayasinghe 7e78a84
ballerina file readme file changed
pamaljayasinghe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,3 +53,4 @@ build | |
|
|
||
| # Ignore Docker env file | ||
| docker.env | ||
| examples/**/Dependencies.toml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pamaljayasinghe marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,113 @@ | ||
| ## Overview | ||
|
|
||
| [//]: # (TODO: Add overview mentioning the purpose of the module, supported REST API versions, and other high-level details.) | ||
| [PayPal](https://www.paypal.com/) 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](https://developer.paypal.com/docs/api/payments/v2/), allowing you to authorize payments, capture authorized payments, refund captured payments, void authorizations, and reauthorize expired authorizations in your Ballerina applications. | ||
|
|
||
| ## Setup guide | ||
|
|
||
| [//]: # (TODO: Add detailed steps to obtain credentials and configure the module.) | ||
| To use the PayPal Payments connector, you must have access to a [PayPal Developer account](https://developer.paypal.com/). | ||
|
|
||
| ### Step 1: Create a business account | ||
|
|
||
| 1. Open the [PayPal Developer Dashboard](https://developer.paypal.com/dashboard). | ||
|
|
||
| 2. Click on "Sandbox Accounts" under "Testing Tools". | ||
|
|
||
|  | ||
|
|
||
| 3. Create a Business account | ||
|
|
||
| > Note: Some PayPal options and features may vary by region or country; check availability before creating an 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. | ||
|
|
||
|  | ||
|
|
||
| ### 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. | ||
|
|
||
|  | ||
|
|
||
| ## Quickstart | ||
|
|
||
| [//]: # (TODO: Add a quickstart guide to demonstrate a basic functionality of the module, including sample code snippets.) | ||
| 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. | ||
|
|
||
| ```ballerina | ||
| 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: | ||
|
|
||
| ```toml | ||
| sandboxClientId = "<test-client-id>" | ||
| sandboxClientSecret = "<test-client-secret>" | ||
|
|
||
| ``` | ||
|
|
||
| 2. Create a `paypal:ConnectionConfig` with the obtained credentials and initialize the connector with it. | ||
|
|
||
| ```ballerina | ||
| configurable string sandboxClientId = ?; | ||
| configurable string sandboxClientSecret= ?; | ||
|
|
||
| configurable string serviceUrl = ?; | ||
| configurable string tokenUrl = ?; | ||
| ``` | ||
|
|
||
| ```ballerina | ||
| final paypal:Client paypal = check new ({ | ||
| auth: { | ||
| clientId, | ||
| clientSecret, | ||
| tokenUrl | ||
| } | ||
| }, serviceUrl); | ||
| ``` | ||
|
|
||
| ### Step 3: Invoke the connector operation | ||
|
|
||
| Now, utilize the available connector operations. | ||
|
|
||
| #### Capture an authorized payment | ||
|
|
||
| ```ballerina | ||
| 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 | ||
|
|
||
| ```bash | ||
| bal run | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| The `Paypal Payments` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/module-ballerinax-paypal.payments/tree/main/examples/), covering the following use cases: | ||
| The `PayPal Payments` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-paypal.payments/tree/main/examples/), covering the following use cases: | ||
|
|
||
| 1. [**Order creation**](https://github.com/ballerina-platform/module-ballerinax-paypal.payments/tree/main/examples/order-creation): Process a complete product purchase from order creation through payment authorization, capture, and partial refunds. | ||
|
|
||
| [//]: # (TODO: Add examples) | ||
| 2. [**Subscription management**](https://github.com/ballerina-platform/module-ballerinax-paypal.payments/tree/main/examples/subscription-management): Simulate a recurring billing flow with subscription-style orders, monthly payments, plan switching, and pro-rated refunds. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.