safaricom / mpesa-node-library

M-Pesa Library for Node.js using REST API
Apache License 2.0
160 stars 137 forks source link

Daraja Sandbox Certificate is different and doesn't work #17

Open alexanderwanyoike opened 5 years ago

alexanderwanyoike commented 5 years ago

Description

Not really a bug actually the sandbox certificate specified in this repo is correct and I managed to get successful transactions using this key. This is not the case for https://developer.safaricom.co.ke/sites/default/files/cert/cert_sandbox/cert.cer that is different from the certificate that the library uses. The certificate posted on the docs didn't work

Reproduction

Steps to reproduce the behaviour:

  1. Using the mpesa-node-library send a b2c request with using the certificate in daraja to encrypt your Security Credential

Expectation

A successful transaction

Actual

Transaction with the error Initiator Information is invalid

Specification

ghost commented 5 years ago

You saved the day! Thank you so much @alexanderwanyoike

geofmureithi-zz commented 5 years ago

@alexanderwanyoike Noted. This will be changed to a post install, hence always get the latest after an install. in the mean while, you can always load your own cert during instantiation.

{ 
    consumerSecret: '<your consumer secret>',
    environment: 'sandbox',
    shortCode: '600111',
    initiatorName: 'Test Initiator',
    lipaNaMpesaShortCode: 123456,
    lipaNaMpesaShortPass: '<some key here>',
    securityCredential: '<credential here>',
    certPath: path.resolve('keys/myKey.cert') //<------------------------- here
}
ghost commented 4 years ago

Hi @geofmureithi any idea if the production has the same mismatch cert issues?

I am trying production cert and it has the same initiator issue as sandbox.

I am communicating with Api feedback team but day of launch has come and they didn't replied back yet

mulama77 commented 4 years ago

Hi @alexanderwanyoike

i have tried both certificates in

https://github.com/safaricom/mpesa-node-library/blob/master/keys/sandbox-cert.cer

and

https://developer.safaricom.co.ke/sites/default/files/cert/cert_sandbox/cert.cer

but am still getting the below callback error in B2C API

{
  "Result": {
    "ResultType": 0,
    "ResultCode": 2001,
    "ResultDesc": "The initiator information is invalid.",
    "OriginatorConversationID": "13400-2728457-1",
    "ConversationID": "AG_20200319_0000554b8a1231b91955",
    "TransactionID": "OCJ41HBH8U",
    "ReferenceData": {
      "ReferenceItem": {
        "Key": "QueueTimeoutURL",
        "Value": "https://internalsandbox.safaricom.co.ke/mpesa/b2cresults/v1/submit"
      }
    }
  }
}
geofmureithi-zz commented 4 years ago

@alexanderwanyoike You may need to look into Daraja itself. Several things might be happening.

  1. Daraja API has changed. I am no longer the maintainer of this lib, so hopefully someone takes it up. A PR would also be recommended.
  2. You are using the right cert but in the wrong environment.
  3. If 1 is not the issue, then this is not a library issue but a Daraja issue. Remember: certPath: path.resolve('keys/myKey.cert') //<------------------------- here
e-kibet commented 2 years ago

Can we add the certificate in vault for ease of management? And have something like docker on top of it.