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 PHP.
First set up the application in the portal
When building apps on the sandbox application, Using the sandbox API which allows us to test our application logic without incurring any costs.
At the bottom left corner of the screen there’s a little phone icon, click it and enter your phone number. This will be the test number you’ll be using and is the number we will send the airtime to. Ensure that you’ve edited the phone number variable we wrote earlier to the phone number you’re using on the simulator.
we will import the required libraries which have already been preinstalled.
Here’s the code that does this:
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 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 calls to the airtime service. Easy right?
Now let’s set up our transaction.
In order 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 up 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.
You’re all set!
#
Example FullHappy Coding!! 😀