Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatch between comment and actual method #22

Open
AustineGwa opened this issue Aug 20, 2018 · 6 comments
Open

Mismatch between comment and actual method #22

AustineGwa opened this issue Aug 20, 2018 · 6 comments

Comments

@AustineGwa
Copy link

AustineGwa commented Aug 20, 2018

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
Copy link
Contributor

urandu commented Sep 4, 2018

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

@urandu
Copy link
Contributor

urandu commented Sep 4, 2018

#23

@AustineGwa
Copy link
Author

AustineGwa commented Sep 5, 2018 via email

@urandu
Copy link
Contributor

urandu commented Sep 5, 2018

I have already corrected it. Here is the PR #23

@griffins
Copy link

moderator close the issue since the PR has been merged

@M-Abdullahi
Copy link

Hi. Why is this issue still open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants