safaricom / mpesa-node-library

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

C2B Register URLs For Production Should Use V2 API #56

Open nigelnindodev opened 2 months ago

nigelnindodev commented 2 months ago

Describe the bug

Using V1 version of the API fails with the following error code & message:

"errorCode": "401.003.01",
"errorMessage": "Error Occurred - Invalid Access Token - Invalid API call as no apiproduct match found"

To Reproduce Steps to reproduce the behavior:

Use the library to make calls to register C2B URLs for production.

Expected behavior First time registration of C2B URLs should have the following as part of its response:

 "ResponseCode": "0",
 "ResponseDescription": "Success"

Screenshots N/A

Additional context To quickly test if this works, here is a script to quickly test using V2 version of the API:

let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Bearer [add_valid_token_here]');

const BASE_URL = '';  // Add you base url

fetch('https://api.safaricom.co.ke/mpesa/c2b/v2/registerurl', {
    method: 'POST',
    headers,
    body: JSON.stringify({
        ShortCode: 0000000, // replace with production short code as number
        ResponseType: 'Completed',
        ConfirmationURL: `${BASE_URL}/confirmation_url_path`,
        ValidationURL: `${BASE_URL}/validation_url_path`
    })
})
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.log(error));