PHP code example of chipdeals / momo-api

1. Go to this page and download the library: Download chipdeals/momo-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chipdeals / momo-api example snippets

=
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");

//Collect 500 XOF from the +22951010200 Mobile Money wallet.
$collection = $momo
  ->collect()
  ->amount(500)
  ->currency("XOF")
  ->from('22951010200')
  ->create();
print_r($collection->getArray());

//Send 2000 XOF to the +22951010200 Mobile Money wallet.
$deposit = $momo
  ->deposit()
  ->amount(2000)
  ->currency("XOF")
  ->to('22951010200')
  ->create();
print_r($deposit->getArray());

=
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");

$collection = $momo
  ->collect()
  ->amount(2000) //Amount of the transaction
  ->currency("XOF") // Any valid currency
  ->from("22951010200") // Sender phone number with country code préfix
  ->isWaveAccount(false) //optional. Required only for wave operator
  ->useOtp(123456) //Required only for Orange Money Burkina. Get it from user after they generate it for your amount by doing: *144*4*6*montant# 
  ->firstName("Iyam") // First name of the sender
  ->lastName("EVERICH") // Last name of the sender
  ->merchantOrderId("collection-test00001") //optional. If added we will check if it is uniq for your account
  ->create();

print_r($collection->getArray());
echo "<br/>" . $collection->getReference();
=4
$collection = $momo
  ->collect()
  ->amount(2000) //Amount of the transaction
  ->currency("XOF") // Any valid currency
  ->from("22951010200") // Sender phone number with country code préfix
  ->firstName("Iyam") // First name of the sender
  ->lastName("EVERICH") // Last name of the sender
  ->webhook("https:// mydomain/payment-status") // Url where we will send you transaction data on progress
  ->create();

print_r($collection->getArray());
echo "<br/>" . $collection->getReference();
=
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");

$deposit = $momo
  ->deposit()
  ->amount(2000) //Amount of the transaction
  ->currency("XOF") // Any valid currency
  ->to('22951010200') // Recipient phone number with country code préfix
  ->isWaveAccount(false) //optional. Required only for CI wave operator
  ->merchantOrderId("deposit-test00001") //optional. If added we will check if it is uniq for your account
  ->create();

print_r($deposit->getArray());
echo "<br/>" . $deposit->getReference();
=4
$deposit = $momo
  ->deposit()
  ->amount(2000) //Amount of the transaction
  ->currency("XOF") // Any valid currency
  ->to('22951010200') // Recipient phone number with country code préfix
  ->webhook("https:// mydomain/payment-status") // Url where we will send you transaction data on progress
  ->create();

print_r($deposit->getArray());
echo "<br/>" . $deposit->getReference();
=
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");

$reference = "ba32a171-cbea-45fd-8848-ac5b77580be3"
$transaction = $momo->getStatus($reference);

echo $transaction->getReference() . "<br/>";
echo $transaction->getMerchantOrderId() . "<br/>";
echo $transaction->getPhoneNumber() . "<br/>";
echo $transaction->getCountryCode() . "<br/>";
echo $transaction->getOperator() . "<br/>";
echo $transaction->getFirstName() . "<br/>";
echo $transaction->getLastName() . "<br/>";
echo $transaction->getOriginalCurrency() . "<br/>";
echo $transaction->getOriginalAmount() . "<br/>";
echo $transaction->getCurrency() . "<br/>";
echo $transaction->getAmount() . "<br/>";
echo $transaction->getStatus() . "<br/>";
echo $transaction->getStatusMessage() . "<br/>";
echo $transaction->getStatusCode() . "<br/>";
echo $transaction->getStartTimestampInSecond() . "<br/>";
echo $transaction->getEndTimestampInSecond() . "<br/>";
echo $transaction->checkIsCollection() . "<br/>"; 
echo $transaction->getOperatorReference() . "<br/>"; 
echo $transaction->getPaymentLink() . "<br/>";


echo "<pre>";
print_r($transaction->getArray());
=
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");

$balances =  $momo->getBalances();

foreach ($balances as $balanceKey => $balance) {
  echo $balance->getCountryCode() . "<br/>";
  echo $balance->getOperator() . "<br/>";
  echo $balance->getCurrency() . "<br/>";
  echo $balance->getAmount() . "<br/>";

  echo "<pre>";
  print_r($balance->getArray());
}