Passed
Push — master ( d44c16...e61ae6 )
by Kelvin
03:00
created

Payouts::createMobilePayoutDestination()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 3
nop 2
dl 0
loc 21
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace KiplingKelvin\ChpterLaravelSdk;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\BadResponseException;
7
8
class Payouts
9
{
10
    public $mobile_payout_destination_url;
11
    public $bank_payout_destination_url;
12
    public $mobile_payout_url;
13
    public $bank_payout_url;
14
    public $token;
15
    public $domain;
16
17
    /**
18
     * Construct method
19
     *
20
     * Initializes the class with an array of API values.
21
     *
22
     * @param array $config
23
     * @return void
24
     * @throws exception if the values array is not valid
25
     */
26
27
    public function __construct()
28
    {
29
        //Base URL for the API endpoints. This is basically the 'common' part of the API endpoints
30
         $this->mobile_payout_destination_url = config('chpter.mobile_payout_destination_url'); 	
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
         $this->mobile_payout_destination_url = /** @scrutinizer ignore-call */ config('chpter.mobile_payout_destination_url'); 	
Loading history...
31
         $this->bank_payout_destination_url = config('chpter.bank_payout_destination_url'); 
32
         $this->mobile_payout_url = config('chpter.mobile_payout_url'); 
33
         $this->bank_payout_url = config('chpter.bank_payout_url'); 
34
         $this->token = config('chpter.chpter_token'); 
35
         $this->domain =config('chpter.domain');
36
    }
37
38
    public static function createMobilePayoutDestination($type, $phone_number)
39
    {
40
        $client  = new Client();
41
42
        $requestBody = array( 
43
            "type"=> $type,
44
            "phone_number"=> $phone_number
45
        );
46
47
        try {
48
            $response = $client->post($this->mobile_payout_destination_url, [
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using $this inside a static method is generally not recommended and can lead to errors in newer PHP versions.
Loading history...
49
                "headers" => [
50
                    "Authorization" => "Token {$this->token}",
51
                    "domain"  => $this->domain,
52
                ],
53
                "json"    => $requestBody,
54
            ]);
55
56
            return json_decode((string) $response->getBody(), true);
57
        } catch (BadResponseException $exception) {
58
            return json_decode((string) $exception->getResponse()->getBody()->getContents(), true);
59
        }
60
    }
61
    public static function createBankPayoutDestination($bank_name, $bank_account_name, $bank_account_number)
62
    {
63
        $client  = new Client();
64
65
        $requestBody = array( 
66
            "bank_name"=> $bank_name,
67
            "bank_account_name"=> $bank_account_name,
68
            "bank_account_number"=> $bank_account_number,
69
        );
70
71
        try {
72
            $response = $client->post($this->bank_payout_destination_url, [
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using $this inside a static method is generally not recommended and can lead to errors in newer PHP versions.
Loading history...
73
                "headers" => [
74
                    "Authorization" => "Token {$this->token}",
75
                    "domain"  => $this->domain,
76
                ],
77
                "json"    => $requestBody,
78
            ]);
79
80
            return json_decode((string) $response->getBody(), true);
81
        } catch (BadResponseException $exception) {
82
            return json_decode((string) $exception->getResponse()->getBody()->getContents(), true);
83
        }
84
    }
85
  
86
    public static function mobilePayouts($customer, $products, $amount, $callback_details)
0 ignored issues
show
Unused Code introduced by
The parameter $callback_details is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

86
    public static function mobilePayouts($customer, $products, $amount, /** @scrutinizer ignore-unused */ $callback_details)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $products is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

86
    public static function mobilePayouts($customer, /** @scrutinizer ignore-unused */ $products, $amount, $callback_details)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $amount is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

86
    public static function mobilePayouts($customer, $products, /** @scrutinizer ignore-unused */ $amount, $callback_details)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
    {
88
        return $customer;
89
    }
90
91
    public static function domesticBanksPayouts($customer, $products, $amount, $callback_details)
0 ignored issues
show
Unused Code introduced by
The parameter $callback_details is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

91
    public static function domesticBanksPayouts($customer, $products, $amount, /** @scrutinizer ignore-unused */ $callback_details)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $amount is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

91
    public static function domesticBanksPayouts($customer, $products, /** @scrutinizer ignore-unused */ $amount, $callback_details)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $products is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

91
    public static function domesticBanksPayouts($customer, /** @scrutinizer ignore-unused */ $products, $amount, $callback_details)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
92
    {
93
        return $customer;
94
    }
95
96
  
97
}
98