Skip to content

Commit

Permalink
Merge pull request #12 from IntaSend/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
felixcheruiyot authored May 30, 2024
2 parents fa04d6f + 5c1c682 commit a8a9d43
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 52 deletions.
90 changes: 53 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ Below is a basic example on how to set up. Check full example in your [Laravel p
use IntaSend\IntaSendPHP\Customer;

$credentials = [
'publishable_key' => 'INTASEND_PUBLISHABLE_KEY'
'publishable_key' => env('INTASEND_PUBLISHABLE_KEY'),
'test' => env('INTASEND_TEST_ENVIRONMENT', true),
];

$customer = new Customer();
$customer->first_name = "Joe";
$customer->last_name = "Doe";
$customer->email = "joe@doe.com";
$customer->country = "KE";
$customer->city = "Nairobi";
$customer->address = "Apt 123, Westland road";
$customer->zipcode = "0100";
$customer->state = "Nairobi";

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

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

## Send M-Pesa STK-Push

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.

use IntaSend\IntaSendPHP\Collection;

$credentials = [
'publishable_key' => 'INTASEND_PUBLISHABLE_KEY'
'publishable_key' => env('INTASEND_PUBLISHABLE_KEY'),
'test' => env('INTASEND_TEST_ENVIRONMENT', true),
];


$collection = new Collection();
$collection->init($credentials);

$amount = 10;
$phone_number = "254720000000";
$api_ref = "ORDER-1";
$response = $collection->mpesa_stk_push($amount, $phone_number, $api_ref);
print_r($response);

$invoice = $response->invoice;
$invoice_id = $invoice->invoice_id;
$response = $collection->status($invoice_id);
$response = $collection->create($amount=10, $phone_number="2547...", $currency="KES", $method="MPESA_STK_PUSH", $api_ref="Your API Ref", $name="", $email="john@example.com");
print_r($response);

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

$transactions = [
['account'=>'254723890353','amount'=>'2000', 'narrative'=>'Salary'],
['account'=>'254723890260','amount'=>'15000', 'narrative'=>'Dividends']
['account'=>'254723890353','amount'=>'20'],
['account'=>'254723890260','amount'=>'15']
];

$transfer = new Transfer();
$transfer->init($credentials);

$response=$transfer->mpesa("KES", $transactions);

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

## How to Send Money to M-Pesa Till Number
## How to Send Money to M-Pesa Till Number or PayBill

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

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

$transactions = [
['account'=>'5002901', 'account_type'=>'TillNumber', 'amount'=>'2000', 'narrative'=>'Trip']
['name' => 'Business A','account'=>'524311','amount'=>'200', 'account_type'=>'PayBill', 'account_reference'=>'29822182', 'narrative'=> 'Bill Payment'],
['name' => 'Business B','account'=>'17626','amount'=>'150', 'account_type'=>'TillNumber', 'narrative'=> 'Purchase']
];

$transfer = new Transfer();
$transfer->init($credentials);
$response=$transfer->mpesa("KES", $transactions);

$response=$transfer->mpesa_b2b("KES", $transactions);

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

$transactions = [
['account'=>'12910000111', 'name'=>'Joe Doe', 'bank_code' => 2, 'amount'=>'2000', 'narrative'=>'Salary'],
['account'=>'23332112222', 'name'=>'Mary Doe', 'bank_code' => 4, 'amount'=>'1500', 'narrative'=>'Salary']
['name' => 'Joe Doe','account'=>'0129292920202','amount'=>'200', 'bank_code'=>'2', 'narrative'=> 'Bill Payment'],
['name' => 'Mary Doe','account'=>'525623632321','amount'=>'150', 'bank_code'=>'11', 'narrative'=> 'Purchase']
];

$transfer = new Transfer();
$transfer->init($credentials);

$response=$transfer->bank("KES", $transactions);

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

$currency = "KES";
$label = "WALLET-1";
$response = $wallet->create($currency, $label);
print_r($response);
$response = $wallet->create($currency='KES', $label='MY-WALLET-ID', $can_disburse=true);
print_r($response);

### List all wallets in your account

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

### View wallet details and its transactions

$wallet_id = "KASPWO1";
$response = $wallet->details($wallet_id);
$response = $wallet->transactions('<wallet_id>');
print_r($response);

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

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

$phone_number = "254723890353";
$email = "john.doe@gmail.com";
$amount = 10;

$response = $wallet->fund($phone_number=$phone_number, $email=$email, $amount=$amount);
$response = $wallet->fund_mpesa_stk_push($wallet_id="<wallet_id>", $phone_number='2547...',$email='john@doe.com', $amount=10, $api_ref="API Request");
print_r($response);

### Direct deposit to wallet with Checkout Method

use IntaSend\IntaSendPHP\Customer;

$customer = new Customer();
$customer->first_name = "Joe";
$customer->last_name = "Doe";
$customer->email = "joe@doe.com";
$customer->country = "KE";

$host = "https://example.com";
$redirect_url = "https://example.com";

$ref_order_number = "fund-wallet-10";

$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");
print_r($response->url);

### Wallet to wallet transfers (Intra-transfer)

Transfer funds between wallets in your account
Expand All @@ -314,6 +317,19 @@ Transfer funds between wallets in your account

$response = $wallet->intra_transfer($origin_wallet_id, $destination_wallet_id, $amount, $narrative);
print_r($response);

### External Wallet Transfer to M-PESA
use IntaSend\IntaSendPHP\Transfer;

$transactions = [
['account'=>'254...','amount'=>'20'],
['account'=>'254...','amount'=>'15']
];

$response=$transfer->mpesa("KES", $transactions=$transactions, $callback_url=null, $wallet_id='<wallet_id>');
print_r($response);

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.

## Chargebacks Management

Expand Down
12 changes: 8 additions & 4 deletions examples/send_money.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
['account'=>'254723890260','amount'=>'15000', 'narrative'=>'Dividends']
];

$requires_approval = 'YES'; // Set to 'NO' if you want the transaction to go through without calling the approve method

$transfer = new Transfer();
$transfer->init($credentials);

$response=$transfer->mpesa("KES", $transactions);
$response=$transfer->mpesa("KES", $transactions, $requires_approval=$requires_approval);

//call approve method for approving last transaction
$response = $transfer->approve($response);
print_r($response);
//call approve method for approving last transaction if requires_approval = 'YES
if( $requires_approval === 'YES' ){
$response = $transfer->approve($response);
print_r($response);
};

// Check status
$response = $transfer->status($response->tracking_id);
Expand Down
23 changes: 12 additions & 11 deletions src/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ public function init($credentials)
$this->credentials=$credentials;
}

public function send_money($provider, $currency, $transactions, $callback_url=null, $wallet_id=null)
public function send_money($provider, $currency, $transactions, $callback_url=null, $wallet_id=null, $requires_approval='YES')
{
$payload=[
'provider'=> $provider,
'currency'=> $currency,
'requires_approval'=>$requires_approval,
'transactions'=> $transactions,
'callback_url'=> $callback_url,
'wallet_id' => $wallet_id
Expand All @@ -40,33 +41,33 @@ public function status($tracking_id)
return $this->send_request('POST','/send-money/status/', $payload);
}

public function mpesa($currency, $transactions, $callback_url=null, $wallet_id=null)
public function mpesa($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
{
$provider = "MPESA-B2C";
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
}

public function mpesa_b2b($currency, $transactions, $callback_url=null, $wallet_id=null)
public function mpesa_b2b($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
{
$provider = "MPESA-B2B";
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
}

public function intasend($currency, $transactions, $callback_url=null, $wallet_id=null)
public function intasend($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
{
$provider = "INTASEND";
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
}

public function bank($currency, $transactions, $callback_url=null, $wallet_id=null)
public function bank($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
{
$provider = "PESALINK";
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
}

public function airtime($currency, $transactions, $callback_url=null, $wallet_id=null)
public function airtime($currency, $transactions, $requires_approval='YES', $callback_url=null, $wallet_id=null)
{
$provider = "AIRTIME";
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id);
return $this->send_money($provider, $currency, $transactions, $callback_url=$callback_url, $wallet_id=$wallet_id, $requires_approval=$requires_approval);
}
}

0 comments on commit a8a9d43

Please sign in to comment.