From 62a9fbe2256a5a37105de3e8a913c0d1dab2e866 Mon Sep 17 00:00:00 2001 From: Sourav Sarkar Date: Thu, 19 Sep 2024 15:37:41 +0530 Subject: [PATCH] feat: fetch paypal_client_id and paypal_client_secret from env --- .gitignore | 2 ++ advanced-integration/v2/client/html/README.md | 6 ++-- .../v2/client/react/README.md | 6 ++-- .../v2/server/dotnet/README.md | 35 ++++++++++++++----- .../v2/server/dotnet/Server.cs | 10 ++---- .../v2/server/dotnet/appsettings.json | 4 --- advanced-integration/v2/server/java/README.md | 35 ++++++++++++++----- advanced-integration/v2/server/java/pom.xml | 2 +- .../src/main/resources/application.properties | 4 +-- advanced-integration/v2/server/node/README.md | 34 +++++++++++++----- advanced-integration/v2/server/php/README.md | 20 +++++++++-- .../v2/server/php/server/.env | 2 -- .../v2/server/php/server/index.php | 31 ++++++++-------- standard-integration/client/html/README.md | 6 ++-- standard-integration/client/react/README.md | 6 ++-- standard-integration/server/dotnet/README.md | 35 ++++++++++++++----- standard-integration/server/dotnet/Server.cs | 10 ++---- .../server/dotnet/appsettings.json | 4 --- standard-integration/server/java/README.md | 35 ++++++++++++++----- standard-integration/server/java/pom.xml | 2 +- .../src/main/resources/application.properties | 4 +-- standard-integration/server/node/README.md | 34 +++++++++++++----- standard-integration/server/php/README.md | 20 +++++++++-- standard-integration/server/php/server/.env | 2 -- .../server/php/server/index.php | 31 ++++++++-------- 25 files changed, 244 insertions(+), 136 deletions(-) delete mode 100644 advanced-integration/v2/server/dotnet/appsettings.json delete mode 100644 advanced-integration/v2/server/php/server/.env delete mode 100644 standard-integration/server/dotnet/appsettings.json delete mode 100644 standard-integration/server/php/server/.env diff --git a/.gitignore b/.gitignore index 5df6b051..2caf82db 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,5 @@ dist # dotnet *.sln + +*.local diff --git a/advanced-integration/v2/client/html/README.md b/advanced-integration/v2/client/html/README.md index 0ebb16ac..a98bb13f 100644 --- a/advanced-integration/v2/client/html/README.md +++ b/advanced-integration/v2/client/html/README.md @@ -20,7 +20,7 @@ This guide will walk you through setting up and running the HTML/JS Advanced Int ### Installation -```sh +```bash npm install ``` @@ -31,7 +31,7 @@ npm install - Rename the .env.example file to .env - Update the following keys with their actual values - - ```sh + ```bash PAYPAL_CLIENT_ID= ``` @@ -61,7 +61,7 @@ npm install - **Start the client**: - ```sh + ```bash npm run dev ``` diff --git a/advanced-integration/v2/client/react/README.md b/advanced-integration/v2/client/react/README.md index 6022519f..70f5f11e 100644 --- a/advanced-integration/v2/client/react/README.md +++ b/advanced-integration/v2/client/react/README.md @@ -20,7 +20,7 @@ This guide will walk you through setting up and running the React Advanced Integ ### Installation -```sh +```bash npm install ``` @@ -31,7 +31,7 @@ npm install - Rename the .env.example file to .env - Update the following keys with their actual values - - ```sh + ```bash PAYPAL_CLIENT_ID= ``` @@ -61,7 +61,7 @@ npm install - **Start the client**: - ```sh + ```bash npm run dev ``` diff --git a/advanced-integration/v2/server/dotnet/README.md b/advanced-integration/v2/server/dotnet/README.md index 92ac1cc2..52ed7c55 100644 --- a/advanced-integration/v2/server/dotnet/README.md +++ b/advanced-integration/v2/server/dotnet/README.md @@ -1,18 +1,35 @@ # Advanced Integartion .NET Sample + PayPal Advanced Integration sample in .NET ## Running the sample -1. Build the server +1. **Add your API credentials to the environment:** + + - **Windows** + + ```powershell + $env:PAYPAL_CLIENT_ID = "" + $env:PAYPAL_CLIENT_SECRET = "" + ``` + + - **Unix** + + ```bash + export PAYPAL_CLIENT_ID="" + export PAYPAL_CLIENT_SECRET="" + ``` + +2. **Build the server** -~~~ -dotnet restore -~~~ + ```bash + dotnet restore + ``` -2. Run the server +3. **Run the server** -~~~ -dotnet run -~~~ + ```bash + dotnet run + ``` -3. Go to [http://localhost:8080/](http://localhost:8080/) \ No newline at end of file +4. Go to [http://localhost:8080/](http://localhost:8080/) diff --git a/advanced-integration/v2/server/dotnet/Server.cs b/advanced-integration/v2/server/dotnet/Server.cs index c9bab8fc..dcd334fb 100644 --- a/advanced-integration/v2/server/dotnet/Server.cs +++ b/advanced-integration/v2/server/dotnet/Server.cs @@ -23,12 +23,6 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration( - (context, config) => - { - config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); - } - ) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseUrls("http://localhost:8080"); @@ -66,11 +60,11 @@ public class CheckoutController : Controller private IConfiguration _configuration { get; } private string _paypalClientId { - get { return _configuration["PAYPAL_CLIENT_ID"]; } + get { return Environment.GetEnvironmentVariable("PAYPAL_CLIENT_ID"); } } private string _paypalClientSecret { - get { return _configuration["PAYPAL_CLIENT_SECRET"]; } + get { return Environment.GetEnvironmentVariable("PAYPAL_CLIENT_SECRET"); } } private readonly string _base = "https://api-m.sandbox.paypal.com"; diff --git a/advanced-integration/v2/server/dotnet/appsettings.json b/advanced-integration/v2/server/dotnet/appsettings.json deleted file mode 100644 index 019194eb..00000000 --- a/advanced-integration/v2/server/dotnet/appsettings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "PAYPAL_CLIENT_ID": "PAYPAL_CLIENT_ID", - "PAYPAL_CLIENT_SECRET": "PAYPAL_CLIENT_SECRET" -} diff --git a/advanced-integration/v2/server/java/README.md b/advanced-integration/v2/server/java/README.md index 578fb9b7..8e330262 100644 --- a/advanced-integration/v2/server/java/README.md +++ b/advanced-integration/v2/server/java/README.md @@ -1,18 +1,35 @@ # Advanced Integartion Java Sample + PayPal Advanced Integration sample in Java ## Running the sample -1. Build the server +1. Add your API credentials to the environment: + + - **Windows** + + ```powershell + $env:PAYPAL_CLIENT_ID = "" + $env:PAYPAL_CLIENT_SECRET = "" + ``` + + - **Unix** + + ```bash + export PAYPAL_CLIENT_ID="" + export PAYPAL_CLIENT_SECRET="" + ``` + +2. Build the server -~~~ -mvn clean install -~~~ + ```bash + mvn clean install + ``` -2. Run the server +3. Run the server -~~~ -mvn spring-boot:run -~~~ + ```bash + mvn spring-boot:run + ``` -3. Go to [http://localhost:8080/](http://localhost:8080/) +4. Go to [http://localhost:8080/](http://localhost:8080/) diff --git a/advanced-integration/v2/server/java/pom.xml b/advanced-integration/v2/server/java/pom.xml index f36d390d..a8c8f8f9 100644 --- a/advanced-integration/v2/server/java/pom.xml +++ b/advanced-integration/v2/server/java/pom.xml @@ -27,7 +27,7 @@ - 22 + 21 diff --git a/advanced-integration/v2/server/java/src/main/resources/application.properties b/advanced-integration/v2/server/java/src/main/resources/application.properties index 88089970..103551b3 100644 --- a/advanced-integration/v2/server/java/src/main/resources/application.properties +++ b/advanced-integration/v2/server/java/src/main/resources/application.properties @@ -1,3 +1,3 @@ spring.application.name=v2-java -PAYPAL_CLIENT_ID= -PAYPAL_CLIENT_SECRET= +PAYPAL_CLIENT_ID=${PAYPAL_CLIENT_ID} +PAYPAL_CLIENT_SECRET=${PAYPAL_CLIENT_SECRET} diff --git a/advanced-integration/v2/server/node/README.md b/advanced-integration/v2/server/node/README.md index 8a3c0250..2a224db8 100644 --- a/advanced-integration/v2/server/node/README.md +++ b/advanced-integration/v2/server/node/README.md @@ -4,16 +4,32 @@ PayPal Advanced Integration sample in Node.js ## Running the sample -1. Install the packages +1. Add your API credentials to the environment: - ```sh - npm install - ``` + - **Windows** -2. Run the server + ```powershell + $env:PAYPAL_CLIENT_ID = "" + $env:PAYPAL_CLIENT_SECRET = "" + ``` - ```sh - npm run start - ``` + - **Unix** -3. Go to [http://localhost:8080/](http://localhost:8080/) + ```bash + export PAYPAL_CLIENT_ID="" + export PAYPAL_CLIENT_SECRET="" + ``` + +2. Install the packages + + ```bash + npm install + ``` + +3. Run the server + + ```bash + npm run start + ``` + +4. Go to [http://localhost:8080/](http://localhost:8080/) diff --git a/advanced-integration/v2/server/php/README.md b/advanced-integration/v2/server/php/README.md index 2f162d42..a789b6bf 100644 --- a/advanced-integration/v2/server/php/README.md +++ b/advanced-integration/v2/server/php/README.md @@ -18,9 +18,23 @@ This sample app demonstrates how to integrate with ACDC using PayPal's REST APIs ## How to Run Locally -1. Replace your Client ID & Client Secret in the server/.env file: -2. Open the `.env` file in a text editor and replace the placeholders with the appropriate values. -3. Follow the below instructions to setup & run server. +1. Add your API credentials to the environment: + + - **Windows** + + ```powershell + $env:PAYPAL_CLIENT_ID = "" + $env:PAYPAL_CLIENT_SECRET = "" + ``` + + - **Unix** + + ```bash + export PAYPAL_CLIENT_ID="" + export PAYPAL_CLIENT_SECRET="" + ``` + +2. Follow the below instructions to setup & run server. ## Install the Composer diff --git a/advanced-integration/v2/server/php/server/.env b/advanced-integration/v2/server/php/server/.env deleted file mode 100644 index 96d3bc76..00000000 --- a/advanced-integration/v2/server/php/server/.env +++ /dev/null @@ -1,2 +0,0 @@ -PAYPAL_CLIENT_ID= -PAYPAL_CLIENT_SECRET= \ No newline at end of file diff --git a/advanced-integration/v2/server/php/server/index.php b/advanced-integration/v2/server/php/server/index.php index 81a25ada..e99a2841 100644 --- a/advanced-integration/v2/server/php/server/index.php +++ b/advanced-integration/v2/server/php/server/index.php @@ -3,17 +3,16 @@ use GuzzleHttp\Client; -$env = parse_ini_file('.env'); - -$PAYPAL_CLIENT_ID = $env['PAYPAL_CLIENT_ID']; -$PAYPAL_CLIENT_SECRET = $env['PAYPAL_CLIENT_SECRET']; +$PAYPAL_CLIENT_ID = getenv('PAYPAL_CLIENT_ID'); +$PAYPAL_CLIENT_SECRET = getenv('PAYPAL_CLIENT_SECRET'); $base = "https://api-m.sandbox.paypal.com"; /** * Generate an OAuth 2.0 access token for authenticating with PayPal REST APIs. * @see https://developer.paypal.com/api/rest/authentication/ */ -function generateAccessToken() { +function generateAccessToken() +{ global $PAYPAL_CLIENT_ID, $PAYPAL_CLIENT_SECRET, $base; if (!$PAYPAL_CLIENT_ID || !$PAYPAL_CLIENT_SECRET) { @@ -21,7 +20,7 @@ function generateAccessToken() { } $auth = base64_encode($PAYPAL_CLIENT_ID . ":" . $PAYPAL_CLIENT_SECRET); - + // Disabling certificate validation for local development $client = new Client(['verify' => false]); $response = $client->post("$base/v1/oauth2/token", [ @@ -41,11 +40,12 @@ function generateAccessToken() { * Create an order to start the transaction. * @see https://developer.paypal.com/docs/api/orders/v2/#orders_create */ -function createOrder($cart) { +function createOrder($cart) +{ global $base; $accessToken = generateAccessToken(); - + // Disabling certificate validation for local development $client = new Client(['verify' => false]); $payload = [ @@ -75,7 +75,8 @@ function createOrder($cart) { * Capture payment for the created order to complete the transaction. * @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture */ -function captureOrder($orderID) { +function captureOrder($orderID) +{ global $base; $accessToken = generateAccessToken(); @@ -92,7 +93,8 @@ function captureOrder($orderID) { return handleResponse($response); } -function handleResponse($response) { +function handleResponse($response) +{ $jsonResponse = json_decode($response->getBody(), true); return [ 'jsonResponse' => $jsonResponse, @@ -101,7 +103,7 @@ function handleResponse($response) { } $endpoint = $_SERVER['REQUEST_URI']; -if($endpoint === '/') { +if ($endpoint === '/') { try { $response = [ "message" => "Server is running" @@ -114,7 +116,7 @@ function handleResponse($response) { } } -if($endpoint === '/api/orders') { +if ($endpoint === '/api/orders') { $data = json_decode(file_get_contents('php://input'), true); $cart = $data['cart']; header('Content-Type: application/json'); @@ -128,7 +130,7 @@ function handleResponse($response) { } -if(str_ends_with($endpoint, '/capture')) { +if (str_ends_with($endpoint, '/capture')) { $urlSegments = explode('/', $endpoint); end($urlSegments); // Will set the pointer to the end of array $orderID = prev($urlSegments); @@ -140,5 +142,4 @@ function handleResponse($response) { echo json_encode(['error' => $e->getMessage()]); http_response_code(500); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/standard-integration/client/html/README.md b/standard-integration/client/html/README.md index 5c79b001..302fcb42 100644 --- a/standard-integration/client/html/README.md +++ b/standard-integration/client/html/README.md @@ -20,7 +20,7 @@ This guide will walk you through setting up and running the HTML/JS Standard Int ### Installation -```sh +```bash npm install ``` @@ -31,7 +31,7 @@ npm install - Rename the .env.example file to .env - Update the following keys with their actual values - - ```sh + ```bash PAYPAL_CLIENT_ID= ``` @@ -61,7 +61,7 @@ npm install - **Start the client**: - ```sh + ```bash npm run dev ``` diff --git a/standard-integration/client/react/README.md b/standard-integration/client/react/README.md index fdf7d214..da8ec278 100644 --- a/standard-integration/client/react/README.md +++ b/standard-integration/client/react/README.md @@ -20,7 +20,7 @@ This guide will walk you through setting up and running the React Standard Integ ### Installation -```sh +```bash npm install ``` @@ -31,7 +31,7 @@ npm install - Rename the .env.example file to .env - Update the following keys with their actual values - - ```sh + ```bash PAYPAL_CLIENT_ID= ``` @@ -61,7 +61,7 @@ npm install - **Start the client**: - ```sh + ```bash npm run dev ``` diff --git a/standard-integration/server/dotnet/README.md b/standard-integration/server/dotnet/README.md index 9dca45c3..d1f5fd91 100644 --- a/standard-integration/server/dotnet/README.md +++ b/standard-integration/server/dotnet/README.md @@ -1,18 +1,35 @@ # Standard Integartion .NET Sample + PayPal Standard Integration sample in .NET ## Running the sample -1. Build the server +1. **Add your API credentials to the environment:** + + - **Windows** + + ```powershell + $env:PAYPAL_CLIENT_ID = "" + $env:PAYPAL_CLIENT_SECRET = "" + ``` + + - **Unix** + + ```bash + export PAYPAL_CLIENT_ID="" + export PAYPAL_CLIENT_SECRET="" + ``` + +2. **Build the server** -~~~ -dotnet restore -~~~ + ```bash + dotnet restore + ``` -2. Run the server +3. **Run the server** -~~~ -dotnet run -~~~ + ```bash + dotnet run + ``` -3. Go to [http://localhost:8080/](http://localhost:8080/) \ No newline at end of file +4. Go to [http://localhost:8080/](http://localhost:8080/) diff --git a/standard-integration/server/dotnet/Server.cs b/standard-integration/server/dotnet/Server.cs index eb24f0e8..9be4f5e5 100644 --- a/standard-integration/server/dotnet/Server.cs +++ b/standard-integration/server/dotnet/Server.cs @@ -23,12 +23,6 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration( - (context, config) => - { - config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); - } - ) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseUrls("http://localhost:8080"); @@ -66,11 +60,11 @@ public class CheckoutController : Controller private IConfiguration _configuration { get; } private string _paypalClientId { - get { return _configuration["PAYPAL_CLIENT_ID"]; } + get { return Environment.GetEnvironmentVariable("PAYPAL_CLIENT_ID"); } } private string _paypalClientSecret { - get { return _configuration["PAYPAL_CLIENT_SECRET"]; } + get { return Environment.GetEnvironmentVariable("PAYPAL_CLIENT_SECRET"); } } private readonly string _base = "https://api-m.sandbox.paypal.com"; diff --git a/standard-integration/server/dotnet/appsettings.json b/standard-integration/server/dotnet/appsettings.json deleted file mode 100644 index 019194eb..00000000 --- a/standard-integration/server/dotnet/appsettings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "PAYPAL_CLIENT_ID": "PAYPAL_CLIENT_ID", - "PAYPAL_CLIENT_SECRET": "PAYPAL_CLIENT_SECRET" -} diff --git a/standard-integration/server/java/README.md b/standard-integration/server/java/README.md index 343200e7..a9fcce21 100644 --- a/standard-integration/server/java/README.md +++ b/standard-integration/server/java/README.md @@ -1,18 +1,35 @@ # Standard Integartion Java Sample + PayPal Standard Integration sample in Java ## Running the sample -1. Build the server +1. Add your API credentials to the environment: + + - **Windows** + + ```powershell + $env:PAYPAL_CLIENT_ID = "" + $env:PAYPAL_CLIENT_SECRET = "" + ``` + + - **Unix** + + ```bash + export PAYPAL_CLIENT_ID="" + export PAYPAL_CLIENT_SECRET="" + ``` + +2. Build the server -~~~ -mvn clean install -~~~ + ```bash + mvn clean install + ``` -2. Run the server +3. Run the server -~~~ -mvn spring-boot:run -~~~ + ```bash + mvn spring-boot:run + ``` -3. Go to [http://localhost:8080/](http://localhost:8080/) +4. Go to [http://localhost:8080/](http://localhost:8080/) diff --git a/standard-integration/server/java/pom.xml b/standard-integration/server/java/pom.xml index 48e7a01c..ab4c30bc 100644 --- a/standard-integration/server/java/pom.xml +++ b/standard-integration/server/java/pom.xml @@ -27,7 +27,7 @@ - 22 + 21 diff --git a/standard-integration/server/java/src/main/resources/application.properties b/standard-integration/server/java/src/main/resources/application.properties index 88089970..103551b3 100644 --- a/standard-integration/server/java/src/main/resources/application.properties +++ b/standard-integration/server/java/src/main/resources/application.properties @@ -1,3 +1,3 @@ spring.application.name=v2-java -PAYPAL_CLIENT_ID= -PAYPAL_CLIENT_SECRET= +PAYPAL_CLIENT_ID=${PAYPAL_CLIENT_ID} +PAYPAL_CLIENT_SECRET=${PAYPAL_CLIENT_SECRET} diff --git a/standard-integration/server/node/README.md b/standard-integration/server/node/README.md index a9ddb604..0fce05d5 100644 --- a/standard-integration/server/node/README.md +++ b/standard-integration/server/node/README.md @@ -4,16 +4,32 @@ PayPal Standard Integration sample in Node.js ## Running the sample -1. Install the packages +1. Add your API credentials to the environment: - ```sh - npm install - ``` + - **Windows** -2. Run the server + ```powershell + $env:PAYPAL_CLIENT_ID = "" + $env:PAYPAL_CLIENT_SECRET = "" + ``` - ```sh - npm run start - ``` + - **Unix** -3. Go to [http://localhost:8080/](http://localhost:8080/) + ```bash + export PAYPAL_CLIENT_ID="" + export PAYPAL_CLIENT_SECRET="" + ``` + +2. Install the packages + + ```bash + npm install + ``` + +3. Run the server + + ```bash + npm run start + ``` + +4. Go to [http://localhost:8080/](http://localhost:8080/) diff --git a/standard-integration/server/php/README.md b/standard-integration/server/php/README.md index 5c5b5ed6..53284b42 100644 --- a/standard-integration/server/php/README.md +++ b/standard-integration/server/php/README.md @@ -18,9 +18,23 @@ This sample app demonstrates how to integrate with ACDC using PayPal's REST APIs ## How to Run Locally -1. Replace your Client ID & Client Secret in the server/.env file: -2. Open the `.env` file in a text editor and replace the placeholders with the appropriate values. -3. Follow the below instructions to setup & run server. +1. Add your API credentials to the environment: + + - **Windows** + + ```powershell + $env:PAYPAL_CLIENT_ID = "" + $env:PAYPAL_CLIENT_SECRET = "" + ``` + + - **Unix** + + ```bash + export PAYPAL_CLIENT_ID="" + export PAYPAL_CLIENT_SECRET="" + ``` + +2. Follow the below instructions to setup & run server. ## Install the Composer diff --git a/standard-integration/server/php/server/.env b/standard-integration/server/php/server/.env deleted file mode 100644 index 96d3bc76..00000000 --- a/standard-integration/server/php/server/.env +++ /dev/null @@ -1,2 +0,0 @@ -PAYPAL_CLIENT_ID= -PAYPAL_CLIENT_SECRET= \ No newline at end of file diff --git a/standard-integration/server/php/server/index.php b/standard-integration/server/php/server/index.php index 81a25ada..e99a2841 100644 --- a/standard-integration/server/php/server/index.php +++ b/standard-integration/server/php/server/index.php @@ -3,17 +3,16 @@ use GuzzleHttp\Client; -$env = parse_ini_file('.env'); - -$PAYPAL_CLIENT_ID = $env['PAYPAL_CLIENT_ID']; -$PAYPAL_CLIENT_SECRET = $env['PAYPAL_CLIENT_SECRET']; +$PAYPAL_CLIENT_ID = getenv('PAYPAL_CLIENT_ID'); +$PAYPAL_CLIENT_SECRET = getenv('PAYPAL_CLIENT_SECRET'); $base = "https://api-m.sandbox.paypal.com"; /** * Generate an OAuth 2.0 access token for authenticating with PayPal REST APIs. * @see https://developer.paypal.com/api/rest/authentication/ */ -function generateAccessToken() { +function generateAccessToken() +{ global $PAYPAL_CLIENT_ID, $PAYPAL_CLIENT_SECRET, $base; if (!$PAYPAL_CLIENT_ID || !$PAYPAL_CLIENT_SECRET) { @@ -21,7 +20,7 @@ function generateAccessToken() { } $auth = base64_encode($PAYPAL_CLIENT_ID . ":" . $PAYPAL_CLIENT_SECRET); - + // Disabling certificate validation for local development $client = new Client(['verify' => false]); $response = $client->post("$base/v1/oauth2/token", [ @@ -41,11 +40,12 @@ function generateAccessToken() { * Create an order to start the transaction. * @see https://developer.paypal.com/docs/api/orders/v2/#orders_create */ -function createOrder($cart) { +function createOrder($cart) +{ global $base; $accessToken = generateAccessToken(); - + // Disabling certificate validation for local development $client = new Client(['verify' => false]); $payload = [ @@ -75,7 +75,8 @@ function createOrder($cart) { * Capture payment for the created order to complete the transaction. * @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture */ -function captureOrder($orderID) { +function captureOrder($orderID) +{ global $base; $accessToken = generateAccessToken(); @@ -92,7 +93,8 @@ function captureOrder($orderID) { return handleResponse($response); } -function handleResponse($response) { +function handleResponse($response) +{ $jsonResponse = json_decode($response->getBody(), true); return [ 'jsonResponse' => $jsonResponse, @@ -101,7 +103,7 @@ function handleResponse($response) { } $endpoint = $_SERVER['REQUEST_URI']; -if($endpoint === '/') { +if ($endpoint === '/') { try { $response = [ "message" => "Server is running" @@ -114,7 +116,7 @@ function handleResponse($response) { } } -if($endpoint === '/api/orders') { +if ($endpoint === '/api/orders') { $data = json_decode(file_get_contents('php://input'), true); $cart = $data['cart']; header('Content-Type: application/json'); @@ -128,7 +130,7 @@ function handleResponse($response) { } -if(str_ends_with($endpoint, '/capture')) { +if (str_ends_with($endpoint, '/capture')) { $urlSegments = explode('/', $endpoint); end($urlSegments); // Will set the pointer to the end of array $orderID = prev($urlSegments); @@ -140,5 +142,4 @@ function handleResponse($response) { echo json_encode(['error' => $e->getMessage()]); http_response_code(500); } -} -?> \ No newline at end of file +} \ No newline at end of file