├── .DS_Store
├── gateways
├── helper.php
├── GatewayProvider.php
├── Gateway.php
├── publish
│ └── config
│ │ └── gateways.php
├── SMS
│ ├── SmsEG.php
│ ├── ForJawaly.php
│ └── SMSMISR.php
└── Payments
│ ├── Fawaterak.php
│ ├── Moyassar.php
│ ├── Fawry.php
│ └── MyFatoorah.php
├── LICENSE
├── composer.json
└── README.md
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arabnewscms/gateways/HEAD/.DS_Store
--------------------------------------------------------------------------------
/gateways/helper.php:
--------------------------------------------------------------------------------
1 | getaway();
7 | return new $data;
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/gateways/GatewayProvider.php:
--------------------------------------------------------------------------------
1 | publishes([__DIR__ . '/publish/config' => base_path('config')]);
16 | }
17 |
18 | /**
19 | * Register services.
20 | *
21 | * @return void
22 | */
23 | public function register() {
24 |
25 | }
26 |
27 | public function provides() {
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/gateways/Gateway.php:
--------------------------------------------------------------------------------
1 | provider = $provider;
11 | }
12 |
13 | public function getaway() {
14 | if ($this->provider == 'fawry') {
15 | return 'Phpanonymous\Gateways\Payments\Fawry';
16 | } elseif ($this->provider == 'moyassar') {
17 | return 'Phpanonymous\Gateways\Payments\Moyassar';
18 | } elseif ($this->provider == 'myfatoorah') {
19 | return 'Phpanonymous\Gateways\Payments\MyFatoorah';
20 | } elseif ($this->provider == 'fawaterak') {
21 | return 'Phpanonymous\Gateways\Payments\Fawaterak';
22 | } elseif ($this->provider == 'smsmisr') {
23 | return 'Phpanonymous\Gateways\SMS\SMSMISR';
24 | } elseif ($this->provider == '4jawaly') {
25 | return 'Phpanonymous\Gateways\SMS\ForJawaly';
26 | } else {
27 | throw new Exception('Please choose your Provider Payments or SMS');
28 | }
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 php anonymous
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name":"phpanonymous/gateways",
3 | "description": "all gateways SMS & Payments gateways By (Mahmoud Ibrahim) ",
4 | "type":"package",
5 | "license": "MIT",
6 | "keywords":["laravel","gateways","SMS","Payments","php"],
7 | "authors":[
8 | {
9 | "name":"Mahmoud Ibrahim",
10 | "email":"php.anonymous1@gmail.com",
11 | "homepage":"https://github.com/arabnewscms"
12 | }
13 | ],
14 | "require":{
15 | "php": "^5.6|^7.3|^8.0",
16 | "laravel/framework": "^5.0|^6.21.0|^7.0|^8.0|^9.0|^10.0"
17 | },
18 | "autoload":{
19 | "psr-4":{
20 | "Phpanonymous\\Gateways\\":"gateways/"
21 | },
22 | "files":[
23 | "gateways/helper.php"
24 | ]
25 | },
26 | "extra": {
27 | "branch-alias": {
28 | "dev-master": "1.8.x-dev"
29 | },
30 | "laravel": {
31 | "providers": [
32 | "Phpanonymous\\Gateways\\GatewayProvider"
33 | ],
34 | "aliases": {
35 | "Geteway" : "Phpanonymous\\Gateways\\Gateway"
36 | }
37 | }
38 | },
39 | "version":"1.8",
40 | "minimum-stability": "RC",
41 | "prefer-stable": true
42 | }
43 |
--------------------------------------------------------------------------------
/gateways/publish/config/gateways.php:
--------------------------------------------------------------------------------
1 | [
4 |
5 | /**
6 | * SMS Providers and Configurations multi providers
7 | *
8 | * enable Multiple getaway to use it in your project
9 | * fawry,myfatoorah,moyassar,fawaterk
10 | */
11 | 'enable_payments' => [
12 | 'fawry',
13 | 'moyassar',
14 | 'myfatoorah',
15 | 'fawaterk',
16 | ],
17 |
18 | ],
19 | /**
20 | * Payments configurations multi getaway
21 | * available providers fawry,moyassar
22 | */
23 | 'payments' => [
24 | 'fawry' => [
25 | "mode" => "sandbox", // sandbox , live
26 | "merchant_code" => "",
27 | "security_key" => "",
28 | ],
29 | 'moyassar' => [
30 | "mode" => "sandbox", // sandbox , live
31 | "test_secret_key" => "",
32 | "test_publishable_key" => "",
33 | "live_secret_key" => "",
34 | "live_publishable_key" => "",
35 | ],
36 | 'myfatoorah' => [
37 | "mode" => "sandbox", // sandbox OR demo , live
38 | "secret_key" => "",
39 | "token" => "",
40 | "live_url" => null,
41 | ],
42 | 'fawaterk' => [
43 | 'mode' => 'sandbox', // sandbox , live
44 | 'api_key' => '',
45 | ],
46 |
47 | ],
48 |
49 | /**
50 | * SMS Providers and Configurations multi providers
51 | * default smsmisr
52 | */
53 | 'sms' => [
54 | 'smsmisr' => [
55 | 'username' => '',
56 | 'password' => '',
57 | 'sender' => '', // default sender name
58 | 'language' => 1, // 1 For English , 2 For Arabic , 3 For Unicode
59 | ],
60 | '4jawaly' => [
61 | 'username' => '',
62 | 'password' => '',
63 | 'sender' => '',
64 | ]
65 | ],
66 |
67 | ];
--------------------------------------------------------------------------------
/gateways/SMS/SmsEG.php:
--------------------------------------------------------------------------------
1 | config = (object) config('gateways.sms.smseg');
28 |
29 | $this->locale = app()->getLocale();
30 |
31 | $this->params['language'] = $this->config->language;
32 | $this->params['sender'] = $this->config->sender;
33 | $this->params['username'] = $this->config->username;
34 | $this->params['password'] = $this->config->password;
35 | //$this->params['SMSID'] = $this->config->sender;
36 |
37 | //set Headers
38 | $this->headers = [
39 | 'Content-Type' => 'application/json',
40 | 'Accept' => 'application/json',
41 | ];
42 |
43 | // Links gateway Methods
44 | $this->links = [
45 | 'SEND' => $this->link . '/v2/',
46 | 'BALANCE' => $this->link . '/Request',
47 | ];
48 | }
49 |
50 | /**
51 | * @function checkPrams to check param exists
52 | * @return Exception
53 | */
54 | protected function checkParams($params = [], $default = null) {
55 | foreach ($params as $param) {
56 | $param = strtolower($param);
57 | if (is_null($default)) {
58 | $all_keys = array_keys($this->params);
59 | $all_keys = array_map('strtolower', $all_keys);
60 |
61 | if (!in_array($param, $all_keys)) {
62 | dd($param . !in_array($param, array_keys($this->params), false));
63 | throw new \Exception($param . ' parameter not found');
64 | }
65 | } else {
66 | $all_keys = array_keys($default);
67 | $all_keys = array_map('strtolower', $all_keys);
68 |
69 | if (!in_array($param, $all_keys, true)) {
70 | throw new \Exception($param . ' parameter not found');
71 | }
72 | }
73 | }
74 | }
75 |
76 | /**
77 | * function signature
78 | * to generate signature code for fawry
79 | * @return void
80 | */
81 | protected function signature(): void {
82 | if ($this->method == 'SEND') {
83 | $params = ['Username', 'password', 'language', 'sender', 'Mobile', 'message'];
84 | } elseif ($this->method == 'BALANCE') {
85 | $params = ['username', 'password', 'smsid'];
86 | }
87 |
88 | if (isset($params)) {
89 | $this->checkParams($params);
90 | }
91 | }
92 |
93 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # All gateways payments & SMS
2 | package name: `gateways`
3 |
4 |
5 | package version: `v1.4`
6 |
7 |
8 | author : `mahmoud ibrahim`
9 |
10 |
11 | description :`provide gateways payments and SMS`
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | to install this pacakge
40 |
41 | ```
42 | composer require phpanonymous/gateways
43 | ```
44 |
45 | then publish config/gateways.php file
46 |
47 | ```
48 | php artisan vendor:publish --provider="Phpanonymous\Gateways\GatewayProvider"
49 | ```
50 |
51 | available gateways click on logo to visit usage wiki
52 |
53 | ### payment gateways
54 |
55 |
56 |
58 |
60 |
62 |
63 |
64 | ### SMS gateways
65 |
66 |
67 |
68 |
69 |
70 | # documents
71 |
72 | https://github.com/arabnewscms/gateways/wiki
73 |
74 | More services are included soon
75 |
76 |
--------------------------------------------------------------------------------
/gateways/SMS/ForJawaly.php:
--------------------------------------------------------------------------------
1 | config = (object) config('gateways.sms.4jawaly');
32 |
33 | $this->params['sender'] = $this->config->sender;
34 | $this->params['username'] = $this->config->username;
35 | $this->params['password'] = $this->config->password;
36 | $this->params['unicode'] = 'E';
37 | $this->params['return'] = 'json';
38 |
39 | $this->links = [
40 | 'SEND' => $this->link . 'sendsms.php',
41 | 'BALANCE' => $this->link . 'getbalance.php',
42 | ];
43 |
44 | }
45 |
46 |
47 | /**
48 | * @function checkPrams to check param exists
49 | * @return Exception
50 | */
51 | protected function checkParams($params = [], $default = null) {
52 | foreach ($params as $param) {
53 | $param = strtolower($param);
54 | if (is_null($default)) {
55 | $all_keys = array_keys($this->params);
56 | $all_keys = array_map('strtolower', $all_keys);
57 |
58 | if (!in_array($param, $all_keys)) {
59 | throw new \Exception($param . ' parameter not found');
60 | }
61 | } else {
62 | $all_keys = array_keys($default);
63 | $all_keys = array_map('strtolower', $all_keys);
64 |
65 | if (!in_array($param, $all_keys, true)) {
66 | throw new \Exception($param . ' parameter not found');
67 | }
68 | }
69 | }
70 | }
71 |
72 | /**
73 | * function signature
74 | * to generate signature code for gateway
75 | * @return void
76 | */
77 | protected function signature(): void {
78 | if ($this->method == 'SEND') {
79 | $params = ['sender', 'username', 'password', 'unicode', 'return', 'numbers', 'message'];
80 | } elseif ($this->method == 'BALANCE') {
81 | $params = ['sender', 'username', 'password', 'unicode', 'return'];
82 | }
83 |
84 | if (isset($params)) {
85 | $this->checkParams($params);
86 | }
87 | }
88 |
89 | /**
90 | * set the payment_method to binding in params
91 | * @return method chaining or Exception
92 | */
93 | public function method($method): self {
94 | if (in_array($method, $this->methods)) {
95 | $this->params['method'] = $method;
96 | $this->method = $method;
97 | return $this;
98 | } else {
99 | // throw exception if not set payment method from array
100 | throw new \Exception('Set payment Method ' . implode(',', $this->methods));
101 | }
102 | }
103 |
104 | public function mobile($mobile): self{
105 | $this->params['numbers'] = is_array($mobile) ? implode(',', $mobile) : $mobile;
106 | return $this;
107 | }
108 |
109 | public function message($message): self{
110 | $this->params['message'] = $message;
111 | return $this;
112 | }
113 |
114 | public function send(){
115 | $this->signature();
116 | unset($this->params['method']);
117 | $response = Http::get( $this->links['SEND'] ,$this->params);
118 | return $response->json();
119 | }
120 |
121 | public function balance() {
122 | $this->signature();
123 | unset($this->params['method'], $this->params['numbers'], $this->params['message']);
124 | $response = Http::get( $this->links['BALANCE'] ,$this->params);
125 | return $response->json();
126 | }
127 |
128 | }
--------------------------------------------------------------------------------
/gateways/Payments/Fawaterak.php:
--------------------------------------------------------------------------------
1 | config = (object) config('gateways.payments.fawaterk');
46 |
47 | $this->locale = app()->getLocale() == 'ar' ? 'AR' : 'EN';
48 |
49 | //set Headers
50 | $this->headers = [
51 | 'Content-Type' => 'application/json',
52 | 'Accept' => 'application/json',
53 | 'Authorization' => 'Bearer ' . $this->config->api_key,
54 | ];
55 |
56 | // prepare links
57 | $this->link = $this->config->mode == 'live' ? 'https://fawaterk.com' : 'https://staging.fawaterk.com';
58 |
59 | // Links gateway Methods
60 | $this->links = [
61 | "INVOICE" => $this->link . "/" . $this->version . "/createInvoiceLink",
62 | "METHODS" => $this->link . "/" . $this->version . "/getPaymentmethods",
63 | "PAY" => $this->link . "/" . $this->version . "/invoiceInitPay",
64 | "getInvoiceData" => $this->link . "/" . $this->version."/getInvoiceData",
65 | ];
66 |
67 | }
68 |
69 | /**
70 | * @function checkPrams to check param exists
71 | * @return Exception
72 | */
73 | protected function checkParams($params = [], $default = null) {
74 | foreach ($params as $param) {
75 | $param = strtolower($param);
76 | if (is_null($default)) {
77 | $all_keys = array_keys($this->params);
78 | $all_keys = array_map('strtolower', $all_keys);
79 |
80 | if (!in_array($param, $all_keys)) {
81 | //dd($param . !in_array($param, array_keys($this->params), false));
82 | throw new \Exception($param . ' parameter not found');
83 | }
84 | } else {
85 | $all_keys = array_keys($default);
86 | $all_keys = array_map('strtolower', $all_keys);
87 |
88 | if (!in_array($param, $all_keys, true)) {
89 | throw new \Exception($param . ' parameter not found');
90 | }
91 | }
92 | }
93 | }
94 |
95 | /**
96 | * function signature
97 | * to generate signature code for fawry
98 | * @return void
99 | */
100 | protected function signature(): void {
101 | if ($this->payment_method == 'INVOICE' || $this->payment_method == 'PAY') {
102 | $params = ['currency', 'cartTotal', 'customer', 'cartItems'];
103 | }
104 |
105 | if (isset($params)) {
106 | $this->checkParams($params);
107 | }
108 | }
109 |
110 | /**
111 | * set the payment_method to binding in params
112 | * @return method chaining or Exception
113 | */
114 | public function method($method): self {
115 | if (in_array($method, $this->methods)) {
116 | $this->params['method'] = $method;
117 | $this->payment_method = $method;
118 |
119 | return $this;
120 | } else {
121 | // throw exception if not set payment method from array
122 | throw new \Exception('set payment Method ' . implode(',', $this->methods));
123 | }
124 | }
125 |
126 | /**
127 | * query method
128 | * to binding params
129 | * @return method chaining
130 | */
131 | public function query($query = []): self{
132 | $this->params = array_merge($query, $this->params);
133 | $this->signature();
134 | return $this;
135 | }
136 |
137 | public function id(int $invoice_id){
138 | $this->signature();
139 | $this->response = $this->response(
140 | Http::withHeaders($this->headers)
141 | ->get($this->links['getInvoiceData'].'/'.$invoice_id)
142 | );
143 | return $this->response['collect'];
144 | }
145 |
146 |
147 |
148 | /**
149 | * @param $response
150 | * @return array
151 | */
152 | public function response($response): array{
153 | return [
154 | 'status' => $response->status(),
155 | 'json' => $response->json(),
156 | 'body' => $response->body(),
157 | 'collect' => $response->collect(),
158 | 'ok' => $response->ok(),
159 | 'successful' => $response->successful(),
160 | 'failed' => $response->failed(),
161 | 'serverError' => $response->serverError(),
162 | 'clientError' => $response->clientError(),
163 | 'headers' => $response->headers(),
164 | ];
165 | }
166 |
167 | /**
168 | * auto redirect to transaction url
169 | * @return method chaining
170 | */
171 | public function redirect() {
172 | $this->params['redirect'] = true;
173 | return $this;
174 | }
175 |
176 | /**
177 | * create invoice
178 | * @param null
179 | * @return array
180 | */
181 | public function create() {
182 | if (!in_array($this->params['currency'], $this->currency)) {
183 | throw new \Exception('currency accepted ' . implode(',', $this->currency));
184 | }
185 | unset($this->params['method']);
186 | $this->response = $this->response(
187 | Http::withHeaders($this->headers)
188 | ->post($this->links[$this->payment_method], $this->params)
189 | );
190 |
191 | if ($this->response['collect']['status'] == 422) {
192 | return $this->response;
193 | } elseif (isset($this->params['redirect']) && $this->response['collect']['status'] == 'success') {
194 | //payment_data
195 | if ($this->payment_method == 'PAY') {
196 | return redirect($this->response['collect']['data']['payment_data']['redirectTo']);
197 | } else {
198 |
199 | return redirect($this->response['collect']['data']['url']);
200 | }
201 | } else {
202 | return $this->response['collect'];
203 | }
204 | }
205 |
206 | /**
207 | * get Payment methods
208 | * @param null
209 | * @return array
210 | */
211 | public function all() {
212 | $this->response = $this->response(
213 | Http::withHeaders($this->headers)
214 | ->get($this->links['METHODS'])
215 | );
216 | return $this->response['collect'];
217 | }
218 |
219 | }
220 |
--------------------------------------------------------------------------------
/gateways/SMS/SMSMISR.php:
--------------------------------------------------------------------------------
1 | config = (object) config('gateways.sms.smsmisr');
29 |
30 | $this->locale = app()->getLocale();
31 |
32 | $this->params['language'] = $this->config->language;
33 | $this->params['sender'] = $this->config->sender;
34 | $this->params['username'] = $this->config->username;
35 | $this->params['password'] = $this->config->password;
36 | //$this->params['SMSID'] = $this->config->sender;
37 |
38 | //set Headers
39 | $this->headers = [
40 | 'Content-Type' => 'application/json',
41 | 'Accept' => 'application/json',
42 | ];
43 |
44 | // Links gateway Methods
45 | $this->links = [
46 | 'SEND' => $this->link . '/v2/',
47 | 'BALANCE' => $this->link . '/Request',
48 | ];
49 | }
50 |
51 | /**
52 | * @function checkPrams to check param exists
53 | * @return Exception
54 | */
55 | protected function checkParams($params = [], $default = null) {
56 | foreach ($params as $param) {
57 | $param = strtolower($param);
58 | if (is_null($default)) {
59 | $all_keys = array_keys($this->params);
60 | $all_keys = array_map('strtolower', $all_keys);
61 |
62 | if (!in_array($param, $all_keys)) {
63 | dd($param . !in_array($param, array_keys($this->params), false));
64 | throw new \Exception($param . ' parameter not found');
65 | }
66 | } else {
67 | $all_keys = array_keys($default);
68 | $all_keys = array_map('strtolower', $all_keys);
69 |
70 | if (!in_array($param, $all_keys, true)) {
71 | throw new \Exception($param . ' parameter not found');
72 | }
73 | }
74 | }
75 | }
76 |
77 | /**
78 | * function signature
79 | * to generate signature code for fawry
80 | * @return void
81 | */
82 | protected function signature(): void {
83 | if ($this->method == 'SEND') {
84 | $params = ['Username', 'password', 'language', 'sender', 'Mobile', 'message'];
85 | } elseif ($this->method == 'BALANCE') {
86 | $params = ['username', 'password', 'smsid'];
87 | }
88 |
89 | if (isset($params)) {
90 | $this->checkParams($params);
91 | }
92 | }
93 |
94 | /**
95 | * set the payment_method to binding in params
96 | * @return method chaining or Exception
97 | */
98 | public function method($method): self {
99 | if (in_array($method, $this->methods)) {
100 | $this->params['method'] = $method;
101 | $this->signature();
102 |
103 | return $this;
104 | } else {
105 | // throw exception if not set payment method from array
106 | throw new \Exception('Set payment Method ' . implode(',', $this->methods));
107 | }
108 | }
109 |
110 | /**
111 | * @param $response
112 | * @return array
113 | */
114 | public function response($response): array{
115 | return [
116 | 'status' => $response->status(),
117 | 'json' => $response->json(),
118 | 'body' => $response->body(),
119 | 'collect' => $response->collect(),
120 | 'ok' => $response->ok(),
121 | 'successful' => $response->successful(),
122 | 'failed' => $response->failed(),
123 | 'serverError' => $response->serverError(),
124 | 'clientError' => $response->clientError(),
125 | 'headers' => $response->headers(),
126 | ];
127 | }
128 |
129 | public function mobile($mobile): self{
130 | $this->params['mobile'] = is_array($mobile) ? implode(',', $mobile) : $mobile;
131 | return $this;
132 | }
133 |
134 | public function language($language): self{
135 | $this->params['language'] = $language;
136 | return $this;
137 | }
138 |
139 | public function sender($sender): self{
140 | $this->params['sender'] = $sender;
141 | return $this;
142 | }
143 |
144 | public function message($message): self{
145 | $this->params['message'] = $message;
146 | return $this;
147 | }
148 |
149 | public function DelayUntil($DelayUntil): self{
150 | $this->params['DelayUntil'] = $DelayUntil;
151 | return $this;
152 | }
153 | public function request($status): self{
154 | $this->params['request'] = $status;
155 | return $this;
156 | }
157 |
158 | public function smsid($SMSID): self{
159 | $this->params['smsid'] = $SMSID;
160 | return $this;
161 | }
162 |
163 | public function send() {
164 | unset($this->params['method']);
165 | $send = $this->response(
166 | Http::withHeaders($this->headers)
167 | ->post($this->links['SEND'], $this->params)
168 | );
169 | return $send;
170 | if ($send['status'] == 500) {
171 | return [
172 | 'status' => $send['status'],
173 | 'code' => 500,
174 | 'message' => $send['body'],
175 | ];
176 | } else {
177 | return [
178 | 'status' => $send['status'],
179 | 'code' => $send['collect']['code'],
180 | 'message' => $this->code($send['collect']['code']),
181 | 'data' => $send['collect'],
182 | ];
183 | }
184 | }
185 |
186 | public function balance() {
187 | unset($this->params['method'], $this->params['language'], $this->params['sender']);
188 | $balance = $this->response(
189 | Http::
190 | post($this->links['BALANCE'] .
191 | '?username=' . $this->params['username'] . '&'
192 | . 'password=' . $this->params['password'] . '&'
193 | . 'smsid=' . $this->params['smsid'] . '&'
194 | . 'request=' . $this->params['request'] . '&'
195 | )
196 | );
197 |
198 | return [
199 | 'status' => $balance['status'],
200 | 'data' => $balance['collect'],
201 | 'body' => $balance['body'],
202 | ];
203 | }
204 |
205 | public function code($code) {
206 | $msg = [];
207 | $msg['1901'] = 'Success, Message Submitted Successfully';
208 | $msg['1902'] = 'Invalid URL , This means that one of the parameters was not provided';
209 | $msg['1200'] = 'You sent a lot of requests at the same time , please make a delay at least 1 sec';
210 | $msg['1903'] = 'Invalid value in username or password field';
211 | $msg['1904'] = 'Invalid value in "sender" field';
212 | $msg['1905'] = 'Invalid value in "mobile" field';
213 | $msg['1906'] = 'Insufficient Credit.';
214 | $msg['1907'] = 'Server under updating';
215 | $msg['1908'] = 'Invalid Date & Time format in “DelayUntil=” parameter';
216 | $msg['1909'] = 'Error In Message';
217 | $msg['8001'] = 'Mobile IS Null';
218 | $msg['8002'] = 'Message IS Null';
219 | $msg['8003'] = 'Language IS Null';
220 | $msg['8004'] = 'Sender IS Null';
221 | $msg['8005'] = 'Username IS Null';
222 | $msg['8006'] = 'Password IS Null';
223 | $msg['8006'] = 'Password IS Null';
224 | $msg['6000'] = 'Success, Request Submitted Successfully';
225 | $msg['Error'] = 'Invalid URL , This means that one of the parameters was not provided or wrong information';
226 | return isset($msg[$code]) ? $msg[$code] : '';
227 | }
228 | }
--------------------------------------------------------------------------------
/gateways/Payments/Moyassar.php:
--------------------------------------------------------------------------------
1 | config = (object) config('gateways.payments.moyassar');
29 | $this->locale = app()->getLocale() == 'ar' ? 'ar' : 'en';
30 |
31 | // Set live & sandbox keys publishable_key | secret_key
32 | $this->params['secret_key'] = $this->config->mode == 'live' ? $this->config->live_secret_key : $this->config->test_secret_key;
33 |
34 | $this->params['publishable_api_key'] = $this->config->mode == 'live' ? $this->config->live_publishable_key : $this->config->test_publishable_key;
35 |
36 | //$this->params['language'] = $this->locale == 'ar' ? 'ar' : 'en';
37 |
38 | // prepare links
39 | $this->link = $this->config->mode == 'sandbox' ? 'https://api.moyasar.com' : 'https://api.moyasar.com';
40 |
41 | $this->links = [
42 | "CREDITCARD" => $this->link . "/v1/payments",
43 | "APPLEPAY" => $this->link . "/v1/payments",
44 | "STCPAY" => $this->link . "/v1/payments",
45 | "SADAD" => $this->link . "/v1/payments",
46 | "MADA" => $this->link . "/v1/payments",
47 | ];
48 |
49 | }
50 |
51 | /**
52 | * @function checkPrams to check param exists
53 | * @return Exception
54 | */
55 | protected function checkParams($params = []) {
56 | foreach ($params as $param) {
57 | if (!isset($this->params[$param])) {
58 | throw new \Exception($param . ' parameter not found');
59 | }
60 | }
61 | }
62 |
63 | /**
64 | * perpare param hash
65 | * @return $hash params
66 | */
67 | protected function getParams($params = []) {
68 | $params_list = '?source[type]=' . strtolower($this->params['source[type]']) . '&';
69 | foreach ($params as $param) {
70 | $params_list .= $param . '=' . $this->params[$param] . '&';
71 | }
72 | return rtrim($params_list, '&');
73 | }
74 |
75 | /**
76 | * function signature
77 | * to generate signature code for fawry
78 | * @return hash sha256
79 | */
80 | protected function signature() {
81 | if ($this->payment_method == 'CREDITCARD') {
82 | $params = ['callback_url', 'amount', 'currency', 'description', 'source[3ds]', 'source[name]', 'source[number]', 'source[cvc]', 'source[month]', 'source[year]'];
83 | } elseif ($this->payment_method == 'APPLEPAY') {
84 | $params = ['source[type]', 'source[3ds]', 'source[token]', 'amount'];
85 | } elseif ($this->payment_method == 'STCPAY') {
86 | $params = ['source[type]', 'source[mobile]', 'source[branch]', 'source[cashier]', 'source[3ds]'];
87 | }
88 |
89 | if (isset($params)) {
90 | $this->checkParams($params);
91 | return $this->getParams($params);
92 | }
93 | }
94 |
95 | /**
96 | * set the payment_method to binding in params
97 | * @return method chaining or Exception
98 | */
99 | public function method($method): self {
100 | if (in_array($method, $this->methods)) {
101 | $this->params['source[type]'] = strtolower($method);
102 | $this->payment_method = $method;
103 |
104 | return $this;
105 | } else {
106 | // throw exception if not set payment method from array
107 | throw new \Exception('set payment Method ' . implode(',', $this->methods));
108 | }
109 | }
110 |
111 | /**
112 | * query method
113 | * to binding params
114 | * @return method chaining
115 | */
116 | public function query($query = []): self{
117 | $this->params = array_merge($query, $this->params);
118 | $this->signature();
119 | return $this;
120 | }
121 |
122 | /**
123 | * @param $response
124 | * @return array
125 | */
126 | public function response($response): array{
127 | return [
128 | 'status' => $response->status(),
129 | 'json' => $response->json(),
130 | 'body' => $response->body(),
131 | 'collect' => $response->collect(),
132 | 'ok' => $response->ok(),
133 | 'successful' => $response->successful(),
134 | 'failed' => $response->failed(),
135 | 'serverError' => $response->serverError(),
136 | 'clientError' => $response->clientError(),
137 | 'headers' => $response->headers(),
138 | ];
139 | }
140 |
141 | /**
142 | * auto redirect to transaction url
143 | * @return method chaining
144 | */
145 | public function redirect() {
146 | $this->params['redirect'] = true;
147 | return $this;
148 | }
149 |
150 | /**
151 | * fetch data
152 | * @return array
153 | */
154 | public function fetch($str_id = null) {
155 | return $this->response(
156 | Http::get($this->links['CREDITCARD'] . '/' . $str_id . '?publishable_api_key=' . $this->params['secret_key'])
157 | );
158 | }
159 |
160 | /**
161 | * capture data payment
162 | * @return array
163 | */
164 | public function capture($str_id = null) {
165 | $params = isset($this->params['amount']) ? ['amount' => $this->params['amount']] : [];
166 | return $this->response(Http::withHeaders([
167 | 'Content-Type' => 'application/json',
168 | 'Accept' => 'application/json',
169 | ])->post($this->links['CREDITCARD'] . '/' . $str_id . '/capture?source[type]=' . strtolower($this->payment_method) . '&publishable_api_key=' . $this->params['secret_key'], $params)
170 | );
171 | }
172 |
173 | /**
174 | * unPaid data payment
175 | * @return array
176 | */
177 | public function unPaid($str_id = null) {
178 | return $this->response(Http::withHeaders([
179 | 'Content-Type' => 'application/json',
180 | 'Accept' => 'application/json',
181 | ])->post($this->links['CREDITCARD'] . '/' . $str_id . '/void?source[type]=' . strtolower($this->payment_method) . '&publishable_api_key=' . $this->params['secret_key'])
182 | );
183 | }
184 |
185 | /**
186 | * refund data payment
187 | * @return array
188 | */
189 | public function refund($str_id = null) {
190 | $params = isset($this->params['amount']) ? ['amount' => $this->params['amount']] : [];
191 |
192 | return $this->response(Http::withHeaders([
193 | 'Content-Type' => 'application/json',
194 | 'Accept' => 'application/json',
195 | ])->post($this->links['CREDITCARD'] . '/' . $str_id . '/refund?source[type]=' . strtolower($this->payment_method) . '&publishable_api_key=' . $this->params['secret_key'], $params)
196 | );
197 | }
198 |
199 | /**
200 | * update data payment
201 | * @return array
202 | */
203 | public function update($str_id = null) {
204 | $params = isset($this->params['description']) ? ['description' => $this->params['description']] : [];
205 |
206 | return $this->response(Http::withHeaders([
207 | 'Content-Type' => 'application/json',
208 | 'Accept' => 'application/json',
209 | ])->put($this->links['CREDITCARD'] . '/' . $str_id . '?source[type]=' . strtolower($this->payment_method) . '&publishable_api_key=' . $this->params['secret_key'], $params)
210 | );
211 | }
212 |
213 | /**
214 | * List payments
215 | * @return array
216 | */
217 | public function get() {
218 | unset($this->params['publishable_api_key']);
219 | $params = '?publishable_api_key=' . $this->params['secret_key'] . '&';
220 | foreach ($this->params as $key => $val) {
221 | $params .= $key . '=' . $val . '&';
222 | }
223 | $params = rtrim($params, '&');
224 | $response = $this->response(
225 | Http::get($this->links['CREDITCARD'] . $params)
226 | );
227 | unset($response['json'], $response['body']);
228 | return $response;
229 | }
230 |
231 | /**
232 | * purchase to pay with multi methods
233 | * @param null
234 | * @return array
235 | */
236 | public function purchase() {
237 | $response = $this->response(
238 | Http::withHeaders([
239 | 'Content-Type' => 'application/json',
240 | 'Accept' => 'application/json',
241 | ])->post($this->links[$this->payment_method] . $this->signature(), $this->params)
242 | );
243 | if (isset($this->params['redirect'])) {
244 | if ($response['status'] == 201 && $response['collect']['status'] == 'initiated') {
245 | return redirect($response['collect']['source']['transaction_url']);
246 | } else {
247 | return $response;
248 | }
249 | } else {
250 | return $response;
251 | }
252 | }
253 |
254 | }
--------------------------------------------------------------------------------
/gateways/Payments/Fawry.php:
--------------------------------------------------------------------------------
1 | config = (object) config('gateways.payments.fawry');
29 | $this->locale = app()->getLocale() == 'ar' ? 'ar-eg' : 'en-gb';
30 |
31 | // Set merchantCode & secureKey from config
32 | $this->params['merchantCode'] = $this->config->merchant_code;
33 | $this->params['secureKey'] = $this->config->security_key;
34 | $this->params['language'] = $this->locale == 'ar' ? 'ar-eg' : 'en-gb';
35 |
36 | // prepare links
37 | $this->link = $this->config->mode == 'sandbox' ? 'https://atfawry.fawrystaging.com' : 'https://www.atfawry.com';
38 |
39 | $this->links = [
40 | "installment_plans" => $this->link . "/ECommerceWeb/api/merchant/installment-plans",
41 | "CARD" => $this->link . "/ECommerceWeb/Fawry/payments/charge",
42 | "PAYATFAWRY" => $this->link . "/ECommerceWeb/Fawry/payments/charge",
43 | "MWALLET" => $this->link . "/ECommerceWeb/api/payments/charge",
44 | "VALU" => $this->link . "/ECommerceWeb/api/payments/charge",
45 | "CASHONDELIVERY" => $this->link . "/ECommerceWeb/Fawry/payments/charge",
46 | "STATUS_V1" => $this->link . "/ECommerceWeb/Fawry/payments/status",
47 | "STATUS_V2" => $this->link . "/ECommerceWeb/Fawry/payments/status/v2",
48 | "REFUND" => $this->link . "/ECommerceWeb/Fawry/payments/refund",
49 | "CANCEL" => $this->link . "/ECommerceWeb/api/orders/cancel-unpaid-order",
50 | ];
51 |
52 | }
53 |
54 | /**
55 | * @function checkPrams to check param exists
56 | * @return Exception
57 | */
58 | protected function checkParams($params = []) {
59 | foreach ($params as $param) {
60 | if (!isset($this->params[$param])) {
61 | throw new \Exception($param . ' parameter not found');
62 | }
63 | }
64 | }
65 |
66 | /**
67 | * perpare param hash
68 | * @return $hash params
69 | */
70 | protected function getParams($params = []) {
71 | $params_list = '';
72 | foreach ($params as $param) {
73 | $params_list .= $this->params[$param];
74 | }
75 | return $params_list;
76 | }
77 | /**
78 | * function signature
79 | * to generate signature code for fawry
80 | * @return hash sha256
81 | */
82 | protected function signature(): string {
83 | if (isset($this->params['version'])) {
84 | // authrize and capture
85 | $params = ['merchantCode', 'merchantRefNum', 'secureKey'];
86 | } elseif ($this->params['payment_method'] == 'PAYATFAWRY') {
87 | // PAYATFAWRY
88 | $params = ['merchantCode', 'merchantRefNum', 'customerProfileId', 'payment_method', 'amount', 'secureKey'];
89 |
90 | } elseif ($this->params['payment_method'] == 'MWALLET') {
91 | //MWALLET
92 | if (isset($this->params['customerProfileId'])) {
93 | $params = ['merchantCode', 'merchantRefNum', 'customerProfileId', 'payment_method', 'amount', 'customerMobile', 'secureKey'];
94 |
95 | } else {
96 | $params = ['merchantCode', 'merchantRefNum', 'payment_method', 'amount', 'customerMobile', 'secureKey'];
97 | }
98 |
99 | } elseif ($this->params['payment_method'] == 'VALU') {
100 | //VALU
101 | $params = ['merchantCode', 'merchantRefNum', 'customerProfileId', 'payment_method', 'amount', 'valuCustomerCode', 'secureKey'];
102 |
103 | } elseif ($this->params['payment_method'] == 'REFUND') {
104 | //REFUND
105 | if (isset($this->params['reason'])) {
106 | $params = ['merchantCode', 'referenceNumber', 'refundAmount', 'reason', 'secureKey'];
107 | } else {
108 | $params = ['merchantCode', 'referenceNumber', 'refundAmount', 'secureKey'];
109 | }
110 |
111 | } elseif ($this->params['payment_method'] == 'CANCEL') {
112 | //CANCEL payment
113 | $params = ['orderRefNo', 'merchantAccount', 'lang', 'secureKey'];
114 |
115 | } else {
116 | // 3D secure && pay using bank installments
117 | if (isset($this->params['customerProfileId']) && isset($this->params['installmentPlanId'])) {
118 | $params = ['merchantCode', 'merchantRefNum', 'customerProfileId', 'payment_method', 'amount', 'cardNumber', 'cardExpiryYear', 'cardExpiryMonth', 'cvv', 'installmentPlanId', 'secureKey'];
119 | } elseif (isset($this->params['installmentPlanId'])) {
120 |
121 | $params = ['merchantCode', 'merchantRefNum', 'customerProfileId', 'payment_method', 'amount', 'cardNumber', 'cardExpiryYear', 'cardExpiryMonth', 'cvv', 'installmentPlanId', 'secureKey'];
122 |
123 | } elseif (isset($this->params['customerProfileId'])) {
124 |
125 | $params = ['merchantCode', 'merchantRefNum', 'customerProfileId', 'payment_method', 'amount', 'cardNumber', 'cardExpiryYear', 'cardExpiryMonth', 'cvv', 'returnUrl', 'secureKey'];
126 | } else {
127 | $params = ['merchantCode', 'merchantRefNum', 'payment_method', 'amount', 'cardNumber', 'cardExpiryYear', 'cardExpiryMonth', 'cvv', 'returnUrl', 'secureKey'];
128 | }
129 |
130 | }
131 |
132 | $this->checkParams($params);
133 | return hash('sha256', $this->getParams($params));
134 | }
135 |
136 | /**
137 | * set the payment_method to binding in params and make signature
138 | * @return method chaining or Exception
139 | */
140 | public function method($method): self {
141 | if (in_array($method, $this->methods)) {
142 | $this->params['payment_method'] = $method;
143 | $this->payment_method = $method;
144 | return $this;
145 | } else {
146 | // throw exception if not set payment method from array
147 | throw new \Exception('set payment Method ' . implode(',', $this->methods));
148 | }
149 | }
150 |
151 | /**
152 | * query method
153 | * to binding params
154 | * @return method chaining
155 | */
156 | public function query($query = []): self{
157 | $this->params = array_merge($query, $this->params);
158 | $this->params['signature'] = $this->signature();
159 | return $this;
160 | }
161 |
162 | /**
163 | * @param $response
164 | * @return array
165 | */
166 | public function response($response): array{
167 | return [
168 | 'status' => $response->status(),
169 | 'json' => $response->json(),
170 | 'body' => $response->body(),
171 | 'collect' => $response->collect(),
172 | 'ok' => $response->ok(),
173 | 'successful' => $response->successful(),
174 | 'failed' => $response->failed(),
175 | 'serverError' => $response->serverError(),
176 | 'clientError' => $response->clientError(),
177 | 'headers' => $response->headers(),
178 | ];
179 | }
180 |
181 | /**
182 | * get installment by account number to pay by installment installmentPlan
183 | * @param $query
184 | * @return array
185 | */
186 | public function getInstallment($query = []): array{
187 | $this->params = array_merge($query, $this->params);
188 | // check if account number not binding and check if query function played
189 | if (!isset($this->params['accountNumber']) || isset($this->params['accountNumber']) && empty($this->params['accountNumber'])) {
190 | throw new \Exception('in installment please add accountNumber parameter');
191 | }
192 |
193 | // get installment plan info
194 | return $this->response(Http::get($this->links['installment_plans'], [
195 | 'query' => [
196 | 'accountNumber' => $this->params['accountNumber'],
197 | ],
198 | ]));
199 | }
200 |
201 | /**
202 | * purchase to pay with multi methods
203 | * @param null
204 | * @return array
205 | */
206 | public function purchase() {
207 |
208 | return $this->response(
209 | Http::withHeaders([
210 | 'Content-Type' => 'application/json',
211 | 'Accept' => 'application/json',
212 | ])
213 | ->asJson(json_encode($this->params))
214 | ->post($this->links[$this->payment_method])
215 | );
216 | }
217 |
218 | /**
219 | * status method to get payment status
220 | * @param null
221 | * @return array
222 | */
223 | public function status() {
224 | if (!isset($this->params['version']) || !in_array($this->params['version'], [1, 2])) {
225 | throw new \Exception('Select version 1 or 2 this is available versions');
226 | }
227 | $version = $this->params['version'];
228 | // payment status unset this params to get correct query
229 | unset($this->params['language'], $this->params['payment_method'], $this->params['version'], $this->params['secureKey']);
230 | // standard params on live query {merchantRefNum,merchantCode,signature}
231 | return $this->response(
232 | Http::withHeaders([
233 | 'Content-Type' => 'application/json',
234 | 'Accept' => 'application/json',
235 | ])
236 | ->asJson(json_encode($this->params))
237 | ->post($this->links['STATUS_V' . $version])
238 | );
239 | }
240 |
241 | /**
242 | * refund method to refund payment
243 | * @param null
244 | * @return array
245 | */
246 | public function refund() {
247 | // payment status unset this params to get correct query
248 | unset($this->params['language'], $this->params['payment_method'], $this->params['secureKey']);
249 | return $this->response(Http::get($this->links['REFUND'],
250 | [
251 | 'query' => $this->params,
252 | ]));
253 | }
254 |
255 | /**
256 | * unPaid method to cancel order payment
257 | * @param null
258 | * @return array
259 | */
260 | public function unPaid() {
261 | // payment status unset this params to get correct query
262 | unset($this->params['language'], $this->params['payment_method'], $this->params['secureKey'], $this->params['merchantCode']);
263 | //return $this->params;
264 | return $this->response(
265 | Http::withHeaders([
266 | 'Content-Type' => 'application/json',
267 | 'Accept' => 'application/json',
268 | ])
269 | ->asJson(json_encode($this->params))
270 | ->post($this->links['CANCEL'])
271 | );
272 | }
273 |
274 | }
--------------------------------------------------------------------------------
/gateways/Payments/MyFatoorah.php:
--------------------------------------------------------------------------------
1 | config = (object) config('gateways.payments.myfatoorah');
60 |
61 | $this->locale = app()->getLocale() == 'ar' ? 'AR' : 'EN';
62 |
63 | // Set live & sandbox keys secret_key
64 | $this->params['secret_key'] = $this->config->secret_key;
65 | $this->token = $this->config->token;
66 |
67 | // set api version
68 | $this->version = 'v' . $this->config->version;
69 |
70 | //set Headers
71 | $this->headers = [
72 | 'Content-Type' => 'application/json',
73 | 'Accept' => 'application/json',
74 | 'Authorization' => 'Bearer ' . $this->token,
75 | ];
76 |
77 | // Set Language
78 | $this->params['language'] = $this->locale;
79 |
80 | // prepare links
81 | $this->link = $this->config->mode == 'live' ? $this->config->live_url ?? 'https://api.myfatoorah.com' : 'https://apitest.myfatoorah.com';
82 |
83 | // Links gateway Methods
84 | $this->links = [
85 | "INVOICE" => $this->link . "/" . $this->version . "/SendPayment",
86 | "INITIAT" => $this->link . "/" . $this->version . "/InitiatePayment",
87 | "EXECUTE" => $this->link . "/" . $this->version . "/ExecutePayment",
88 | "CANCELTOKEN" => $this->link . "/" . $this->version . "/CancelToken",
89 | "GetRECURRING" => $this->link . "/" . $this->version . "/GetRecurringPayment",
90 | "CANCELRECURRING" => $this->link . "/" . $this->version . "/CancelRecurringPayment",
91 | "PAYMENTSTATUS" => $this->link . "/" . $this->version . "/getPaymentStatus",
92 | "REFUND" => $this->link . "/" . $this->version . "/MakeRefund",
93 | "GETCOUNTRIES" => $this->link . "/" . $this->version . "/GetCountries",
94 | "GETCITIES" => $this->link . "/" . $this->version . "/Getcities",
95 | "CALCULATE" => $this->link . "/" . $this->version . "/CalculateShippingCharge",
96 | "CREATESUPPLIER" => $this->link . "/" . $this->version . "/CreateSupplier",
97 | "EDITSUPPLIER" => $this->link . "/" . $this->version . "/EditSupplier",
98 | "GETSUPPLIER" => $this->link . "/" . $this->version . "/GetSuppliers",
99 | "GETSUPPLIERDEPOSITS" => $this->link . "/" . $this->version . "/GetSupplierDeposits",
100 | "GETSUPPLIERDOCUMENTS" => $this->link . "/" . $this->version . "/GetSupplierDocuments",
101 | "GETSUPPLIERDASHBOARD" => $this->link . "/" . $this->version . "/GetSupplierDashboard",
102 | "UPLOADSUPPLIERDOCUMENT" => $this->link . "/" . $this->version . "/UploadSupplierDocument",
103 | "MAKESUPPLIERREFUND" => $this->link . "/" . $this->version . "/MakeSupplierRefund",
104 | "TRANSFERBALANCE" => $this->link . "/" . $this->version . "/TransferBalance",
105 | ];
106 |
107 | }
108 |
109 | /**
110 | * @function checkPrams to check param exists
111 | * @return Exception
112 | */
113 | protected function checkParams($params = [], $default = null) {
114 | foreach ($params as $param) {
115 | $param = strtolower($param);
116 | if (is_null($default)) {
117 | $all_keys = array_keys($this->params);
118 | $all_keys = array_map('strtolower', $all_keys);
119 |
120 | if (!in_array($param, $all_keys)) {
121 | //dd($param . !in_array($param, array_keys($this->params), false));
122 | throw new \Exception($param . ' parameter not found');
123 | }
124 | } else {
125 | $all_keys = array_keys($default);
126 | $all_keys = array_map('strtolower', $all_keys);
127 |
128 | if (!in_array($param, $all_keys, true)) {
129 | throw new \Exception($param . ' parameter not found');
130 | }
131 | }
132 | }
133 | }
134 |
135 | /**
136 | * function signature
137 | * to generate signature code for fawry
138 | * @return void
139 | */
140 | protected function signature(): void {
141 | if ($this->payment_method == 'INVOICE') {
142 | $params = ['NotificationOption', 'InvoiceValue', 'CustomerName'];
143 | } elseif ($this->payment_method == 'INVOICE_SHIPPING') {
144 | $params = ['NotificationOption', 'InvoiceValue', 'CustomerName', 'InvoiceItems', 'ShippingConsignee', 'ShippingMethod'];
145 | } elseif ($this->payment_method == 'CANCELTOKEN') {
146 | $params = ['token'];
147 | } elseif ($this->payment_method == 'RECURRING') {
148 | $params = ['InvoiceValue', 'CallBackUrl', 'ErrorUrl', 'RecurringModel'];
149 | } elseif ($this->payment_method == 'CANCELRECURRING') {
150 | $params = ['recurringId'];
151 | } else {
152 | $params = ['InvoiceValue', 'CallBackUrl', 'ErrorUrl'];
153 | }
154 |
155 | if (isset($params)) {
156 | $this->checkParams($params);
157 | }
158 | }
159 |
160 | /**
161 | * set the payment_method to binding in params
162 | * @return method chaining or Exception
163 | */
164 | public function method($method): self {
165 | if (in_array($method, $this->methods)) {
166 | $this->params['method'] = $method;
167 | $this->payment_method = $method;
168 |
169 | return $this;
170 | } else {
171 | // throw exception if not set payment method from array
172 | throw new \Exception('set payment Method ' . implode(',', $this->methods));
173 | }
174 | }
175 |
176 | /**
177 | * query method
178 | * to binding params
179 | * @return method chaining
180 | */
181 | public function query($query = []): self{
182 | $this->params = array_merge($query, $this->params);
183 | $this->signature();
184 | return $this;
185 | }
186 |
187 | /**
188 | * @param $response
189 | * @return array
190 | */
191 | public function response($response): array{
192 | return [
193 | 'status' => $response->status(),
194 | 'json' => $response->json(),
195 | 'body' => $response->body(),
196 | 'collect' => $response->collect(),
197 | 'ok' => $response->ok(),
198 | 'successful' => $response->successful(),
199 | 'failed' => $response->failed(),
200 | 'serverError' => $response->serverError(),
201 | 'clientError' => $response->clientError(),
202 | 'headers' => $response->headers(),
203 | ];
204 | }
205 |
206 | /**
207 | * auto redirect to transaction url
208 | * @return method chaining
209 | */
210 | public function redirect() {
211 | $this->params['redirect'] = true;
212 | return $this;
213 | }
214 |
215 | /**
216 | * create invoice
217 | * @param null
218 | * @return array
219 | */
220 | public function create() {
221 | if (!in_array($this->params['NotificationOption'], $this->NotificationOption)) {
222 | throw new \Exception('NotificationOption accepted ' . implode(',', $this->NotificationOption));
223 | }
224 | $this->response = $this->response(
225 | Http::withHeaders($this->headers)
226 | ->post($this->links['INVOICE'], $this->params)
227 | );
228 | if (isset($this->params['redirect']) && $this->response['status'] == '200' && $this->response['collect']['IsSuccess']) {
229 | return redirect($this->response['collect']['Data']['InvoiceURL']);
230 | } else {
231 | return $this->response;
232 | }
233 | }
234 |
235 | /**
236 | * INITIAT method to create payment link
237 | * @param null
238 | * @return array
239 | */
240 | public function init() {
241 | // check if available params
242 | $this->checkParams(['InvoiceAmount', 'CurrencyIso']);
243 |
244 | $this->response = $this->response(Http::withHeaders($this->headers)
245 | ->post($this->links['INITIAT'], $this->params));
246 | // return all methods gateways
247 | return [
248 | 'status' => $this->response['status'],
249 | 'data' => $this->response['collect'],
250 | ];
251 | }
252 |
253 | /**
254 | * execute payment
255 | * @param null
256 | * @return method chaining
257 | */
258 | public function card($query) {
259 | $this->params['card_info'] = [
260 | 'secret_key' => $this->params['secret_key'],
261 | 'language' => $this->params['language'],
262 | ];
263 |
264 | $this->params['card_info'] = array_merge($query, $this->params['card_info']);
265 |
266 | if (isset($query['token']) && !empty($query['token'])) {
267 | // check if available directPayment Params
268 | $this->checkParams(['PaymentType', 'Card'], $this->params['card_info']);
269 | // check if available params for CARD Info
270 | $this->checkParams(['SecurityCode'], $this->params['card_info']['Card']);
271 | } else {
272 | // check if available directPayment Params
273 | $this->checkParams(['PaymentType', 'Bypass3DS', 'Card'], $this->params['card_info']);
274 | // check if available params for CARD Info
275 | $this->checkParams(['Number', 'ExpiryMonth', 'ExpiryYear', 'SecurityCode', 'CardHolderName'], $this->params['card_info']['Card']);
276 | }
277 | return $this;
278 | }
279 |
280 | /**
281 | * execute payment
282 | * @param null
283 | * @return array
284 | */
285 | public function exec($id) {
286 | // binding Card Info To Push direct payment link
287 | $card_info = isset($this->params['card_info']) ? $this->params['card_info'] : null;
288 | unset($this->params['method'], $this->params['card_info']);
289 |
290 | // set paymentMethodId
291 | $this->params['paymentMethodId'] = $id;
292 | // check if available params
293 | $this->checkParams(['InvoiceAmount', 'CurrencyIso']);
294 |
295 | $this->response = $this->response(Http::withHeaders($this->headers)
296 | ->post($this->links['EXECUTE'], $this->params));
297 |
298 | // Direct Payment statement
299 | if (!empty($card_info) && $this->response['status'] == '200' && $this->response['collect']['IsSuccess']) {
300 |
301 | $directPayment = $this->response(Http::withHeaders($this->headers)
302 | ->post($this->response['collect']['Data']['PaymentURL'], $card_info));
303 | if (isset($card_info['SaveToken']) && $card_info['SaveToken'] && $directPayment['status'] == 200) {
304 | session()->put('myfatoorah_token_id', $directPayment['collect']['Data']['Token']);
305 | }
306 | // Redirect Statment of Direct Payment
307 | return isset($this->params['redirect']) && $this->params['redirect']
308 | && $directPayment['status'] == '200'
309 | && $directPayment['collect']['IsSuccess'] ?
310 | redirect($directPayment['collect']['Data']['PaymentURL'])
311 | : $directPayment;
312 |
313 | } elseif (isset($this->params['redirect']) && $this->params['redirect'] && $this->response['status'] == '200' && $this->response['collect']['IsSuccess']) {
314 | return redirect($this->response['collect']['Data']['PaymentURL']);
315 | } else {
316 | return $this->response;
317 | }
318 | }
319 |
320 | /**
321 | * execute payment
322 | * @param null
323 | * @return array
324 | */
325 | public function cancelToken() {
326 | unset($this->params['method']);
327 | return $this->response(Http::withHeaders($this->headers)
328 | ->post($this->links['CANCELTOKEN'], $this->params));
329 | }
330 |
331 | /**
332 | * Get Recurring Payment
333 | * @param null
334 | * @return array
335 | */
336 | public function getRecurringList() {
337 | $requrring = $this->response(Http::withHeaders($this->headers)
338 | ->get($this->links['GetRECURRING']));
339 | return $requrring['status'] == 200 ? $requrring['collect'] : $requrring;
340 | }
341 |
342 | /**
343 | * Cancel Recurring Payment
344 | * @param null
345 | * @return array
346 | */
347 | public function cancelRecurring() {
348 | return $this->response(Http::withHeaders($this->headers)
349 | ->post($this->links['CANCELRECURRING'], $this->params));
350 | }
351 |
352 | /**
353 | * PAYMENTSTATUS Payment
354 | * @param null
355 | * @return array
356 | */
357 | public function status($query) {
358 | $this->checkParams(['Key', 'KeyType'], $query);
359 | $this->params = array_merge($query, $this->params);
360 |
361 | $status = $this->response(Http::withHeaders($this->headers)
362 | ->post($this->links['PAYMENTSTATUS'], $this->params));
363 | return $status['status'] == 200 ? $status['collect'] : $status;
364 | }
365 |
366 | /**
367 | * refund Payment
368 | * @param null
369 | * @return array
370 | */
371 | public function refund($query) {
372 | $this->checkParams(['Key', 'KeyType', 'RefundChargeOnCustomer', 'ServiceChargeOnCustomer', 'Amount', 'Comment'], $query);
373 | $this->params = array_merge($query, $this->params);
374 |
375 | $refund = $this->response(Http::withHeaders($this->headers)
376 | ->post($this->links['REFUND'], $this->params));
377 | return $refund['status'] == 200 ? $refund['collect'] : $refund;
378 | }
379 |
380 | /**
381 | * GetCountries Payment
382 | * @param null
383 | * @return array
384 | */
385 | public function getCountries($find = null) {
386 | $this->countries = $this->response(Http::withHeaders($this->headers)
387 | ->get($this->links['GETCOUNTRIES']));
388 | if (!is_null($find) && !empty($find) && $this->countries['status'] == 200) {
389 | foreach ($this->countries['collect']['Data'] as $country) {
390 | if ($country['CountryName'] == $find) {
391 | return $country;
392 | }
393 | }
394 | return [];
395 | } else {
396 |
397 | return $this->countries['status'] == 200 ? $this->countries['collect']['Data'] : $this->countries;
398 | }
399 | }
400 |
401 | /**
402 | * GetCities Payment
403 | * @param null
404 | * @return array
405 | */
406 | public function getCities($query) {
407 | $this->checkParams(['shippingMethod', 'countryCode'], $query);
408 | $this->params = array_merge($query, $this->params);
409 | // remove parameters
410 | unset($this->params['secret_key'], $this->params['language']);
411 |
412 | $this->cities = $this->response(Http::withHeaders($this->headers)
413 | ->get($this->links['GETCITIES'], $this->params));
414 | return $this->cities['status'] == 200 ? $this->cities['collect']['Data'] : $this->cities;
415 | }
416 |
417 | /**
418 | * Calculate Shipping Charge
419 | * @param null
420 | * @return array
421 | */
422 | public function calculate($query) {
423 | // Check public Parameters
424 | $this->checkParams(['shippingMethod', 'CityName', 'CountryCode', 'PostalCode', 'Items', 'Items'], $query);
425 |
426 | // Check Items with offset 0 Items[0] Parameters
427 | $this->checkParams(['ProductName', 'Description', 'Quantity', 'UnitPrice', 'Weight', 'Width', 'Height', 'Depth'], $query['Items'][0]);
428 |
429 | $this->params = array_merge($query, $this->params);
430 | // remove parameters
431 | unset($this->params['secret_key'], $this->params['language']);
432 | $calculate = $this->response(Http::withHeaders($this->headers)
433 | ->post($this->links['CALCULATE'], $this->params));
434 | return $calculate['status'] == 200 ? $calculate['collect']['Data'] : $calculate;
435 | }
436 |
437 | /**
438 | * CreateSupplier
439 | * @param null
440 | * @return array
441 | */
442 | public function createSupplier($query) {
443 | $this->checkParams(['SupplierName', 'Mobile', 'Email'], $query);
444 | $this->params = array_merge($query, $this->params);
445 | return $this->response(Http::withHeaders($this->headers)
446 | ->post($this->links['CREATESUPPLIER'], $this->params));
447 | }
448 |
449 | /**
450 | * editSupplier
451 | * @param null
452 | * @return array
453 | */
454 | public function editSupplier($query) {
455 | $this->checkParams(['SupplierCode', 'SupplierName', 'Mobile', 'Email'], $query);
456 | $this->params = array_merge($query, $this->params);
457 | return $this->response(Http::withHeaders($this->headers)
458 | ->post($this->links['EDITSUPPLIER'], $this->params));
459 | }
460 |
461 | /**
462 | * GETSupplier
463 | * @param null
464 | * @return array
465 | */
466 | public function GetSuppliers() {
467 | $GETSUPPLIER = $this->response(Http::withHeaders($this->headers)
468 | ->get($this->links['GETSUPPLIER']));
469 | return $GETSUPPLIER['status'] == 200 ? $GETSUPPLIER['collect'] : $GETSUPPLIER;
470 | }
471 |
472 | /**
473 | * GetSupplierDeposits
474 | * @param null
475 | * @return array
476 | */
477 | public function GetSupplierDeposits($query) {
478 | $this->checkParams(['SupplierCode'], $query);
479 | $this->params = array_merge($query, $this->params);
480 |
481 | unset($this->params['secret_key'], $this->params['language']);
482 |
483 | $SupplierDeposits = $this->response(Http::withHeaders($this->headers)
484 | ->get($this->links['GETSUPPLIERDEPOSITS'], $this->params));
485 | return $SupplierDeposits['status'] == 200 ? $SupplierDeposits['collect'] : $SupplierDeposits;
486 | }
487 |
488 | /**
489 | * GetSupplierDocuments
490 | * @param null
491 | * @return array
492 | */
493 | public function GetSupplierDocuments($query) {
494 | $this->checkParams(['SupplierCode'], $query);
495 | $this->params = array_merge($query, $this->params);
496 |
497 | unset($this->params['secret_key'], $this->params['language']);
498 |
499 | $SupplierDocuments = $this->response(Http::withHeaders($this->headers)
500 | ->get($this->links['GETSUPPLIERDOCUMENTS'], $this->params));
501 | return $SupplierDocuments['status'] == 200 ? $SupplierDocuments['collect'] : $SupplierDocuments;
502 | }
503 |
504 | /**
505 | * MakeSupplierRefund
506 | * @param null
507 | * @return array
508 | */
509 | public function MakeSupplierRefund($query) {
510 | $this->checkParams(['Key', 'KeyType', 'Comment'], $query);
511 | $this->params = array_merge($query, $this->params);
512 |
513 | unset($this->params['secret_key'], $this->params['language']);
514 |
515 | $SupplierRefund = $this->response(Http::withHeaders($this->headers)
516 | ->post($this->links['MAKESUPPLIERREFUND'], $this->params));
517 | return $SupplierRefund['status'] == 200 ? $SupplierRefund['collect'] : $SupplierRefund;
518 | }
519 |
520 | /**
521 | * TransferBalance
522 | * @param null
523 | * @return array
524 | */
525 | public function TransferBalance($query) {
526 | $this->checkParams(['SupplierCode', 'TransferAmount', 'TransferType'], $query);
527 | $this->params = array_merge($query, $this->params);
528 |
529 | unset($this->params['secret_key'], $this->params['language']);
530 |
531 | $SupplierRefund = $this->response(Http::withHeaders($this->headers)
532 | ->post($this->links['TRANSFERBALANCE'], $this->params));
533 | return $SupplierRefund['status'] == 200 ? $SupplierRefund['collect'] : $SupplierRefund;
534 | }
535 |
536 | /**
537 | * GetSupplierDashboard
538 | * @param null
539 | * @return array
540 | */
541 | public function GetSupplierDashboard($query) {
542 | $this->checkParams(['SupplierCode'], $query);
543 | $this->params = array_merge($query, $this->params);
544 |
545 | unset($this->params['secret_key'], $this->params['language']);
546 |
547 | $SupplierDashboard = $this->response(Http::withHeaders($this->headers)
548 | ->get($this->links['GETSUPPLIERDASHBOARD'], $this->params));
549 | return $SupplierDashboard['status'] == 200 ? $SupplierDashboard['collect'] : $SupplierDashboard;
550 | }
551 |
552 | /**
553 | * UploadSupplierDocument
554 | * @param null
555 | * @return array
556 | */
557 | public function UploadSupplierDocument($query) {
558 | $this->checkParams(['SupplierCode', 'FileUpload', 'FileType'], $query);
559 | $file = $this->uploadFile($query['FileUpload']);
560 | $default_path = config('filesystems.disks.' . config('filesystems.default') . '.root');
561 | $file = isset($file['path']) ? $default_path . '/' . $file['path'] : '';
562 | $curl = curl_init();
563 |
564 | curl_setopt_array($curl, array(
565 | CURLOPT_URL => 'https://apitest.myfatoorah.com/v2/UploadSupplierDocument',
566 | CURLOPT_RETURNTRANSFER => true,
567 | CURLOPT_ENCODING => '',
568 | CURLOPT_MAXREDIRS => 10,
569 | CURLOPT_TIMEOUT => 0,
570 | CURLOPT_FOLLOWLOCATION => true,
571 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
572 | CURLOPT_CUSTOMREQUEST => 'PUT',
573 | CURLOPT_POSTFIELDS => array(
574 | 'FileUpload' => new
575 | \CURLFILE($file),
576 | 'SupplierCode' => $query['SupplierCode'],
577 | 'FileType' => $query['FileType'],
578 | ),
579 | CURLOPT_HTTPHEADER => array(
580 | 'Authorization: Bearer ' . $this->token,
581 | 'Cookie: ApplicationGatewayAffinity=3ef0c0508ad415fb05a4ff3f87fb97da; ApplicationGatewayAffinityCORS=3ef0c0508ad415fb05a4ff3f87fb97da',
582 | ),
583 | ));
584 |
585 | $response = curl_exec($curl);
586 | \Storage::deleteDirectory('myfatoorah_temp_file_system');
587 | curl_close($curl);
588 | if (!empty($response)) {
589 | return array_merge(['status' => 200], (array) json_decode($response));
590 | } else {
591 | return [
592 | 'status' => 400,
593 | 'message' => 'file empty or not sent',
594 | ];
595 | }
596 | }
597 |
598 | /**
599 | * upload and prepare file
600 | * @return array
601 | */
602 | protected function uploadFile($FileUpload) {
603 | if (is_string($FileUpload) && request()->hasFile($FileUpload)) {
604 | $file = request()->file($FileUpload);
605 | } elseif (!is_string($FileUpload)) {
606 | $file = $FileUpload;
607 | }
608 |
609 | if (!empty($file)) {
610 | return [
611 | 'path' => $file->store('myfatoorah_temp_file_system'),
612 | 'name' => $file->getClientOriginalName(),
613 | 'ext' => $file->extension(),
614 | 'mime' => $file->getMimeType(),
615 | ];
616 | }
617 | }
618 |
619 | }
--------------------------------------------------------------------------------