Customer to bussiness transactions
#
How to transact from customer to businessIn this course, we will cover what you need to transact from customers to businesses using Node.js.
First, we set up the application in the portal.
When building apps on the sandbox environment, Using the sandbox credentials allows us to test our application logic without incurring any costs.
We will import the required libraries which have already been pre-installed.
Here’s the code that does this:
- CommonJS
- ES Modules
The above code imports the Pesa SDK for us.
Next, we set our app credentials.
These are the credentials that we use to authenticate requests to the Mpesa OpenAPI service.
Now we are going to initialize the Pesa SDK.
We have just required the Pesa module into our app and assigned it to the pesa
variable. We initialize it with our api_key
and public_key
which will be used to make authenticated transactions. Easy right?
Now let’s set up our transaction.
To transact from customer to business, you need the following:
Attribute | Desccription | default |
---|---|---|
Amount | An Amount | |
CustomerMSISDN | A CustomerMSISDN | |
Country | Country | TZN |
Currency | Currency | TZS |
ServiceProviderCode | Service Provider Code | |
TransactionReference | Transaction Reference | random number |
ThirdPartyConversationID | Purchased Items Desc | random number |
Next, we have a function to execute the transaction right below the // Execute transaction
line.
If the code works and the transaction is successful, it will print the response onto the console logs. If it’s not successful, it will print out an error instead.
Sample response
You’re all set!
#
Example FullHappy Coding!! 😀