Skip to content

Commit a8a9d43

Browse files
Merge pull request #12 from IntaSend/dev
Dev
2 parents fa04d6f + 5c1c682 commit a8a9d43

3 files changed

Lines changed: 73 additions & 52 deletions

File tree

README.md

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,15 @@ Below is a basic example on how to set up. Check full example in your [Laravel p
4646
use IntaSend\IntaSendPHP\Customer;
4747

4848
$credentials = [
49-
'publishable_key' => 'INTASEND_PUBLISHABLE_KEY'
49+
'publishable_key' => env('INTASEND_PUBLISHABLE_KEY'),
50+
'test' => env('INTASEND_TEST_ENVIRONMENT', true),
5051
];
5152

5253
$customer = new Customer();
5354
$customer->first_name = "Joe";
5455
$customer->last_name = "Doe";
5556
$customer->email = "joe@doe.com";
5657
$customer->country = "KE";
57-
$customer->city = "Nairobi";
58-
$customer->address = "Apt 123, Westland road";
59-
$customer->zipcode = "0100";
60-
$customer->state = "Nairobi";
6158

6259
$amount = 10;
6360
$currency = "KES";
@@ -71,30 +68,24 @@ Below is a basic example on how to set up. Check full example in your [Laravel p
7168
$checkout->init($credentials);
7269
$resp = $checkout->create($amount = $amount, $currency = $currency, $customer = $customer, $host=$host, $redirect_url = $redirect_url, $api_ref = $ref_order_number, $comment = null, $method = null);
7370

71+
// Redirect the user to the URL to complete payment
7472
print_r($resp->url);
7573

7674
## Send M-Pesa STK-Push
7775

7876
Checkout API generates a URL that enables you to do M-Pesa collection and other payment methods. In case you want to leverage only the M-Pesa STK-Push option, you might want to consider this the `collection->mpesa_stk_push()` option.
7977

8078
use IntaSend\IntaSendPHP\Collection;
81-
8279
$credentials = [
83-
'publishable_key' => 'INTASEND_PUBLISHABLE_KEY'
80+
'publishable_key' => env('INTASEND_PUBLISHABLE_KEY'),
81+
'test' => env('INTASEND_TEST_ENVIRONMENT', true),
8482
];
8583

84+
8685
$collection = new Collection();
8786
$collection->init($credentials);
8887

89-
$amount = 10;
90-
$phone_number = "254720000000";
91-
$api_ref = "ORDER-1";
92-
$response = $collection->mpesa_stk_push($amount, $phone_number, $api_ref);
93-
print_r($response);
94-
95-
$invoice = $response->invoice;
96-
$invoice_id = $invoice->invoice_id;
97-
$response = $collection->status($invoice_id);
88+
$response = $collection->create($amount=10, $phone_number="2547...", $currency="KES", $method="MPESA_STK_PUSH", $api_ref="Your API Ref", $name="", $email="john@example.com");
9889
print_r($response);
9990

10091
## How to create Payment links
@@ -145,13 +136,13 @@ Payment links are free forms that you can share with your customers on email and
145136
];
146137

147138
$transactions = [
148-
['account'=>'254723890353','amount'=>'2000', 'narrative'=>'Salary'],
149-
['account'=>'254723890260','amount'=>'15000', 'narrative'=>'Dividends']
139+
['account'=>'254723890353','amount'=>'20'],
140+
['account'=>'254723890260','amount'=>'15']
150141
];
151142

152143
$transfer = new Transfer();
153144
$transfer->init($credentials);
154-
145+
155146
$response=$transfer->mpesa("KES", $transactions);
156147

157148
//call approve method for approving last transaction
@@ -186,7 +177,7 @@ To send money to M-Pesa PayBills, specify business number under account and an a
186177
$response = $transfer->approve($response);
187178
print_r($response);
188179

189-
## How to Send Money to M-Pesa Till Number
180+
## How to Send Money to M-Pesa Till Number or PayBill
190181

191182
To send money to Till Numbers, simply specify the account number. No account reference is requred.
192183

@@ -198,13 +189,14 @@ To send money to Till Numbers, simply specify the account number. No account ref
198189
];
199190

200191
$transactions = [
201-
['account'=>'5002901', 'account_type'=>'TillNumber', 'amount'=>'2000', 'narrative'=>'Trip']
192+
['name' => 'Business A','account'=>'524311','amount'=>'200', 'account_type'=>'PayBill', 'account_reference'=>'29822182', 'narrative'=> 'Bill Payment'],
193+
['name' => 'Business B','account'=>'17626','amount'=>'150', 'account_type'=>'TillNumber', 'narrative'=> 'Purchase']
202194
];
203195

204196
$transfer = new Transfer();
205197
$transfer->init($credentials);
206-
207-
$response=$transfer->mpesa("KES", $transactions);
198+
199+
$response=$transfer->mpesa_b2b("KES", $transactions);
208200

209201
//call approve method for approving last transaction
210202
$response = $transfer->approve($response);
@@ -222,13 +214,13 @@ You'll need a bank code and account numbers to send bank payments. Here is a [li
222214
];
223215

224216
$transactions = [
225-
['account'=>'12910000111', 'name'=>'Joe Doe', 'bank_code' => 2, 'amount'=>'2000', 'narrative'=>'Salary'],
226-
['account'=>'23332112222', 'name'=>'Mary Doe', 'bank_code' => 4, 'amount'=>'1500', 'narrative'=>'Salary']
217+
['name' => 'Joe Doe','account'=>'0129292920202','amount'=>'200', 'bank_code'=>'2', 'narrative'=> 'Bill Payment'],
218+
['name' => 'Mary Doe','account'=>'525623632321','amount'=>'150', 'bank_code'=>'11', 'narrative'=> 'Purchase']
227219
];
228220

229221
$transfer = new Transfer();
230222
$transfer->init($credentials);
231-
223+
232224
$response=$transfer->bank("KES", $transactions);
233225

234226
//call approve method for approving last transaction
@@ -275,10 +267,8 @@ Example on how to create a new wallet, list wallets and other details
275267
$wallet = new Wallet();
276268
$wallet->init($credentials);
277269

278-
$currency = "KES";
279-
$label = "WALLET-1";
280-
$response = $wallet->create($currency, $label);
281-
print_r($response);
270+
$response = $wallet->create($currency='KES', $label='MY-WALLET-ID', $can_disburse=true);
271+
print_r($response);
282272

283273
### List all wallets in your account
284274

@@ -287,22 +277,35 @@ Example on how to create a new wallet, list wallets and other details
287277

288278
### View wallet details and its transactions
289279

290-
$wallet_id = "KASPWO1";
291-
$response = $wallet->details($wallet_id);
280+
$response = $wallet->transactions('<wallet_id>');
292281
print_r($response);
293282

294283
$response = $wallet->transactions($wallet_id);
295284
print_r($response);
296285

297286
### Direct deposit to wallet using M-Pesa STK Push
298287

299-
$phone_number = "254723890353";
300-
$email = "john.doe@gmail.com";
301-
$amount = 10;
302-
303-
$response = $wallet->fund($phone_number=$phone_number, $email=$email, $amount=$amount);
288+
$response = $wallet->fund_mpesa_stk_push($wallet_id="<wallet_id>", $phone_number='2547...',$email='john@doe.com', $amount=10, $api_ref="API Request");
304289
print_r($response);
305290

291+
### Direct deposit to wallet with Checkout Method
292+
293+
use IntaSend\IntaSendPHP\Customer;
294+
295+
$customer = new Customer();
296+
$customer->first_name = "Joe";
297+
$customer->last_name = "Doe";
298+
$customer->email = "joe@doe.com";
299+
$customer->country = "KE";
300+
301+
$host = "https://example.com";
302+
$redirect_url = "https://example.com";
303+
304+
$ref_order_number = "fund-wallet-10";
305+
306+
$response = $wallet->fund_checkout($wallet_id="<wallet_id>", $phone_number='2547..', $currency='USD', $customer=$customer, $amount=10, $host=$host, $redirect_url=$redirect_url, $api_ref=$ref_order_number, $card_tarrif = "BUSINESS-PAYS", $mobile_tarrif = "BUSINESS-PAYS");
307+
print_r($response->url);
308+
306309
### Wallet to wallet transfers (Intra-transfer)
307310

308311
Transfer funds between wallets in your account
@@ -314,6 +317,19 @@ Transfer funds between wallets in your account
314317

315318
$response = $wallet->intra_transfer($origin_wallet_id, $destination_wallet_id, $amount, $narrative);
316319
print_r($response);
320+
321+
### External Wallet Transfer to M-PESA
322+
use IntaSend\IntaSendPHP\Transfer;
323+
324+
$transactions = [
325+
['account'=>'254...','amount'=>'20'],
326+
['account'=>'254...','amount'=>'15']
327+
];
328+
329+
$response=$transfer->mpesa("KES", $transactions=$transactions, $callback_url=null, $wallet_id='<wallet_id>');
330+
print_r($response);
331+
332+
Like all other Send Money APIs, the above request is also a two step. Please go through the send money examples on full implementation for M-Pesa B2C, M-Pesa B2B, Bank Payouts and IntaSend P2P.
317333

318334
## Chargebacks Management
319335

examples/send_money.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818
['account'=>'254723890260','amount'=>'15000', 'narrative'=>'Dividends']
1919
];
2020

21+
$requires_approval = 'YES'; // Set to 'NO' if you want the transaction to go through without calling the approve method
22+
2123
$transfer = new Transfer();
2224
$transfer->init($credentials);
2325

24-
$response=$transfer->mpesa("KES", $transactions);
26+
$response=$transfer->mpesa("KES", $transactions, $requires_approval=$requires_approval);
2527

26-
//call approve method for approving last transaction
27-
$response = $transfer->approve($response);
28-
print_r($response);
28+
//call approve method for approving last transaction if requires_approval = 'YES
29+
if( $requires_approval === 'YES' ){
30+
$response = $transfer->approve($response);
31+
print_r($response);
32+
};
2933

3034
// Check status
3135
$response = $transfer->status($response->tracking_id);

src/Transfer.php

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

15-
public function send_money($provider, $currency, $transactions, $callback_url=null, $wallet_id=null)
15+
public function send_money($provider, $currency, $transactions, $callback_url=null, $wallet_id=null, $requires_approval='YES')
1616
{
1717
$payload=[
1818
'provider'=> $provider,
1919
'currency'=> $currency,
20+
'requires_approval'=>$requires_approval,
2021
'transactions'=> $transactions,
2122
'callback_url'=> $callback_url,
2223
'wallet_id' => $wallet_id
@@ -40,33 +41,33 @@ public function status($tracking_id)
4041
return $this->send_request('POST','/send-money/status/', $payload);
4142
}
4243

43-
public function mpesa($currency, $transactions, $callback_url=null, $wallet_id=null)
44+
public function mpesa($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
4445
{
4546
$provider = "MPESA-B2C";
46-
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
47+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
4748
}
4849

49-
public function mpesa_b2b($currency, $transactions, $callback_url=null, $wallet_id=null)
50+
public function mpesa_b2b($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
5051
{
5152
$provider = "MPESA-B2B";
52-
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
53+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
5354
}
5455

55-
public function intasend($currency, $transactions, $callback_url=null, $wallet_id=null)
56+
public function intasend($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
5657
{
5758
$provider = "INTASEND";
58-
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
59+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
5960
}
6061

61-
public function bank($currency, $transactions, $callback_url=null, $wallet_id=null)
62+
public function bank($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
6263
{
6364
$provider = "PESALINK";
64-
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
65+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
6566
}
6667

67-
public function airtime($currency, $transactions, $callback_url=null, $wallet_id=null)
68+
public function airtime($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
6869
{
6970
$provider = "AIRTIME";
70-
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
71+
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
7172
}
7273
}

0 commit comments

Comments
 (0)