From a51e38556cf279927d672863f2f5cd8230e89196 Mon Sep 17 00:00:00 2001 From: Alaa Elsaid Date: Thu, 9 May 2024 06:07:05 +0300 Subject: [PATCH 1/2] Add MyFatoorah Gateway --- composer.json | 3 +- composer.lock | 66 ++++++++++++++++++++++++++- config/nafezly-payments.php | 4 ++ src/Classes/MyFatoorahPayment.php | 76 +++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 src/Classes/MyFatoorahPayment.php diff --git a/composer.json b/composer.json index ad6e87a..28b638a 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "laravel/framework": ">=6.0", "paypal/paypal-checkout-sdk": "1.0.2", "ext-json": "*", - "ext-curl": "*" + "ext-curl": "*", + "myfatoorah/library": "^2.2" }, "authors": [ { diff --git a/composer.lock b/composer.lock index 30e45c8..40c94d0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "816e6e7e24fae8abbd69ad25a320a592", + "content-hash": "a5e2df3c2a0a69b17da01708f7e74ce3", "packages": [ { "name": "brick/math", @@ -1346,6 +1346,70 @@ ], "time": "2023-02-06T13:46:10+00:00" }, + { + "name": "myfatoorah/library", + "version": "2.2.7", + "source": { + "type": "git", + "url": "https://dev.azure.com/myfatoorahsc/Public-Repo/_git/Library", + "reference": "9daacff144df983d8ecb3872e49dcf2d5e515ea2" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "php": ">=7" + }, + "require-dev": { + "phan/phan": "^5.4", + "phpcompatibility/php-compatibility": "*", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "*" + }, + "type": "library", + "autoload": { + "files": [ + "autoload.php" + ], + "psr-4": { + "MyFatoorah\\Library\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0-only" + ], + "authors": [ + { + "name": "MyFatoorah Plugin Team", + "email": "plugins@myfatoorah.com" + }, + { + "name": "Nermeen Shoman", + "email": "nshoman@myfatoorah.com", + "role": "Senior Software Engineer" + }, + { + "name": "Rasha Saeed", + "email": "rsaeed@myfatoorah.com", + "role": "Senior Software Engineer" + } + ], + "description": "MyFatoorah PHP Library", + "homepage": "https://myfatoorah.com/", + "keywords": [ + "My Fatoorah", + "api", + "commerce", + "fatoorah", + "gateway", + "library", + "myfatoorah", + "payment", + "shipping" + ], + "time": "2024-04-28T12:22:01+00:00" + }, { "name": "nesbot/carbon", "version": "2.66.0", diff --git a/config/nafezly-payments.php b/config/nafezly-payments.php index b583b55..43867ed 100644 --- a/config/nafezly-payments.php +++ b/config/nafezly-payments.php @@ -162,5 +162,9 @@ 'PAYLINK_MODE'=>env('PAYLINK_MODE','test'), + 'MYFATOORAH_API_KEY'=>env('MYFATOORAH_API_KEY'), + 'MYFATOORAH_MODE'=>env('MYFATOORAH_MODE','test'), + 'MYFATOORAH_CURRENCY'=>env('MYFATOORAH_CURRENCY','SAR'), + 'MYFATOORAH_COUNTRY'=>env('MYFATOORAH_COUNTRY','EGY'), ]; \ No newline at end of file diff --git a/src/Classes/MyFatoorahPayment.php b/src/Classes/MyFatoorahPayment.php new file mode 100644 index 0000000..47527b9 --- /dev/null +++ b/src/Classes/MyFatoorahPayment.php @@ -0,0 +1,76 @@ +config = [ + 'apiKey' => config('nafezly-payments.MYFATOORAH_API_KEY'), + 'isTest' => strtolower(config('nafezly-payments.MYFATOORAH_MODE', 'test')) == 'test', + 'countryCode' => config('nafezly-payments.MYFATOORAH_COUNTRY_CODE') + ]; + $this->verify_route_name = config('nafezly-payments.VERIFY_ROUTE_NAME'); + + $this->setCurrency(config('nafezly-payments.MYFATOORAH_CURRENCY')); + } + + public function pay( + $amount, + $user_id = null, + $user_first_name = null, + $user_last_name = null, + $user_email = null, + $user_phone = null, + $source = null + ) { + $this->setPassedVariablesToGlobal($amount, $user_id, $user_first_name, $user_last_name, $user_email, + $user_phone, $source); + $required_fields = ['amount', 'user_first_name', 'user_last_name']; + $this->checkRequiredFields($required_fields, 'MYFATOORAH'); + $custom_reference = uniqid() . '-nafezly-' . uniqid(); + $res = (new MyFatoorahPaymentProvider($this->config))->getInvoiceURL([ + 'InvoiceValue' => $amount, + 'CustomerName' => $user_first_name . ' ' . $user_last_name, + 'NotificationOption' => 'LNK', + 'DisplayCurrencyIso' => $this->currency, + 'CallBackUrl' => route($this->verify_route_name, + ['payment' => "myfatootah", 'cus_ref' => $custom_reference]), + 'ErrorUrl' => route($this->verify_route_name, ['payment' => "myfatootah", 'cus_ref' => $custom_reference]), + 'Language' => in_array(app()->getLocale(), ['ar', 'en']) ? app()->getLocale() : 'en', + 'CustomerReference' => $custom_reference, + + + ]); + + return [ + 'payment_id' => $res['invoiceId'], + 'html' => "", + 'redirect_url' => $res['InvoiceURL'] + ]; + + } + + public function verify(Request $request) + { + $data = (new MyFatoorahPaymentStatusProvider($this->config))->getPaymentStatus($request->get('cus_ref'), + 'CustomerReference'); + $status = $data->InvoiceStatus == "Paid"; + return [ + 'success' => $status, + 'payment_id' => $data->InvoiceID, + 'message' => $status ? __('nafezly::messages.PAYMENT_DONE') : __('nafezly::messages.PAYMENT_FAILED'), + 'process_data' => json_decode(json_encode($data), true) + ]; + } +} \ No newline at end of file From ee7d3978165eddb600b043b9b773d8c679766451 Mon Sep 17 00:00:00 2001 From: Alaa Elsaid Date: Thu, 9 May 2024 06:19:49 +0300 Subject: [PATCH 2/2] Bind MyFatoorah to Container --- src/NafezlyPaymentsServiceProvider.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/NafezlyPaymentsServiceProvider.php b/src/NafezlyPaymentsServiceProvider.php index 4a1cb56..75fc082 100644 --- a/src/NafezlyPaymentsServiceProvider.php +++ b/src/NafezlyPaymentsServiceProvider.php @@ -6,6 +6,7 @@ use Nafezly\Payments\Classes\FawryPayment; use Nafezly\Payments\Classes\HyperPayPayment; use Nafezly\Payments\Classes\KashierPayment; +use Nafezly\Payments\Classes\MyFatoorahPayment; use Nafezly\Payments\Classes\PaymobPayment; use Nafezly\Payments\Classes\PayPalPayment; use Nafezly\Payments\Classes\PaytabsPayment; @@ -84,6 +85,9 @@ public function register() $this->app->bind(PaytabsPayment::class, function () { return new PaytabsPayment(); }); + $this->app->bind(MyFatoorahPayment::class, function () { + return new MyFatoorahPayment(); + }); } /**