Skip to content

Commit fa04d6f

Browse files
Merge pull request #9 from IntaSend/dev
Improved wallet funding
2 parents 3545c06 + e05d842 commit fa04d6f

5 files changed

Lines changed: 30 additions & 21 deletions

File tree

src/Checkout.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function init($credentials)
1414
$this->credentials = $credentials;
1515
}
1616

17-
public function create($amount, $currency, Customer $customer, $host, ?string $redirect_url, ?string $api_ref, ?string $comment, ?string $method, $card_tarrif = "BUSINESS-PAYS", $mobile_tarrif = "BUSINESS-PAYS")
17+
public function create($amount, $currency, Customer $customer, $host, ?string $redirect_url, ?string $api_ref, ?string $comment, ?string $method, $card_tarrif = "BUSINESS-PAYS", $mobile_tarrif = "BUSINESS-PAYS", $wallet_id=null)
1818
{
1919
$payload = [
2020
"public_key" => $this->credentials['publishable_key'],
@@ -35,10 +35,11 @@ public function create($amount, $currency, Customer $customer, $host, ?string $r
3535
"comment" => $comment,
3636
"card_tarrif" => $card_tarrif,
3737
"mobile_tarrif" => $mobile_tarrif,
38-
"host" => $host
38+
"host" => $host,
39+
"wallet_id"=> $wallet_id
3940
];
4041
$payload = json_encode($payload);
41-
return $this->send_request('POST', '/checkout/', $payload);
42+
return $this->send_request($method='POST', $url='/checkout/', $payload=$payload, $auth=false);
4243
}
4344

4445
public function check_status($signature, $checkout_id, $invoice_id)

src/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function init($credentials)
1212
$this->credentials=$credentials;
1313
}
1414

15-
public function create($amount, $phone_number, $currency="KES", $method="MPESA_STK_PUSH", $api_ref="API Request", $name=null, $email=null)
15+
public function create($amount, $phone_number, $currency="KES", $method="MPESA_STK_PUSH", $api_ref="API Request", $email=null, $wallet_id=null)
1616
{
1717
if ($method == 'MPESA_STK_PUSH') {
1818
$payload=[
@@ -21,9 +21,9 @@ public function create($amount, $phone_number, $currency="KES", $method="MPESA_S
2121
'method'=> $method,
2222
'amount'=> $amount,
2323
'api_ref'=> $api_ref,
24-
'name'=> $name,
2524
'phone_number'=> $phone_number,
2625
'email'=> $email,
26+
'wallet_id'=>$wallet_id
2727
];
2828
$payload=json_encode($payload);
2929
return $this->send_request('POST','/payment/mpesa-stk-push/',$payload);
@@ -34,8 +34,8 @@ public function create($amount, $phone_number, $currency="KES", $method="MPESA_S
3434
/**
3535
* Shortcut method to send MPesa STK Push request
3636
*/
37-
public function mpesa_stk_push($amount, $phone_number, $api_ref="API Request", $name=null, $email=null) {
38-
return $this->create($amount, $phone_number, "KES", "MPESA_STK_PUSH", $api_ref, $name, $email);
37+
public function mpesa_stk_push($amount, $phone_number, $api_ref="API Request", $email=null) {
38+
return $this->create($amount, $phone_number, "KES", "MPESA_STK_PUSH", $api_ref, $email);
3939
}
4040

4141
public function status($invoice_id)

src/Traits/BaseAPITrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ private function get_env_call($payload) {
5454
throw new \Exception('Invalid tokens provided. We could not identify the target enviroment for this request');
5555
}
5656

57-
private function send_request($method, $url, $payload = null)
57+
private function send_request($method, $url, $payload = null, $auth= true)
5858
{
5959
$headers = [
6060
'Content-Type' => 'application/json'
6161
];
62-
if (isset($this->credentials['token'])) {
62+
if (isset($this->credentials['token']) && $auth) {
6363
$headers = [
6464
'Authorization' => 'Bearer ' . $this->credentials['token'],
6565
'Content-Type' => 'application/json'

src/Transfer.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,33 @@ public function status($tracking_id)
4040
return $this->send_request('POST','/send-money/status/', $payload);
4141
}
4242

43-
public function mpesa($currency, $transactions, $callback_url=null)
43+
public function mpesa($currency, $transactions, $callback_url=null, $wallet_id=null)
4444
{
4545
$provider = "MPESA-B2C";
46-
return $this->send_money($provider, $currency, $transactions, $callback_url=null);
46+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
4747
}
4848

49-
public function mpesa_b2b($currency, $transactions, $callback_url=null)
49+
public function mpesa_b2b($currency, $transactions, $callback_url=null, $wallet_id=null)
5050
{
5151
$provider = "MPESA-B2B";
52-
return $this->send_money($provider, $currency, $transactions, $callback_url=null);
52+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
5353
}
5454

55-
public function intasend($currency, $transactions, $callback_url=null)
55+
public function intasend($currency, $transactions, $callback_url=null, $wallet_id=null)
5656
{
5757
$provider = "INTASEND";
58-
return $this->send_money($provider, $currency, $transactions, $callback_url=null);
58+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
5959
}
6060

61-
public function bank($currency, $transactions, $callback_url=null)
61+
public function bank($currency, $transactions, $callback_url=null, $wallet_id=null)
6262
{
6363
$provider = "PESALINK";
64-
return $this->send_money($provider, $currency, $transactions, $callback_url=null);
64+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
6565
}
6666

67-
public function airtime($currency, $transactions, $callback_url=null)
67+
public function airtime($currency, $transactions, $callback_url=null, $wallet_id=null)
6868
{
6969
$provider = "AIRTIME";
70-
return $this->send_money($provider, $currency, $transactions, $callback_url=null);
70+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
7171
}
7272
}

src/Wallet.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ public function intra_transfer( $origin_id, $destination_id, $amount, $narrative
5252
return $this->send_request('POST','/wallets/'.$origin_id.'/intra_transfer/',$payload);
5353
}
5454

55-
public function fund($phone_number, $email=null, $amount, $method="MPESA_STK_PUSH", $currency="KES", $api_ref="API Request", $name=null)
55+
public function fund_mpesa_stk_push($wallet_id, $phone_number, $email=null, $amount, $api_ref="API Request")
5656
{
5757
$collection=new Collection();
5858
$collection->init($this->credentials);
59-
return $collection->create($amount, $phone_number, $currency, $method, $api_ref, $name, $email);
59+
return $collection->create($amount=$amount, $phone_number=$phone_number, $currency="KES", $method="MPESA_STK_PUSH", $api_ref=$api_ref, $email=null, $wallet_id=$wallet_id);
60+
}
61+
62+
public function fund_checkout($wallet_id, $currency, $customer, $amount, $host, $redirect_url=null, $api_ref="API Request", $card_tarrif = "BUSINESS-PAYS", $mobile_tarrif = "BUSINESS-PAYS"){
63+
$checkout = new Checkout();
64+
$checkout->init($this->credentials);
65+
66+
return $checkout->create($amount = $amount, $currency = $currency, $customer = $customer, $host=$host, $redirect_url = $redirect_url, $api_ref = $api_ref, $comment = null, $method = null, $card_tarrif = "BUSINESS-PAYS", $mobile_tarrif = "BUSINESS-PAYS", $wallet_id=$wallet_id);
67+
6068
}
6169

6270
}

0 commit comments

Comments
 (0)