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'); |
|
|
|
|
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, [ |
|
|
|
|
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, [ |
|
|
|
|
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) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
return $customer; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public static function domesticBanksPayouts($customer, $products, $amount, $callback_details) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
return $customer; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|