From 2b874c069c0fc2bdf06d089f316486a4d9b349c0 Mon Sep 17 00:00:00 2001 From: "Dr. Pshtiwan" Date: Sat, 6 Apr 2024 09:26:51 +0300 Subject: [PATCH 1/2] Support Laravel 11.x --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a153704..3436744 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ "type": "library", "license": "MIT", "require": { - "php": "^8.1", - "illuminate/support": "^10.16" + "php": "^8.1|^8.2", + "laravel/framework": "^10.0|^11.0" }, "authors": [ { From cea55bb33d80cb76212adc209cae5b1002caefa2 Mon Sep 17 00:00:00 2001 From: Pshtiwan Mahmood Date: Tue, 9 Apr 2024 07:44:04 +0300 Subject: [PATCH 2/2] wip --- README.ar.md | 1 + README.ku.md | 1 + README.md | 1 + config/fastpay.php | 3 ++ .../migrations/create_fastpay_table.php.stub | 19 -------- src/Fastpay.php | 46 +++++++++++-------- src/FastpayBaseClass.php | 8 ++-- 7 files changed, 37 insertions(+), 42 deletions(-) delete mode 100644 database/migrations/create_fastpay_table.php.stub diff --git a/README.ar.md b/README.ar.md index a230c80..9bd1509 100644 --- a/README.ar.md +++ b/README.ar.md @@ -24,6 +24,7 @@ php artisan vendor:publish --tag="fastpay" FASTPAY_ENVIRONMENT="" FASTPAY_STORE_ID="" FASTPAY_STORE_PASSWORD="" +FASTPAY_REFUND_SECRET_KEY="" ``` **ملاحظة:** تأكد من ضبط المتغير "FASTPAY_ENVIRONMENT" في ملف ".env" إما على "staging" أو "production" بناءً على متطلباتك. diff --git a/README.ku.md b/README.ku.md index bb98a68..0cdeb11 100644 --- a/README.ku.md +++ b/README.ku.md @@ -23,6 +23,7 @@ php artisan vendor:publish --tag="fastpay" FASTPAY_ENVIRONMENT="" FASTPAY_STORE_ID="" FASTPAY_STORE_PASSWORD="" +FASTPAY_REFUND_SECRET_KEY="" ``` **تێبینی:** دڵنیابە لە ڕێکخستنی گۆڕاوەی `FASTPAY_ENVIRONMENT` لە پەڕگەی `.env` ـەکەتدا بۆ "staging" یان "production" بە پشتبەستن بە پێداویستییەکانتان. diff --git a/README.md b/README.md index e6a3cb9..a536cd9 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ After installing the package, make sure to add the following environment variabl FASTPAY_ENVIRONMENT="" FASTPAY_STORE_ID="" FASTPAY_STORE_PASSWORD="" +FASTPAY_REFUND_SECRET_KEY="" ``` **Note:** Ensure to set the `FASTPAY_ENVIRONMENT` variable in your `.env` file to either "staging" or "production" based on your requirements. diff --git a/config/fastpay.php b/config/fastpay.php index 6bcb9fb..0de985c 100644 --- a/config/fastpay.php +++ b/config/fastpay.php @@ -12,6 +12,8 @@ */ 'environment' => env('FASTPAY_ENVIRONMENT', 'staging'), + 'staging_base_url' => env('FASTPAY_STAGING_BASE_URL', 'https://staging-apigw-merchant.fast-pay.iq'), + 'production_base_url' => env('FASTPAY_PRODUCTION_BASE_URL', 'https://apigw-merchant.fast-pay.iq'), /* |-------------------------------------------------------------------------- @@ -24,4 +26,5 @@ "store_id" => env('FASTPAY_STORE_ID'), "store_password" => env('FASTPAY_STORE_PASSWORD'), + "refund_secret_key" => env('FASTPAY_REFUND_SECRET_KEY'), ]; diff --git a/database/migrations/create_fastpay_table.php.stub b/database/migrations/create_fastpay_table.php.stub deleted file mode 100644 index 69d3a54..0000000 --- a/database/migrations/create_fastpay_table.php.stub +++ /dev/null @@ -1,19 +0,0 @@ -id(); - - // add fields - - $table->timestamps(); - }); - } -}; diff --git a/src/Fastpay.php b/src/Fastpay.php index 72b3468..fe4aad4 100644 --- a/src/Fastpay.php +++ b/src/Fastpay.php @@ -10,10 +10,9 @@ class Fastpay extends FastpayBaseClass { - public static function initiate($orderId, $cart) : JsonResponse + public static function initiate($orderId, $cart): JsonResponse { try { - // validate incoming parameters $validator = Validator::make( [ 'order_id' => $orderId, @@ -53,7 +52,7 @@ public static function initiate($orderId, $cart) : JsonResponse $response = Http::post(self::baseUrl() . '/api/v1/public/pgw/payment/initiation', [ "store_id" => config("fastpay.store_id"), "store_password" => config("fastpay.store_password"), - "order_id" => $orderId, + "order_id" => $orderId, "bill_amount" => $billAmount, "currency" => "IQD", "cart" => $cart, @@ -73,11 +72,13 @@ public static function initiate($orderId, $cart) : JsonResponse public static function validate($merchantOrderId): JsonResponse { try { - $response = Http::post(self::baseUrl() . '/api/v1/public/pgw/payment/validate', [ - "store_id" => config("fastpay.store_id"), - "store_password" => config("fastpay.store_password"), - "order_id" => $merchantOrderId, - ])->json(); + $response = Http::post(self::baseUrl() . '/api/v1/public/pgw/payment/validate', + [ + "store_id" => config("fastpay.store_id"), + "store_password" => config("fastpay.store_password"), + "order_id" => $merchantOrderId, + ]) + ->json(); return response()->json($response); } catch (\Throwable $th) { @@ -88,13 +89,16 @@ public static function validate($merchantOrderId): JsonResponse public static function refund(string $merchantOrderId, string $msisdn, float $amount): JsonResponse { try { - $response = Http::post(self::baseUrl() . '/api/v1/public/pgw/payment/refund', [ - "store_id" => config("fastpay.store_id"), - "store_password" => config("fastpay.store_password"), - "order_id" => $merchantOrderId, - "msisdn" => $msisdn, - "amount" => $amount, - ])->json(); + $response = Http::post(self::baseUrl() . '/api/v1/public/pgw/payment/refund', + [ + "store_id" => config("fastpay.store_id"), + "store_password" => config("fastpay.store_password"), + "refund_secret_key" => config("fastpay.refund_secret_key"), + "order_id" => $merchantOrderId, + "msisdn" => $msisdn, + "amount" => $amount, + ]) + ->json(); return response()->json($response); } catch (\Throwable $th) { @@ -109,11 +113,13 @@ public static function refund(string $merchantOrderId, string $msisdn, float $am public static function refundValidate(string $merchantOrderId): JsonResponse { try { - $response = Http::post(self::baseUrl() . '/api/v1/public/pgw/payment/refund/validation', [ - "store_id" => config("fastpay.store_id"), - "store_password" => config("fastpay.store_password"), - "order_id" => $merchantOrderId, - ])->json(); + $response = Http::post(self::baseUrl() . '/api/v1/public/pgw/payment/refund/validation', + [ + "store_id" => config("fastpay.store_id"), + "store_password" => config("fastpay.store_password"), + "order_id" => $merchantOrderId, + ]) + ->json(); return response()->json($response); } catch (\Throwable $th) { diff --git a/src/FastpayBaseClass.php b/src/FastpayBaseClass.php index fd56bbc..afd6a25 100644 --- a/src/FastpayBaseClass.php +++ b/src/FastpayBaseClass.php @@ -4,8 +4,10 @@ class FastpayBaseClass { - protected static function baseUrl() :string - { - return config("fastpay.environment") == "production" ? "https://apigw-merchant.fast-pay.iq": "https://staging-apigw-merchant.fast-pay.iq"; + protected static function baseUrl(): string + { + return config("fastpay.environment") == "production" ? + config('fastpay.production_base_url') ?? "https://apigw-merchant.fast-pay.iq" : + config('fastpay.staging_base_url') ?? "https://staging-apigw-merchant.fast-pay.iq"; } }