Completed
Pull Request — master (#47)
by
unknown
09:13
created

Paystack   C

Complexity

Total Complexity 54

Size/Duplication

Total Lines 664
Duplicated Lines 26.66 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 54
lcom 1
cbo 5
dl 177
loc 664
rs 6.0099
c 0
b 0
f 0

41 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setBaseUrl() 0 4 1
A setKey() 0 4 1
A setRequestOptions() 0 15 1
B makePaymentRequest() 0 35 2
A setHttpResponse() 0 13 2
A getAuthorizationUrl() 0 8 1
A getAuthorizationResponse() 0 8 1
A verifyTransactionAtGateway() 0 8 1
A isTransactionVerificationValid() 0 20 3
A getPaymentData() 0 8 2
A redirectNow() 0 4 1
A getAccessCode() 0 4 1
A genTranxRef() 0 4 1
A getAllCustomers() 0 6 1
A getAllPlans() 0 6 1
A getAllTransactions() 0 6 1
A getResponse() 0 4 1
A getData() 0 4 1
A createPlan() 19 19 2
A fetchPlan() 0 5 1
A updatePlan() 17 17 2
A createCustomer() 15 15 2
A fetchCustomer() 0 5 1
A updateCustomer() 16 16 2
A exportTransactions() 13 13 2
A createSubscription() 11 11 1
A getAllSubscriptions() 0 6 1
A getCustomerSubscriptions() 0 6 1
A getPlanSubscriptions() 0 6 1
A enableSubscription() 12 12 2
A disableSubscription() 10 10 1
A fetchSubscription() 0 5 1
A createPage() 11 11 1
A getAllPages() 0 5 1
A fetchPage() 0 5 1
A updatePage() 11 11 1
A createSubAccount() 21 21 2
A fetchSubAccount() 0 6 1
A listSubAccounts() 0 6 1
A updateSubAccount() 21 21 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Paystack often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Paystack, and based on these observations, apply Extract Interface, too.

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
     * Issue Secret Key from your Paystack Dashboard
33
     * @var string
34
     */
35
    protected $secretKey;
36
37
    /**
38
     * Instance of Client
39
     * @var Client
40
     */
41
    protected $client;
42
43
    /**
44
     *  Response from requests made to Paystack
45
     * @var mixed
46
     */
47
    protected $response;
48
49
    /**
50
     * Paystack API base Url
51
     * @var string
52
     */
53
    protected $baseUrl;
54
55
    /**
56
     * Authorization Url - Paystack payment page
57
     * @var string
58
     */
59
    protected $authorizationUrl;
60
61
    public function __construct()
62
    {
63
        $this->setKey();
64
        $this->setBaseUrl();
65
        $this->setRequestOptions();
66
    }
67
68
    /**
69
     * Get Base Url from Paystack config file
70
     */
71
    public function setBaseUrl()
72
    {
73
        $this->baseUrl = Config::get('paystack.paymentUrl');
74
    }
75
76
    /**
77
     * Get secret key from Paystack config file
78
     */
79
    public function setKey()
80
    {
81
        $this->secretKey = Config::get('paystack.secretKey');
82
    }
83
84
    /**
85
     * Set options for making the Client request
86
     */
87
    private function setRequestOptions()
88
    {
89
        $authBearer = 'Bearer '. $this->secretKey;
90
91
        $this->client = new Client(
92
            [
93
                'base_uri' => $this->baseUrl,
94
                'headers' => [
95
                    'Authorization' => $authBearer,
96
                    'Content-Type'  => 'application/json',
97
                    'Accept'        => 'application/json'
98
                ]
99
            ]
100
        );
101
    }
102
103
104
     /**
105
106
     * Initiate a payment request to Paystack
107
     * Included the option to pass the payload to this method for situations
108
     * when the payload is built on the fly (not passed to the controller from a view)
109
     * @return Paystack
110
     */
111
112
    public function makePaymentRequest( $data = null )
113
    {
114
        if ( $data == null ) {
115
            $data = [
116
                "amount" => intval(request()->amount),
117
                "reference" => request()->reference,
118
                "email" => request()->email,
119
                "plan" => request()->plan,
120
                "first_name" => request()->first_name,
121
                "last_name" => request()->last_name,
122
                "callback_url" => request()->callback_url,
123
                /*
124
                * to allow use of metadata on Paystack dashboard and a means to return additional data back to redirect url
125
                * form need an input field: <input type="hidden" name="metadata" value="{{ json_encode($array) }}" >
126
                *array must be set up as: $array = [ 'custom_fields' => [
127
                *                                                            ['display_name' => "Cart Id", "variable_name" => "cart_id", "value" => "2"],
128
                *                                                            ['display_name' => "Sex", "variable_name" => "sex", "value" => "female"],
129
                *                                                            .
130
                *                                                            .
131
                *                                                            .
132
                *                                                        ]
133
                *
134
                *                                  ]
135
                */
136
                'metadata' => request()->metadata
137
            ];
138
139
            // Remove the fields which were not sent (value would be null)
140
            array_filter($data);
141
        }
142
143
        $this->setHttpResponse('/transaction/initialize', 'POST', $data);
144
145
        return $this;
146
    }
147
148
149
    /**
150
     * @param string $relativeUrl
151
     * @param string $method
152
     * @param array $body
153
     * @return Paystack
154
     * @throws IsNullException
155
     */
156
    private function setHttpResponse($relativeUrl, $method, $body = [])
157
    {
158
        if (is_null($method)) {
159
            throw new IsNullException("Empty method not allowed");
160
        }
161
162
        $this->response = $this->client->{strtolower($method)}(
163
            $this->baseUrl . $relativeUrl,
164
            ["body" => json_encode($body)]
165
        );
166
167
        return $this;
168
    }
169
170
    /**
171
     * Get the authorization url from the callback response
172
     * @return Paystack
173
     */
174
    public function getAuthorizationUrl()
175
    {
176
        $this->makePaymentRequest();
177
178
        $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...
179
180
        return $this;
181
    }
182
183
     /**
184
     * Get the authorization callback response
185
     * In situations where Laravel serves as an backend for a detached UI, the api cannot redirect
186
     * and might need to take different actions based on the success or not of the transaction
187
     * @return array
188
     */
189
    public function getAuthorizationResponse($data)
190
    {
191
        $this->makePaymentRequest($data);
192
193
        $this->url = $this->getResponse()['data']['authorization_url'];
194
195
        return $this->getResponse();
196
    }
197
198
    /**
199
     * Hit Paystack Gateway to Verify that the transaction is valid
200
     */
201
    private function verifyTransactionAtGateway()
202
    {
203
        $transactionRef = request()->query('trxref');
204
205
        $relativeUrl = "/transaction/verify/{$transactionRef}";
206
207
        $this->response = $this->client->get($this->baseUrl . $relativeUrl, []);
208
    }
209
210
    /**
211
     * True or false condition whether the transaction is verified
212
     * @return boolean
213
     */
214
    public function isTransactionVerificationValid()
215
    {
216
        $this->verifyTransactionAtGateway();
217
218
        $result = $this->getResponse()['message'];
219
220
        switch ($result) {
221
            case self::VS:
222
                $validate = true;
223
                break;
224
            case self::ITF:
225
                $validate = false;
226
                break;
227
            default:
228
                $validate = false;
229
                break;
230
        }
231
232
        return $validate;
233
    }
234
235
    /**
236
     * Get Payment details if the transaction was verified successfully
237
     * @return json
238
     * @throws PaymentVerificationFailedException
239
     */
240
    public function getPaymentData()
241
    {
242
        if ($this->isTransactionVerificationValid()) {
243
            return $this->getResponse();
244
        } else {
245
            throw new PaymentVerificationFailedException("Invalid Transaction Reference");
246
        }
247
    }
248
249
    /**
250
     * Fluent method to redirect to Paystack Payment Page
251
     */
252
    public function redirectNow()
253
    {
254
        return redirect($this->url);
255
    }
256
257
    /**
258
     * Get Access code from transaction callback respose
259
     * @return string
260
     */
261
    public function getAccessCode()
262
    {
263
        return $this->getResponse()['data']['access_code'];
264
    }
265
266
    /**
267
     * Generate a Unique Transaction Reference
268
     * @return string
269
     */
270
    public function genTranxRef()
271
    {
272
        return TransRef::getHashedToken();
273
    }
274
275
    /**
276
     * Get all the customers that have made transactions on your platform
277
     * @return array
278
     */
279
    public function getAllCustomers()
280
    {
281
        $this->setRequestOptions();
282
283
        return $this->setHttpResponse("/customer", 'GET', [])->getData();
284
    }
285
286
    /**
287
     * Get all the plans that you have on Paystack
288
     * @return array
289
     */
290
    public function getAllPlans()
291
    {
292
        $this->setRequestOptions();
293
294
        return $this->setHttpResponse("/plan", 'GET', [])->getData();
295
    }
296
297
    /**
298
     * Get all the transactions that have happened overtime
299
     * @return array
300
     */
301
    public function getAllTransactions()
302
    {
303
        $this->setRequestOptions();
304
305
        return $this->setHttpResponse("/transaction", 'GET', [])->getData();
306
    }
307
308
    /**
309
     * Get the whole response from a get operation
310
     * @return array
311
     */
312
    private function getResponse()
313
    {
314
        return json_decode($this->response->getBody(), true);
315
    }
316
317
    /**
318
     * Get the data response from a get operation
319
     * @return array
320
     */
321
    private function getData()
322
    {
323
        return $this->getResponse()['data'];
324
    }
325
326
    /**
327
     * Create a plan
328
     */
329 View Code Duplication
    public function createPlan( $data = null )
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...
330
    {
331
        if ($data == null) {
332
          $data = [
333
              "name" => request()->name,
334
              "description" => request()->desc,
335
              "amount" => intval(request()->amount),
336
              "interval" => request()->interval,
337
              "send_invoices" => request()->send_invoices,
338
              "send_sms" => request()->send_sms,
339
              "currency" => request()->currency,
340
          ];
341
       }
342
343
        $this->setRequestOptions();
344
345
        $this->setHttpResponse("/plan", 'POST', $data);
346
347
    }
348
349
    /**
350
     * Fetch any plan based on its plan id or code
351
     * @param $plan_code
352
     * @return array
353
     */
354
    public function fetchPlan($plan_code)
355
    {
356
        $this->setRequestOptions();
357
        return $this->setHttpResponse('/plan/' . $plan_code, 'GET', [])->getResponse();
358
    }
359
360
    /**
361
     * Update any plan's details based on its id or code
362
     * @param $plan_code
363
     * @return array
364
     */
365 View Code Duplication
    public function updatePlan($plan_code, $data = null)
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...
366
    {
367
        if ($data == null) {
368
          $data = [
369
              "name" => request()->name,
370
              "description" => request()->desc,
371
              "amount" => intval(request()->amount),
372
              "interval" => request()->interval,
373
              "send_invoices" => request()->send_invoices,
374
              "send_sms" => request()->send_sms,
375
              "currency" => request()->currency,
376
          ];
377
        }
378
379
        $this->setRequestOptions();
380
        return $this->setHttpResponse('/plan/' . $plan_code, 'PUT', $data)->getResponse();
381
    }
382
383
    /**
384
     * Create a customer
385
     */
386 View Code Duplication
    public function createCustomer( $data = null )
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...
387
    {
388
        if ($data == null){
389
          $data = [
390
              "email" => request()->email,
391
              "first_name" => request()->fname,
392
              "last_name" => request()->lname,
393
              "phone" => request()->phone,
394
              "metadata" => request()->additional_info /* key => value pairs array */
395
396
          ];
397
        }
398
        $this->setRequestOptions();
399
        return $this->setHttpResponse('/customer', 'POST', $data)->getResponse();
400
    }
401
402
    /**
403
     * Fetch a customer based on id or code
404
     * @param $customer_id
405
     * @return array
406
     */
407
    public function fetchCustomer($customer_id)
408
    {
409
        $this->setRequestOptions();
410
        return $this->setHttpResponse('/customer/'. $customer_id, 'GET', [])->getResponse();
411
    }
412
413
    /**
414
     * Update a customer's details based on their id or code
415
     * @param $customer_id
416
     * @return array
417
     */
418 View Code Duplication
    public function updateCustomer($customer_id, $data = null)
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...
419
    {
420
        if ($data == null) {
421
          $data = [
422
              "email" => request()->email,
423
              "first_name" => request()->fname,
424
              "last_name" => request()->lname,
425
              "phone" => request()->phone,
426
              "metadata" => request()->additional_info /* key => value pairs array */
427
428
          ];
429
        }
430
431
        $this->setRequestOptions();
432
        return $this->setHttpResponse('/customer/'. $customer_id, 'PUT', $data)->getResponse();
433
    }
434
435
    /**
436
     * Export transactions in .CSV
437
     * @return array
438
     */
439 View Code Duplication
    public function exportTransactions( $data = null )
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...
440
    {
441
        if ($data == null) {
442
          $data = [
443
              "from" => request()->from,
444
              "to" => request()->to,
445
              'settled' => request()->settled
446
          ];
447
        }
448
449
        $this->setRequestOptions();
450
        return $this->setHttpResponse('/transaction/export', 'GET', $data)->getResponse();
451
    }
452
453
    /**
454
     * Create a subscription to a plan from a customer.
455
     */
456 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...
457
    {
458
        $data = [
459
            "customer" => request()->customer, //Customer email or code
460
            "plan" => request()->plan,
461
            "authorization" => request()->authorization_code
462
        ];
463
464
        $this->setRequestOptions();
465
        $this->setHttpResponse('/subscription', 'POST', $data);
466
    }
467
468
    /**
469
     * Get all the subscriptions made on Paystack.
470
     *
471
     * @return array
472
     */
473
    public function getAllSubscriptions()
474
    {
475
        $this->setRequestOptions();
476
477
        return $this->setHttpResponse("/subscription", 'GET', [])->getData();
478
    }
479
480
    /**
481
     * Get customer subscriptions
482
     *
483
     * @param integer $customer_id
484
     * @return array
485
     */
486
    public function getCustomerSubscriptions($customer_id)
487
    {
488
        $this->setRequestOptions();
489
490
        return $this->setHttpResponse('/subscription?customer=' . $customer_id, 'GET', [])->getData();
491
    }
492
493
    /**
494
     * Get plan subscriptions
495
     *
496
     * @param  integer $plan_id
497
     * @return array
498
     */
499
    public function getPlanSubscriptions($plan_id)
500
    {
501
        $this->setRequestOptions();
502
503
        return $this->setHttpResponse('/subscription?plan=' . $plan_id, 'GET', [])->getData();
504
    }
505
506
    /**
507
     * Enable a subscription using the subscription code and token
508
     * @return array
509
     */
510 View Code Duplication
    public function enableSubscription( $data = null )
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...
511
    {
512
        if ($data == null) {
513
          $data = [
514
              "code" => request()->code,
515
              "token" => request()->token,
516
          ];
517
        }
518
519
        $this->setRequestOptions();
520
        return $this->setHttpResponse('/subscription/enable', 'POST', $data)->getResponse();
521
    }
522
523
    /**
524
     * Disable a subscription using the subscription code and token
525
     * @return array
526
     */
527 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...
528
    {
529
        $data = [
530
            "code" => request()->code,
531
            "token" => request()->token,
532
        ];
533
534
        $this->setRequestOptions();
535
        return $this->setHttpResponse('/subscription/disable', 'POST', $data)->getResponse();
536
    }
537
538
    /**
539
     * Fetch details about a certain subscription
540
     * @param mixed $subscription_id
541
     * @return array
542
     */
543
    public function fetchSubscription($subscription_id)
544
    {
545
        $this->setRequestOptions();
546
        return $this->setHttpResponse('/subscription/'.$subscription_id, 'GET', [])->getResponse();
547
    }
548
549
    /**
550
     * Create pages you can share with users using the returned slug
551
     */
552 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...
553
    {
554
        $data = [
555
            "name" => request()->name,
556
            "description" => request()->description,
557
            "amount" => request()->amount
558
        ];
559
560
        $this->setRequestOptions();
561
        $this->setHttpResponse('/page', 'POST', $data);
562
    }
563
564
    /**
565
     * Fetches all the pages the merchant has
566
     * @return array
567
     */
568
    public function getAllPages()
569
    {
570
        $this->setRequestOptions();
571
        return $this->setHttpResponse('/page', 'GET', [])->getResponse();
572
    }
573
574
    /**
575
     * Fetch details about a certain page using its id or slug
576
     * @param mixed $page_id
577
     * @return array
578
     */
579
    public function fetchPage($page_id)
580
    {
581
        $this->setRequestOptions();
582
        return $this->setHttpResponse('/page/'.$page_id, 'GET', [])->getResponse();
583
    }
584
585
    /**
586
     * Update the details about a particular page
587
     * @param $page_id
588
     * @return array
589
     */
590 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...
591
    {
592
        $data = [
593
            "name" => request()->name,
594
            "description" => request()->description,
595
            "amount" => request()->amount
596
        ];
597
598
        $this->setRequestOptions();
599
        return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse();
600
    }
601
602
     /**
603
     * Creates a subaccount to be used for split payments . Required    params are business_name , settlement_bank , account_number ,   percentage_charge
604
     *
605
     * @return array
606
     */
607
608 View Code Duplication
    public function createSubAccount( $data = null ){
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...
609
610
        if ($data == null) {
611
          $data = [
612
              "business_name" => request()->business_name,
613
              "settlement_bank" => request()->settlement_bank,
614
              "account_number" => request()->account_number,
615
              "percentage_charge" => request()->percentage_charge,
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
          $data = array_filter($data);
623
       }
624
625
        $this->setRequestOptions();
626
        return $this->setHttpResponse('/subaccount', 'POST', $data)->getResponse();
627
628
    }
629
630
     /**
631
     * Fetches details of a subaccount
632
     * @param subaccount code
633
     * @return array
634
     */
635
    public function fetchSubAccount($subaccount_code){
636
637
        $this->setRequestOptions();
638
        return $this->setHttpResponse("/subaccount/{$subaccount_code}","GET",[])->getResponse();
639
640
    }
641
642
     /**
643
     * Lists all the subaccounts associated with the account
644
     * @param $per_page - Specifies how many records to retrieve per page , $page - SPecifies exactly what page to retrieve
645
     * @return array
646
     */
647
    public function listSubAccounts($per_page,$page){
648
649
        $this->setRequestOptions();
650
        return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse();
651
652
    }
653
654
655
    /**
656
     * Updates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge
657
     * @param subaccount code
658
     * @return array
659
     */
660
661 View Code Duplication
    public function updateSubAccount($subaccount_code, $data = null){
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...
662
        if ($data == null) {
663
          $data = [
664
              "business_name" => request()->business_name,
665
              "settlement_bank" => request()->settlement_bank,
666
              "account_number" => request()->account_number,
667
              "percentage_charge" => request()->percentage_charge,
668
              "description" => request()->description,
669
              "primary_contact_email" => request()->primary_contact_email,
670
              "primary_contact_name" => request()->primary_contact_name,
671
              "primary_contact_phone" => request()->primary_contact_phone,
672
              "metadata" => request()->metadata,
673
              'settlement_schedule' => request()->settlement_schedule
674
          ];
675
          $data = array_filter($data);
676
        }
677
678
        $this->setRequestOptions();
679
        return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", $data)->getResponse();
680
681
    }
682
}
683