safaricom / mpesa-php-sdk

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

Understanding the response of c2b transaction. #16

Closed abhi9419 closed 1 year ago

abhi9419 commented 6 years ago

Hi, I am using mpsea-php-sdk which is great but I am not able to understand what does the c2b transaction returns in response. I am getting below response. "{ "ConversationID": "AG_20180402_00004a92452ef78e864d", "OriginatorCoversationID": "12362-3240472-1", "ResponseDescription": "Accept the service request successfully." } "

What does this mean?? I am not able to fetch success code or something like that. Am i missing something ?

mossey commented 6 years ago

Hello @abhi9419 this is an immediate response saying that M-Pesa has received your request. The status os the transaction is determined by the response that is posted to your callback route.

abhi9419 commented 6 years ago

When sending a request initiate the C2B transaction there is no paramter to send the callback route. It has only below paramters:

{
    "ShortCode": "601426",
    "CommandID": "CustomerPayBillOnline",
    "Amount": "1",
    "Msisdn": "254708374149",
    "BillRefNumber": "10000",
}

I also tried sending callbackurl in the Safaricom Simulation Environment but I am unable to get any response on the callback page.

I am trying to simulate this process on Safaricom Website. But I am stuck at this point. Any help would be appreciated

mossey commented 5 years ago

Hi @abhi9419 lemme clarify how the C2B transaction works. The C2B transaction is a simulation of a usual payment to a paybill or till number from an MSISDN. When payment is made to a shortcode /till, two callbacks (callback and validation) are sent to the callback URLs that were configured/registered. Registation of the callbackURLS can be done on the portal. Upon receiving the two callbacks, one must respond with this JSON {"ResultCode": 0, "ResultDesc": "The service was accepted successfully", "ThirdPartyTransID": "1234567890"} . This tells M-Pesa to allow the transaction to proceed.

josekenya commented 5 years ago

Please help me understand how to implement both callbacks

AbeNalee commented 5 years ago

Hey @josekenya, upon testing you can use postman to register the callback routes. This is the syntax of the post request: { "ShortCode": $shortcode, "ResponseType": "Completed", "CommandID": "RegisterURL", "ConfirmationURL": $your_confirmation_url, "ValidationURL": $your_validation_url }

Of course, you need to have the access token in your headers. The response you should expect is a success message from the mpesa API.