From 3a1fd26f829fec1605fea7b8f07b2c0981570880 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 19 Jul 2024 15:29:30 +0530 Subject: [PATCH 01/16] Add initial strucuture for the stripe examples --- examples/README.md | 50 +++++++++++++++++++++++++++ examples/build.gradle | 78 +++++++++++++++++++++++++++++++++++++++++++ examples/build.sh | 63 ++++++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 examples/README.md create mode 100644 examples/build.gradle create mode 100644 examples/build.sh diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..ab36098 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,50 @@ +# Examples + +The `ballerinax/stripe` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples), covering various Stripe functiontionalities. + +// todo: add examples + + +## Prerequisites + +1. Retrieve Stripe API token to authenticate the connector as described in the [Setup guide](https://central.ballerina.io/ballerinax/stripe/latest#setup-guide). + +2. For each example, create a `Config.toml` file with the related configuration. Here's an example of how your `Config.toml` file should look: + + ```toml + secretKey="" + ``` + +## Running an Example + +Execute the following commands to build an example from the source: + +* To build an example: + + ```bash + bal build + ``` + +* To run an example: + + ```bash + bal run + ``` + +## Building the Examples with the Local Module + +**Warning**: Due to the absence of support for reading local repositories for single Ballerina files, the Bala of the module is manually written to the central repository as a workaround. Consequently, the bash script may modify your local Ballerina repositories. + +Execute the following commands to build all the examples against the changes you have made to the module locally: + +* To build all the examples: + + ```bash + ./build.sh build + ``` + +* To run all the examples: + + ```bash + ./build.sh run + ``` diff --git a/examples/build.gradle b/examples/build.gradle new file mode 100644 index 0000000..9a02a4a --- /dev/null +++ b/examples/build.gradle @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.tools.ant.taskdefs.condition.Os + +apply plugin: 'java' + +def graalvmFlag = "" + +task testExamples { + if (project.hasProperty("balGraalVMTest")) { + graalvmFlag = "--graalvm" + } + doLast { + try { + exec { + workingDir project.projectDir + println("Working dir: ${workingDir}") + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', "/c", "chmod +x ./build.sh && ./build.sh run && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', "-c", "chmod +x ./build.sh && ./build.sh run" + } + } + } catch (Exception e) { + println("Example Build failed: " + e.message) + throw e + } + } +} + +task buildExamples { + gradle.taskGraph.whenReady { graph -> + if (graph.hasTask(":stripe-examples:test")) { + buildExamples.enabled = false + } else { + testExamples.enabled = false + } + } + doLast { + try { + exec { + workingDir project.projectDir + println("Working dir: ${workingDir}") + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', "/c", "chmod +x ./build.sh && ./build.sh build && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', "-c", "chmod +x ./build.sh && ./build.sh build" + } + } + } catch (Exception e) { + println("Example Build failed: " + e.message) + throw e + } + } +} + +buildExamples.dependsOn ":stripe-ballerina:build" +testExamples.dependsOn ":stripe-ballerina:build" + +// TODO: Enable the examples build once https://github.com/ballerina-platform/ballerina-library/issues/6135 is fixed +// test.dependsOn testExamples +// build.dependsOn buildExamples diff --git a/examples/build.sh b/examples/build.sh new file mode 100644 index 0000000..10fe84c --- /dev/null +++ b/examples/build.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +BAL_EXAMPLES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BAL_CENTRAL_DIR="$HOME/.ballerina/repositories/central.ballerina.io" +BAL_HOME_DIR="$BAL_EXAMPLES_DIR/../ballerina" + +set -e + +case "$1" in +build) + BAL_CMD="build" + ;; +run) + BAL_CMD="run" + ;; +*) + echo "Invalid command provided: '$1'. Please provide 'build' or 'run' as the command." + exit 1 + ;; +esac + +# Read Ballerina package name +BAL_PACKAGE_NAME=$(awk -F'"' '/^name/ {print $2}' "$BAL_HOME_DIR/Ballerina.toml") + +# Push the package to the local repository +cd "$BAL_HOME_DIR" && + bal pack && + bal push --repository=local + +# Remove the cache directories in the repositories +cacheDirs=$(ls -d $BAL_CENTRAL_DIR/cache-* 2>/dev/null) || true +for dir in "${cacheDirs[@]}"; do + [ -d "$dir" ] && rm -r "$dir" +done +echo "Successfully cleaned the cache directories" + +# Create the package directory in the central repository, this will not be present if no modules are pulled +mkdir -p "$BAL_CENTRAL_DIR/bala/ballerinax/$BAL_PACKAGE_NAME" + +# Update the central repository +BAL_DESTINATION_DIR="$HOME/.ballerina/repositories/central.ballerina.io/bala/ballerinax/$BAL_PACKAGE_NAME" +BAL_SOURCE_DIR="$HOME/.ballerina/repositories/local/bala/ballerinax/$BAL_PACKAGE_NAME" +[ -d "$BAL_DESTINATION_DIR" ] && rm -r "$BAL_DESTINATION_DIR" +[ -d "$BAL_SOURCE_DIR" ] && cp -r "$BAL_SOURCE_DIR" "$BAL_DESTINATION_DIR" +echo "Successfully updated the local central repositories" + +echo "$BAL_DESTINATION_DIR" +echo "$BAL_SOURCE_DIR" + +# Loop through examples in the examples directory +cd "$BAL_EXAMPLES_DIR" +for dir in $(find "$BAL_EXAMPLES_DIR" -type d -maxdepth 1 -mindepth 1); do + # Skip the build directory + if [[ "$dir" == *build ]]; then + continue + fi + (cd "$dir" && bal "$BAL_CMD" --offline && cd ..); +done + +# Remove generated JAR files +find "$BAL_HOME_DIR" -maxdepth 1 -type f -name "*.jar" | while read -r JAR_FILE; do + rm "$JAR_FILE" +done From 96f6d6b9c71c5020c459db1707251b6fa040a2c2 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 19 Jul 2024 15:30:19 +0530 Subject: [PATCH 02/16] Fix spelling mistakes --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index ab36098..7ffd701 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,6 @@ # Examples -The `ballerinax/stripe` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples), covering various Stripe functiontionalities. +The `ballerinax/stripe` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples), covering various Stripe functionalities. // todo: add examples From cca366d2cb3f5755cb41ca174fcacbfedce98156 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Mon, 22 Jul 2024 13:26:33 +0530 Subject: [PATCH 03/16] Add initial structure for the PGW sample --- examples/online-pgw/Ballerina.toml | 8 +++++ examples/online-pgw/service.bal | 33 +++++++++++++++++++ examples/online-pgw/tests/service_test.bal | 37 ++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 examples/online-pgw/Ballerina.toml create mode 100644 examples/online-pgw/service.bal create mode 100644 examples/online-pgw/tests/service_test.bal diff --git a/examples/online-pgw/Ballerina.toml b/examples/online-pgw/Ballerina.toml new file mode 100644 index 0000000..376b38f --- /dev/null +++ b/examples/online-pgw/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "online_pgw" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/examples/online-pgw/service.bal b/examples/online-pgw/service.bal new file mode 100644 index 0000000..1928f04 --- /dev/null +++ b/examples/online-pgw/service.bal @@ -0,0 +1,33 @@ +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/http; + +# A service representing a network-accessible API +# bound to port `9090`. +service / on new http:Listener(9090) { + + # A resource for generating greetings + # + name - name as a string or nil + # + return - string name with hello message or error + resource function get greeting(string? name) returns string|error { + // Send a response back to the caller. + if name is () { + return error("name should not be empty!"); + } + return string `Hello, ${name}`; + } +} diff --git a/examples/online-pgw/tests/service_test.bal b/examples/online-pgw/tests/service_test.bal new file mode 100644 index 0000000..0d85eb2 --- /dev/null +++ b/examples/online-pgw/tests/service_test.bal @@ -0,0 +1,37 @@ +import ballerina/io; +import ballerina/http; +import ballerina/test; + +http:Client testClient = check new ("http://localhost:9090"); + +// Before Suite Function + +@test:BeforeSuite +function beforeSuiteFunc() { + io:println("I'm the before suite function!"); +} + +// Test function + +@test:Config {} +function testServiceWithProperName() { + string|error response = testClient->get("/greeting/?name=John"); + test:assertEquals(response, "Hello, John"); +} + +// Negative test function + +@test:Config {} +function testServiceWithEmptyName() returns error? { + http:Response response = check testClient->get("/greeting/"); + test:assertEquals(response.statusCode, 500); + json errorPayload = check response.getJsonPayload(); + test:assertEquals(errorPayload.message, "name should not be empty!"); +} + +// After Suite Function + +@test:AfterSuite +function afterSuiteFunc() { + io:println("I'm the after suite function!"); +} From 8f196b2e38eeb161cb6a8a91e1e7a6f73bb8211c Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Wed, 24 Jul 2024 09:39:39 +0530 Subject: [PATCH 04/16] Add initial structure for the project --- examples/online-pgw/service.bal | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/online-pgw/service.bal b/examples/online-pgw/service.bal index 1928f04..3dd7046 100644 --- a/examples/online-pgw/service.bal +++ b/examples/online-pgw/service.bal @@ -15,6 +15,21 @@ // under the License. import ballerina/http; +import ballerinax/stripe; + +final stripe:Client cl = check new({ + auth: { + token: "" + } +}); + + +function testStripe() returns error? { + stripe:Payment_intent s = check cl->/payment_intents.post({ + amount: 10, + currency: "USD" + }); +} # A service representing a network-accessible API # bound to port `9090`. From 1f93b2b2393c573cc08547e603ce0774c4bbb41b Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 17:26:48 +0530 Subject: [PATCH 05/16] Remove PGW example --- examples/online-pgw/Ballerina.toml | 8 ---- examples/online-pgw/service.bal | 48 ---------------------- examples/online-pgw/tests/service_test.bal | 37 ----------------- 3 files changed, 93 deletions(-) delete mode 100644 examples/online-pgw/Ballerina.toml delete mode 100644 examples/online-pgw/service.bal delete mode 100644 examples/online-pgw/tests/service_test.bal diff --git a/examples/online-pgw/Ballerina.toml b/examples/online-pgw/Ballerina.toml deleted file mode 100644 index 376b38f..0000000 --- a/examples/online-pgw/Ballerina.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -org = "wso2" -name = "online_pgw" -version = "0.1.0" -distribution = "2201.9.2" - -[build-options] -observabilityIncluded = true diff --git a/examples/online-pgw/service.bal b/examples/online-pgw/service.bal deleted file mode 100644 index 3dd7046..0000000 --- a/examples/online-pgw/service.bal +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). -// -// WSO2 LLC. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/http; -import ballerinax/stripe; - -final stripe:Client cl = check new({ - auth: { - token: "" - } -}); - - -function testStripe() returns error? { - stripe:Payment_intent s = check cl->/payment_intents.post({ - amount: 10, - currency: "USD" - }); -} - -# A service representing a network-accessible API -# bound to port `9090`. -service / on new http:Listener(9090) { - - # A resource for generating greetings - # + name - name as a string or nil - # + return - string name with hello message or error - resource function get greeting(string? name) returns string|error { - // Send a response back to the caller. - if name is () { - return error("name should not be empty!"); - } - return string `Hello, ${name}`; - } -} diff --git a/examples/online-pgw/tests/service_test.bal b/examples/online-pgw/tests/service_test.bal deleted file mode 100644 index 0d85eb2..0000000 --- a/examples/online-pgw/tests/service_test.bal +++ /dev/null @@ -1,37 +0,0 @@ -import ballerina/io; -import ballerina/http; -import ballerina/test; - -http:Client testClient = check new ("http://localhost:9090"); - -// Before Suite Function - -@test:BeforeSuite -function beforeSuiteFunc() { - io:println("I'm the before suite function!"); -} - -// Test function - -@test:Config {} -function testServiceWithProperName() { - string|error response = testClient->get("/greeting/?name=John"); - test:assertEquals(response, "Hello, John"); -} - -// Negative test function - -@test:Config {} -function testServiceWithEmptyName() returns error? { - http:Response response = check testClient->get("/greeting/"); - test:assertEquals(response.statusCode, 500); - json errorPayload = check response.getJsonPayload(); - test:assertEquals(errorPayload.message, "name should not be empty!"); -} - -// After Suite Function - -@test:AfterSuite -function afterSuiteFunc() { - io:println("I'm the after suite function!"); -} From 9809e63c22806a21469776206edbea88342001bc Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 17:37:51 +0530 Subject: [PATCH 06/16] Add manage-payment example --- examples/manage-payments/Ballerina.toml | 8 +++++ examples/manage-payments/main.bal | 41 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 examples/manage-payments/Ballerina.toml create mode 100644 examples/manage-payments/main.bal diff --git a/examples/manage-payments/Ballerina.toml b/examples/manage-payments/Ballerina.toml new file mode 100644 index 0000000..3df327b --- /dev/null +++ b/examples/manage-payments/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "ayesh" +name = "manage_payments" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/examples/manage-payments/main.bal b/examples/manage-payments/main.bal new file mode 100644 index 0000000..584645d --- /dev/null +++ b/examples/manage-payments/main.bal @@ -0,0 +1,41 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/io; +import ballerinax/stripe; + +// Configuration for Stripe API access +configurable string secretKey = ?; + +public function main() returns error? { + stripe:Client stripe = check new ({auth: {token: secretKey}}); + + // Create a payment intent + stripe:payment_intents_body paymentDetails = { + amount: 100, + currency: "usd" + }; + stripe:Payment_intent payment = check stripe->/payment_intents.post(paymentDetails); + + // Confirm the payment + stripe:intent_confirm_body confirmation = { + // Update the payment method here + payment_method: "pm_xxxxxx", + return_url: "https://www.example.com" + }; + payment = check stripe->/payment_intents/[payment.id]/confirm.post(confirmation); + io:println("Payment confirmed successfully: ", payment.id); +} From d652831e93e4b68fa0e917eee8125a4629089675 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 17:45:30 +0530 Subject: [PATCH 07/16] Add payment-refund example --- examples/refund-payments/Ballerina.toml | 8 +++++++ examples/refund-payments/main.bal | 31 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 examples/refund-payments/Ballerina.toml create mode 100644 examples/refund-payments/main.bal diff --git a/examples/refund-payments/Ballerina.toml b/examples/refund-payments/Ballerina.toml new file mode 100644 index 0000000..d2cf971 --- /dev/null +++ b/examples/refund-payments/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "refund_payments" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/examples/refund-payments/main.bal b/examples/refund-payments/main.bal new file mode 100644 index 0000000..82de9f3 --- /dev/null +++ b/examples/refund-payments/main.bal @@ -0,0 +1,31 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/io; +import ballerinax/stripe; + +// Configuration for Stripe API access +configurable string secretKey = ?; + +public function main() returns error? { + stripe:refunds_body refundDetails = { + // Update the payment-id here + payment_intent: "pi_xxxxxx" + }; + stripe:Refund paymentRefund = check stripe->/refunds.post(refundDetails); + + io:println("Payment refund successful: ", paymentRefund.id); +} From 930372058d12a0ee657be9b9c6ac1f3f43969b22 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 17:46:06 +0530 Subject: [PATCH 08/16] Update package org of the example --- examples/manage-payments/Ballerina.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/manage-payments/Ballerina.toml b/examples/manage-payments/Ballerina.toml index 3df327b..66ba6fd 100644 --- a/examples/manage-payments/Ballerina.toml +++ b/examples/manage-payments/Ballerina.toml @@ -1,5 +1,5 @@ [package] -org = "ayesh" +org = "wso2" name = "manage_payments" version = "0.1.0" distribution = "2201.9.2" From a725e4e019c7351970c69ce02b5a3e1aa25fdae4 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 17:57:34 +0530 Subject: [PATCH 09/16] Add onetime-charge example --- .../manage-one-time-charges/Ballerina.toml | 8 ++++ examples/manage-one-time-charges/main.bal | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 examples/manage-one-time-charges/Ballerina.toml create mode 100644 examples/manage-one-time-charges/main.bal diff --git a/examples/manage-one-time-charges/Ballerina.toml b/examples/manage-one-time-charges/Ballerina.toml new file mode 100644 index 0000000..3ecea90 --- /dev/null +++ b/examples/manage-one-time-charges/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "manage_one_time_charges" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/examples/manage-one-time-charges/main.bal b/examples/manage-one-time-charges/main.bal new file mode 100644 index 0000000..f92bbd0 --- /dev/null +++ b/examples/manage-one-time-charges/main.bal @@ -0,0 +1,42 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/io; +import ballerinax/stripe; + +// Configuration for Stripe API access +configurable string secretKey = ?; + +public function main() returns error? { + stripe:Client stripe = check new ({auth: {token: secretKey}}); + + // Initiate a one-time charge + stripe:charges_body chargeDetails = { + amount: 100, + currency: "usd", + // Update the payment-source token here + 'source: "tok_xxxx" + }; + stripe:Charge charge = check stripe->/charges.post(chargeDetails); + io:println("Onetime charge was successful: ", charge.id); + + // Refund a one-time charge + stripe:charge_refund_body chargeRefund = { + amount: 100 + }; + charge = check stripe->/charges/[charge.id]/refund.post(chargeRefund); + io:println("Onetime charge refund was successful: ", charge.id); +} From dfb215b637e60fe12144f8698b2345e6b957d9cf Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 18:06:31 +0530 Subject: [PATCH 10/16] Add readme for manage-payments example --- examples/manage-payments/.github/README.md | 1 + .../manage-payments/Manage Stripe Payments.md | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 120000 examples/manage-payments/.github/README.md create mode 100644 examples/manage-payments/Manage Stripe Payments.md diff --git a/examples/manage-payments/.github/README.md b/examples/manage-payments/.github/README.md new file mode 120000 index 0000000..3df3c6e --- /dev/null +++ b/examples/manage-payments/.github/README.md @@ -0,0 +1 @@ +../Manage Stripe Payments.md \ No newline at end of file diff --git a/examples/manage-payments/Manage Stripe Payments.md b/examples/manage-payments/Manage Stripe Payments.md new file mode 100644 index 0000000..db07f4b --- /dev/null +++ b/examples/manage-payments/Manage Stripe Payments.md @@ -0,0 +1,26 @@ +# Manage stripe payments + +This example demonstrates how Stripe REST API v1 can be utilized to manage business payments. + +## Prerequisites + +### 1. Setup Stripe account + +Refer to the [Setup guide](https://central.ballerina.io/ballerinax/stripe/latest#setup-guide) to set up your stripe +account, if you do not have one. + +### 2. Configuration + +Update your Stripe account-related configurations in the `Config.toml` file in the example root directory: + +```toml +secretKey="" +``` + +## Run the example + +Execute the following command to run the example: + +```ballerina +bal run +``` From e6bf3f8f3023540a66998f2488cdf65eb3072dd1 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 18:09:54 +0530 Subject: [PATCH 11/16] Restructure the manage-payment example --- examples/manage-payments/main.bal | 8 +++++++ examples/refund-payments/Ballerina.toml | 8 ------- examples/refund-payments/main.bal | 31 ------------------------- 3 files changed, 8 insertions(+), 39 deletions(-) delete mode 100644 examples/refund-payments/Ballerina.toml delete mode 100644 examples/refund-payments/main.bal diff --git a/examples/manage-payments/main.bal b/examples/manage-payments/main.bal index 584645d..63054d0 100644 --- a/examples/manage-payments/main.bal +++ b/examples/manage-payments/main.bal @@ -38,4 +38,12 @@ public function main() returns error? { }; payment = check stripe->/payment_intents/[payment.id]/confirm.post(confirmation); io:println("Payment confirmed successfully: ", payment.id); + + // Refund a confirmed payment + stripe:refunds_body refundDetails = { + // Update the payment-id here + payment_intent: payment.id + }; + stripe:Refund paymentRefund = check stripe->/refunds.post(refundDetails); + io:println("Payment refund successful: ", paymentRefund.id); } diff --git a/examples/refund-payments/Ballerina.toml b/examples/refund-payments/Ballerina.toml deleted file mode 100644 index d2cf971..0000000 --- a/examples/refund-payments/Ballerina.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -org = "wso2" -name = "refund_payments" -version = "0.1.0" -distribution = "2201.9.2" - -[build-options] -observabilityIncluded = true diff --git a/examples/refund-payments/main.bal b/examples/refund-payments/main.bal deleted file mode 100644 index 82de9f3..0000000 --- a/examples/refund-payments/main.bal +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). -// -// WSO2 LLC. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/io; -import ballerinax/stripe; - -// Configuration for Stripe API access -configurable string secretKey = ?; - -public function main() returns error? { - stripe:refunds_body refundDetails = { - // Update the payment-id here - payment_intent: "pi_xxxxxx" - }; - stripe:Refund paymentRefund = check stripe->/refunds.post(refundDetails); - - io:println("Payment refund successful: ", paymentRefund.id); -} From 357af41690e6574ca96bf76ee9d9ba031d6d5232 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 18:12:49 +0530 Subject: [PATCH 12/16] Add readme for onetime-charges example --- .../manage-one-time-charges/.github/README.md | 1 + .../Manage Stripe One-Time Charges.md | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 120000 examples/manage-one-time-charges/.github/README.md create mode 100644 examples/manage-one-time-charges/Manage Stripe One-Time Charges.md diff --git a/examples/manage-one-time-charges/.github/README.md b/examples/manage-one-time-charges/.github/README.md new file mode 120000 index 0000000..fb61d90 --- /dev/null +++ b/examples/manage-one-time-charges/.github/README.md @@ -0,0 +1 @@ +../Manage Stripe One-Time Charges.md \ No newline at end of file diff --git a/examples/manage-one-time-charges/Manage Stripe One-Time Charges.md b/examples/manage-one-time-charges/Manage Stripe One-Time Charges.md new file mode 100644 index 0000000..9b2b1c0 --- /dev/null +++ b/examples/manage-one-time-charges/Manage Stripe One-Time Charges.md @@ -0,0 +1,26 @@ +# Manage stripe one-time charges + +This example demonstrates how Stripe REST API v1 can be utilized to manage one-time charges. + +## Prerequisites + +### 1. Setup Stripe account + +Refer to the [Setup guide](https://central.ballerina.io/ballerinax/stripe/latest#setup-guide) to set up your stripe +account, if you do not have one. + +### 2. Configuration + +Update your Stripe account-related configurations in the `Config.toml` file in the example root directory: + +```toml +secretKey="" +``` + +## Run the example + +Execute the following command to run the example: + +```ballerina +bal run +``` From b412ca7e94e39e633a678d7e6268ff7245dd85b8 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 18:16:04 +0530 Subject: [PATCH 13/16] Update examples readme with an overview --- examples/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 7ffd701..723948c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,7 +2,9 @@ The `ballerinax/stripe` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples), covering various Stripe functionalities. -// todo: add examples +1. [Manage stripe payments](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-payments) - Manage business payments with Stripe. + +2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage business one-time charges with Stripe. ## Prerequisites From 1fcbfd3fd4675cc5dbde41ec1e8c3ad4ded41cd0 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Fri, 26 Jul 2024 18:18:49 +0530 Subject: [PATCH 14/16] Update package-documentation with the examples --- README.md | 9 +++++++++ ballerina/Module.md | 8 ++++++++ ballerina/Package.md | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 352f566..52cccf2 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,15 @@ stripe:Customer customerDetails = check stripe->/customers.post(newCustomer); stripe:CustomerResourceCustomerList availableCustomers = check stripe->/customers; ``` +## Examples + +The `ballerinax/stripe` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples), covering various Stripe functionalities. + +1. [Manage stripe payments](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-payments) - Manage business payments with Stripe. + +2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage business one-time charges with Stripe. + + ## Build from the source ### Setting up the prerequisites diff --git a/ballerina/Module.md b/ballerina/Module.md index 9a273d0..f91fbb2 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -82,3 +82,11 @@ stripe:Customer customerDetails = check stripe->/customers.post(newCustomer); ```ballerina stripe:CustomerResourceCustomerList availableCustomers = check stripe->/customers; ``` + +## Examples + +The `ballerinax/stripe` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples), covering various Stripe functionalities. + +1. [Manage stripe payments](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-payments) - Manage business payments with Stripe. + +2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage business one-time charges with Stripe. diff --git a/ballerina/Package.md b/ballerina/Package.md index 9a273d0..f91fbb2 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -82,3 +82,11 @@ stripe:Customer customerDetails = check stripe->/customers.post(newCustomer); ```ballerina stripe:CustomerResourceCustomerList availableCustomers = check stripe->/customers; ``` + +## Examples + +The `ballerinax/stripe` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples), covering various Stripe functionalities. + +1. [Manage stripe payments](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-payments) - Manage business payments with Stripe. + +2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage business one-time charges with Stripe. From f8455e97dbfa203c86780b59adb41c4999bc32d3 Mon Sep 17 00:00:00 2001 From: Ayesh Almeida <77491511+ayeshLK@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:35:43 +0530 Subject: [PATCH 15/16] Update examples/manage-payments/main.bal Co-authored-by: Nipuna Ransinghe --- examples/manage-payments/main.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/manage-payments/main.bal b/examples/manage-payments/main.bal index 63054d0..e7c75a7 100644 --- a/examples/manage-payments/main.bal +++ b/examples/manage-payments/main.bal @@ -45,5 +45,5 @@ public function main() returns error? { payment_intent: payment.id }; stripe:Refund paymentRefund = check stripe->/refunds.post(refundDetails); - io:println("Payment refund successful: ", paymentRefund.id); + io:println("Payment refund was successful. Refund ID: ", paymentRefund.id); } From 14bf00f7ee5b32059400fdf36363a7d234db28f0 Mon Sep 17 00:00:00 2001 From: ayeshLK Date: Wed, 7 Aug 2024 13:49:44 +0530 Subject: [PATCH 16/16] Update the text of the example description --- README.md | 2 +- ballerina/Module.md | 2 +- ballerina/Package.md | 2 +- examples/README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 52cccf2..3754feb 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ The `ballerinax/stripe` connector provides practical examples illustrating usage 1. [Manage stripe payments](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-payments) - Manage business payments with Stripe. -2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage business one-time charges with Stripe. +2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage one-time charges with Stripe. ## Build from the source diff --git a/ballerina/Module.md b/ballerina/Module.md index f91fbb2..03971e2 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -89,4 +89,4 @@ The `ballerinax/stripe` connector provides practical examples illustrating usage 1. [Manage stripe payments](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-payments) - Manage business payments with Stripe. -2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage business one-time charges with Stripe. +2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage one-time charges with Stripe. diff --git a/ballerina/Package.md b/ballerina/Package.md index f91fbb2..03971e2 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -89,4 +89,4 @@ The `ballerinax/stripe` connector provides practical examples illustrating usage 1. [Manage stripe payments](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-payments) - Manage business payments with Stripe. -2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage business one-time charges with Stripe. +2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage one-time charges with Stripe. diff --git a/examples/README.md b/examples/README.md index 723948c..e0e5163 100644 --- a/examples/README.md +++ b/examples/README.md @@ -4,7 +4,7 @@ The `ballerinax/stripe` connector provides practical examples illustrating usage 1. [Manage stripe payments](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-payments) - Manage business payments with Stripe. -2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage business one-time charges with Stripe. +2. [Manage one-time charges](https://github.com/ballerina-platform/module-ballerinax-stripe/tree/main/examples/manage-one-time-charges) - Manage one-time charges with Stripe. ## Prerequisites