safaricom / mpesa-php-sdk

A PHP sdk for the new Mpesa RESTful APIs
188 stars 219 forks source link

Mismatch between comment and actual method #22

Open AustineGwa opened 6 years ago

AustineGwa commented 6 years ago

There is a misleading comment in the mpesa class . The comment says that the function should be called for a B2C transaction while the actual function is a c2b.

/**
 * Use this function to initiate a B2C transaction
 * @param $ShortCode | 6 digit M-Pesa Till Number or PayBill Number
 * @param $CommandID | Unique command for each transaction type.
 * @param $Amount | The amount been transacted.
 * @param $Msisdn | MSISDN (phone number) sending the transaction, start with country code without the plus(+) sign.
 * @param $BillRefNumber |  Bill Reference Number (Optional).
 * @return mixed|string
 */
public  static  function  c2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber ){
    $environment=env("MPESA_ENV");

    if( $environment =="live"){
        $url = 'https://api.safaricom.co.ke/mpesa/c2b/v1/simulate';
        $token=self::generateLiveToken();
    }elseif ($environment=="sandbox"){
        $url = 'https://sandbox.safaricom.co.ke/mpesa/c2b/v1/simulate';
        $token=self::generateSandBoxToken();
    }else{
        return json_encode(["Message"=>"invalid application status"]);
    }

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Bearer '.$token));

    $curl_post_data = array(
        'ShortCode' => $ShortCode,
        'CommandID' => $CommandID,
        'Amount' => $Amount,
        'Msisdn' => $Msisdn,
        'BillRefNumber' => $BillRefNumber
    );

    $data_string = json_encode($curl_post_data);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($curl, CURLOPT_HEADER, false);
    $curl_response = curl_exec($curl);
    return $curl_response;

}

please check it out

urandu commented 6 years ago

That is clearly an error. the comment should be corrected to c2b

urandu commented 6 years ago

https://github.com/safaricom/mpesa-php-sdk/pull/23

AustineGwa commented 6 years ago

Can I correct it or has it been assigned to someone else On Sep 5, 2018 12:25 AM, "Urandu Bildad Namawa" notifications@github.com wrote:

23 https://github.com/safaricom/mpesa-php-sdk/pull/23

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/safaricom/mpesa-php-sdk/issues/22#issuecomment-418523302, or mute the thread https://github.com/notifications/unsubscribe-auth/Aa0KCUGlxIWEthGuBQT8UtHTn1Kk5LvMks5uXu_UgaJpZM4WDtXQ .

urandu commented 6 years ago

I have already corrected it. Here is the PR https://github.com/safaricom/mpesa-php-sdk/pull/23

griffins commented 6 years ago

moderator close the issue since the PR has been merged

M-Abdullahi commented 5 years ago

Hi. Why is this issue still open?