Completed
Pull Request — master (#44)
by 'Tunde
10:50
created

Paystack::makePaymentRequest()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 35
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 14
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Laravel Paystack package.
5
 *
6
 * (c) Prosper Otemuyiwa <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Unicodeveloper\Paystack;
13
14
use GuzzleHttp\Client;
15
use Illuminate\Support\Facades\Config;
16
use Unicodeveloper\Paystack\Exceptions\IsNullException;
17
use Unicodeveloper\Paystack\Exceptions\PaymentVerificationFailedException;
18
19
class Paystack
20
{
21
    /**
22
     * Transaction Verification Successful
23
     */
24
    const VS = 'Verification successful';
25
26
    /**
27
     *  Invalid Transaction reference
28
     */
29
    const ITF = "Invalid transaction reference";
30
31
    /**
32
     * Instance of Client
33
     * @var Client
34
     */
35
    protected $client;
36
37
    /**
38
     *  Response from requests made to Paystack
39
     * @var mixed
40
     */
41
    protected $response;
42
43
    /**
44
     * Paystack API base Url
45
     * @var string
46
     */
47
    protected $baseUrl;
48
49
    /**
50
     * Authorization Url - Paystack payment page
51
     * @var string
52
     */
53
    protected $authorizationUrl;
54
55
    public function __construct(Client $client = null)
56
    {
57
        $this->setBaseUrl();
58
        $this->client = $client;
59
    }
60
61
    /**
62
     * Get Base Url from Paystack config file
63
     */
64
    public function setBaseUrl()
65
    {
66
        $this->baseUrl = Config::get('paystack.paymentUrl');
67
    }
68
   
69
     /**
70
     * Initiate a payment request to Paystack
71
     * Included the option to pass the payload to this method for situations 
72
     * when the payload is built on the fly (not passed to the controller from a view)
73
     * @return Paystack
74
     */
75
    public function makePaymentRequest( $data = null)
76
    {
77
        if ( $data == null ) {
78
            $data = [
79
                "amount" => intval(request()->amount),
80
                "reference" => request()->reference,
81
                "email" => request()->email,
82
                "plan" => request()->plan,
83
                "first_name" => request()->first_name,
84
                "last_name" => request()->last_name,
85
                "callback_url" => request()->callback_url,
86
                /*
87
                * to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url
88
                * form need an input field: <input type="hidden" name="metadata" value="{{ json_encode($array) }}" >
89
                *array must be set up as: $array = [ 'custom_fields' => [
90
                *                                                            ['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
91
                *                                                            ['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
92
                *                                                            .
93
                *                                                            .
94
                *                                                            .
95
                *                                                        ]
96
                *                                        
97
                *                                  ]
98
                */
99
                'metadata' => request()->metadata
100
            ];
101
102
            // Remove the fields which were not sent (value would be null)
103
            array_filter($data);
104
        }
105
106
        $this->setHttpResponse('/transaction/initialize', 'POST', $data);
107
108
        return $this;
109
    }
110
111
112
    /**
113
     * @param string $relativeUrl
114
     * @param string $method
115
     * @param array $body
116
     * @return Paystack
117
     * @throws IsNullException
118
     */
119
    private function setHttpResponse($relativeUrl, $method, $body = [])
120
    {
121
        if (is_null($method)) {
122
            throw new IsNullException("Empty method not allowed");
123
        }
124
125
        $this->response = $this->client->{strtolower($method)}(
126
            $this->baseUrl . $relativeUrl,
127
            ["body" => json_encode($body)]
128
        );
129
130
        return $this;
131
    }
132
133
    /**
134
     * Get the authorization url from the callback response
135
     * @return Paystack
136
     */
137
    public function getAuthorizationUrl()
138
    {
139
        $this->makePaymentRequest();
140
141
        $this->url = $this->getResponse()['data']['authorization_url'];
0 ignored issues
show
Bug introduced by
The property url does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
142
143
        return $this;
144
    }
145
    
146
     /**
147
     * Get the authorization callback response
148
     * In situations where Laravel serves as an backend for a detached UI, the api cannot redirect 
149
     * and might need to take different actions based on the success (or not) of the transaction
150
     * @return array
151
     */
152
    public function getAuthorizationResponse($data = null)
153
    {
154
        $this->makePaymentRequest($data);
155
156
        $this->url = $this->getResponse()['data']['authorization_url'];
157
158
        return $this->getResponse();
159
    }
160
161
    /**
162
     * Hit Paystack Gateway to Verify that the transaction is valid
163
     */
164
    private function verifyTransactionAtGateway()
165
    {
166
        $transactionRef = request()->query('trxref');
167
168
        $relativeUrl = "/transaction/verify/{$transactionRef}";
169
170
        $this->response = $this->client->get($this->baseUrl . $relativeUrl, []);
171
    }
172
173
    /**
174
     * True or false condition whether the transaction is verified
175
     * @return boolean
176
     */
177
    public function isTransactionVerificationValid()
178
    {
179
        $this->verifyTransactionAtGateway();
180
181
        $result = $this->getResponse()['message'];
182
183
        switch ($result) {
184
            case self::VS:
185
                $validate = true;
186
                break;
187
            case self::ITF:
188
                $validate = false;
189
                break;
190
            default:
191
                $validate = false;
192
                break;
193
        }
194
195
        return $validate;
196
    }
197
198
    /**
199
     * Get Payment details if the transaction was verified successfully
200
     * @return json
201
     * @throws PaymentVerificationFailedException
202
     */
203
    public function getPaymentData()
204
    {
205
        if ($this->isTransactionVerificationValid()) {
206
            return $this->getResponse();
207
        } else {
208
            throw new PaymentVerificationFailedException("Invalid Transaction Reference");
209
        }
210
    }
211
212
    /**
213
     * Fluent method to redirect to Paystack Payment Page
214
     */
215
    public function redirectNow()
216
    {
217
        return redirect($this->url);
218
    }
219
220
    /**
221
     * Get Access code from transaction callback respose
222
     * @return string
223
     */
224
    public function getAccessCode()
225
    {
226
        return $this->getResponse()['data']['access_code'];
227
    }
228
229
    /**
230
     * Generate a Unique Transaction Reference
231
     * @return string
232
     */
233
    public function genTranxRef()
234
    {
235
        return TransRef::getHashedToken();
236
    }
237
238
    /**
239
     * Get all the customers that have made transactions on your platform
240
     * @return array
241
     */
242
    public function getAllCustomers()
243
    {
244
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
245
246
        return $this->setHttpResponse("/customer", 'GET', [])->getData();
247
    }
248
249
    /**
250
     * Get all the plans that you have on Paystack
251
     * @return array
252
     */
253
    public function getAllPlans()
254
    {
255
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
256
257
        return $this->setHttpResponse("/plan", 'GET', [])->getData();
258
    }
259
260
    /**
261
     * Get all the transactions that have happened overtime
262
     * @return array
263
     */
264
    public function getAllTransactions()
265
    {
266
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
267
268
        return $this->setHttpResponse("/transaction", 'GET', [])->getData();
269
    }
270
271
    /**
272
     * Get the whole response from a get operation
273
     * @return array
274
     */
275
    private function getResponse()
276
    {
277
        return json_decode($this->response->getBody(), true);
278
    }
279
280
    /**
281
     * Get the data response from a get operation
282
     * @return array
283
     */
284
    private function getData()
285
    {
286
        return $this->getResponse()['data'];
287
    }
288
289
    /**
290
     * Create a plan
291
     */
292 View Code Duplication
    public function createPlan()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
293
    {
294
        $data = [
295
            "name" => request()->name,
296
            "description" => request()->desc,
297
            "amount" => intval(request()->amount),
298
            "interval" => request()->interval,
299
            "send_invoices" => request()->send_invoices,
300
            "send_sms" => request()->send_sms,
301
            "currency" => request()->currency,
302
        ];
303
304
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
305
306
        $this->setHttpResponse("/plan", 'POST', $data);
307
308
    }
309
310
    /**
311
     * Fetch any plan based on its plan id or code
312
     * @param $plan_code
313
     * @return array
314
     */
315
    public function fetchPlan($plan_code)
316
    {
317
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
318
        return $this->setHttpResponse('/plan/' . $plan_code, 'GET', [])->getResponse();
319
    }
320
321
    /**
322
     * Update any plan's details based on its id or code
323
     * @param $plan_code
324
     * @return array
325
     */
326 View Code Duplication
    public function updatePlan($plan_code)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
327
    {
328
        $data = [
329
            "name" => request()->name,
330
            "description" => request()->desc,
331
            "amount" => intval(request()->amount),
332
            "interval" => request()->interval,
333
            "send_invoices" => request()->send_invoices,
334
            "send_sms" => request()->send_sms,
335
            "currency" => request()->currency,
336
        ];
337
338
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
339
        return $this->setHttpResponse('/plan/' . $plan_code, 'PUT', $data)->getResponse();
340
    }
341
342
    /**
343
     * Create a customer
344
     */
345 View Code Duplication
    public function createCustomer()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
346
    {
347
        $data = [
348
            "email" => request()->email,
349
            "first_name" => request()->fname,
350
            "last_name" => request()->lname,
351
            "phone" => request()->phone,
352
            "metadata" => request()->additional_info /* key => value pairs array */
353
354
        ];
355
356
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
357
        return $this->setHttpResponse('/customer', 'POST', $data)->getResponse();
358
    }
359
360
    /**
361
     * Fetch a customer based on id or code
362
     * @param $customer_id
363
     * @return array
364
     */
365
    public function fetchCustomer($customer_id)
366
    {
367
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
368
        return $this->setHttpResponse('/customer/'. $customer_id, 'GET', [])->getResponse();
369
    }
370
371
    /**
372
     * Update a customer's details based on their id or code
373
     * @param $customer_id
374
     * @return array
375
     */
376 View Code Duplication
    public function updateCustomer($customer_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
377
    {
378
        $data = [
379
            "email" => request()->email,
380
            "first_name" => request()->fname,
381
            "last_name" => request()->lname,
382
            "phone" => request()->phone,
383
            "metadata" => request()->additional_info /* key => value pairs array */
384
385
        ];
386
387
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
388
        return $this->setHttpResponse('/customer/'. $customer_id, 'PUT', $data)->getResponse();
389
    }
390
391
    /**
392
     * Export transactions in .CSV
393
     * @return array
394
     */
395
    public function exportTransactions()
396
    {
397
        $data = [
398
            "from" => request()->from,
399
            "to" => request()->to,
400
            'settled' => request()->settled
401
        ];
402
403
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
404
        return $this->setHttpResponse('/transaction/export', 'GET', $data)->getResponse();
405
    }
406
407
    /**
408
     * Create a subscription to a plan from a customer.
409
     */
410 View Code Duplication
    public function createSubscription()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
411
    {
412
        $data = [
413
            "customer" => request()->customer, //Customer email or code
414
            "plan" => request()->plan,
415
            "authorization" => request()->authorization_code
416
        ];
417
418
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
419
        $this->setHttpResponse('/subscription', 'POST', $data);
420
    }
421
422
    /**
423
     * Get all the subscriptions made on Paystack.
424
     *
425
     * @return array
426
     */
427
    public function getAllSubscriptions()
428
    {
429
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
430
431
        return $this->setHttpResponse("/subscription", 'GET', [])->getData();
432
    }
433
434
    /**
435
     * Get customer subscriptions
436
     *
437
     * @param integer $customer_id
438
     * @return array
439
     */
440
    public function getCustomerSubscriptions($customer_id)
441
    {
442
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
443
444
        return $this->setHttpResponse('/subscription?customer=' . $customer_id, 'GET', [])->getData();
445
    }
446
447
    /**
448
     * Get plan subscriptions
449
     *
450
     * @param  integer $plan_id
451
     * @return array
452
     */
453
    public function getPlanSubscriptions($plan_id)
454
    {
455
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
456
457
        return $this->setHttpResponse('/subscription?plan=' . $plan_id, 'GET', [])->getData();
458
    }
459
460
    /**
461
     * Enable a subscription using the subscription code and token
462
     * @return array
463
     */
464 View Code Duplication
    public function enableSubscription()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
465
    {
466
        $data = [
467
            "code" => request()->code,
468
            "token" => request()->token,
469
        ];
470
471
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
472
        return $this->setHttpResponse('/subscription/enable', 'POST', $data)->getResponse();
473
    }
474
475
    /**
476
     * Disable a subscription using the subscription code and token
477
     * @return array
478
     */
479 View Code Duplication
    public function disableSubscription()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
480
    {
481
        $data = [
482
            "code" => request()->code,
483
            "token" => request()->token,
484
        ];
485
486
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
487
        return $this->setHttpResponse('/subscription/disable', 'POST', $data)->getResponse();
488
    }
489
490
    /**
491
     * Fetch details about a certain subscription
492
     * @param mixed $subscription_id
493
     * @return array
494
     */
495
    public function fetchSubscription($subscription_id)
496
    {
497
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
498
        return $this->setHttpResponse('/subscription/'.$subscription_id, 'GET', [])->getResponse();
499
    }
500
501
    /**
502
     * Create pages you can share with users using the returned slug
503
     */
504 View Code Duplication
    public function createPage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
505
    {
506
        $data = [
507
            "name" => request()->name,
508
            "description" => request()->description,
509
            "amount" => request()->amount
510
        ];
511
512
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
513
        $this->setHttpResponse('/page', 'POST', $data);
514
    }
515
516
    /**
517
     * Fetches all the pages the merchant has
518
     * @return array
519
     */
520
    public function getAllPages()
521
    {
522
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
523
        return $this->setHttpResponse('/page', 'GET', [])->getResponse();
524
    }
525
526
    /**
527
     * Fetch details about a certain page using its id or slug
528
     * @param mixed $page_id
529
     * @return array
530
     */
531
    public function fetchPage($page_id)
532
    {
533
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
534
        return $this->setHttpResponse('/page/'.$page_id, 'GET', [])->getResponse();
535
    }
536
537
    /**
538
     * Update the details about a particular page
539
     * @param $page_id
540
     * @return array
541
     */
542 View Code Duplication
    public function updatePage($page_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
543
    {
544
        $data = [
545
            "name" => request()->name,
546
            "description" => request()->description,
547
            "amount" => request()->amount
548
        ];
549
550
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
551
        return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse();
552
    }
553
554
     /**
555
     * Creates a subaccount to be used for split payments . Required    params are business_name , settlement_bank , account_number ,   percentage_charge
556
     * 
557
     * @return array
558
     */
559
    
560 View Code Duplication
    public function createSubAccount(){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
561
        $data = [
562
            "business_name" => request()->business_name, 
563
            "settlement_bank" => request()->settlement_bank,
564
            "account_number" => request()->account_number,
565
            "percentage_charge" => request()->percentage_charge,
566
            "primary_contact_email" => request()->primary_contact_email,
567
            "primary_contact_name" => request()->primary_contact_name,
568
            "primary_contact_phone" => request()->primary_contact_phone,
569
            "metadata" => request()->metadata,
570
            'settlement_schedule' => request()->settlement_schedule
571
        ];
572
573
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
574
        return $this->setHttpResponse('/subaccount', 'POST', array_filter($data))->getResponse();
575
576
    }
577
578
     /**
579
     * Fetches details of a subaccount
580
     * @param subaccount code
581
     * @return array
582
     */
583
    public function fetchSubAccount($subaccount_code){
584
585
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
586
        return $this->setHttpResponse("/subaccount/{$subaccount_code}","GET",[])->getResponse();
587
588
    }
589
590
     /**
591
     * Lists all the subaccounts associated with the account
592
     * @param $per_page - Specifies how many records to retrieve per page , $page - SPecifies exactly what page to retrieve
593
     * @return array
594
     */
595
    public function listSubAccounts($per_page,$page){
596
597
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
598
        return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse();
599
600
    }
601
602
603
    /**
604
     * Updates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge
605
     * @param subaccount code 
606
     * @return array
607
     */
608
    
609 View Code Duplication
    public function updateSubAccount($subaccount_code){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
610
        $data = [
611
            "business_name" => request()->business_name, 
612
            "settlement_bank" => request()->settlement_bank,
613
            "account_number" => request()->account_number,
614
            "percentage_charge" => request()->percentage_charge,
615
            "description" => request()->description,
616
            "primary_contact_email" => request()->primary_contact_email,
617
            "primary_contact_name" => request()->primary_contact_name,
618
            "primary_contact_phone" => request()->primary_contact_phone,
619
            "metadata" => request()->metadata,
620
            'settlement_schedule' => request()->settlement_schedule
621
        ];
622
623
        $this->setRequestOptions();
0 ignored issues
show
Bug introduced by
The method setRequestOptions() does not seem to exist on object<Unicodeveloper\Paystack\Paystack>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
624
        return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse();
625
626
    }
627
}
628