Coder Social home page Coder Social logo

Comments (7)

newtonmunene99 avatar newtonmunene99 commented on June 3, 2024

Hi there, does this occur in the sandbox?
It doesn't seem to suggest a problem with the library, you might be passing the wrong initiator name.
When you say everything else works, does that include other methods which require initiator name?

from mpesa-api.

cngeru avatar cngeru commented on June 3, 2024

The withdrawal works in postman but fails when i use the code with the same credentials

from mpesa-api.

cngeru avatar cngeru commented on June 3, 2024

Any solution to this problem ?

from mpesa-api.

newtonmunene99 avatar newtonmunene99 commented on June 3, 2024

Hi @cngeru i'm still unable to reproduce this. You mentioned it worked for you on Postman. Can you share your request, with dummy values for sensitive fields.

from mpesa-api.

cngeru avatar cngeru commented on June 3, 2024

The request body in postman

{
    "InitiatorName": "CODE",
    "SecurityCredential": "CODE",
    "CommandID": "BusinessPayment",
    "Amount": "100",
    "PartyA": "CODE",
    "PartyB": "CODE",
    "Remarks": "CODEWithdrawal",
    "QueueTimeOutURL": "https://us-central1-CODE.cloudfunctions.net/mpesaWithdrawalTimeout?userId=xx&wAuth=xx",
    "ResultURL": "https://us-central1-CODE.cloudfunctions.net/mpesaWithdrawalResult?userId=xx&wAuth=xx",
    "Occasion": "CODE Withdrawal"
}

The code (JS)

const B2C_CREDS ={
  client_key: CODE,
  client_secret: 'CODE',
  initiator_password: "CODE",
  certificatepath: null
}

const B2C_DETAILS= {
  SHORTCODE : CODE,
  INITIATOR_NAME:'CODE',
};

const environment = "production";
const B2C = new Mpesa(B2C_CREDS, environment);

try {
    await B2C.b2c({
      Initiator:B2C_DETAILS.INITIATOR_NAME,
      Amount: amount,
      PartyA: B2C_DETAILS.SHORTCODE,
      PartyB: phoneNumber,
      QueueTimeOutURL:timeout,
      ResultURL: result,
      CommandID: "BusinessPayment",
      Occasion: `Withdrawal By ${CODE}`,
      Remarks: "CODE Withdrawal" 
    })
    .then((mpesaResponse)=>{
      console.log(JSON.stringify(mpesaResponse));
      return {result: 'Mpesa Transaction was successful'};
    })

from mpesa-api.

newtonmunene99 avatar newtonmunene99 commented on June 3, 2024

@cngeru I'm still looking into this, in the meantime, I've added the option to pass security credentials when initiating. This means you can generate the security credential in your M-Pesa web portal and pass it statically as a string. The library will generate it automatically if you exclude this field or pass it as null.

from mpesa-api.

cngeru avatar cngeru commented on June 3, 2024

Alrighty

from mpesa-api.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.