Skip to content

Commit

Permalink
feat(examples): added pesa demo example
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaolomi committed Oct 11, 2020
1 parent bda2517 commit 4d91304
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/pesa-demo/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
USERNAME=sandbox
PUBLICKEY=
AUTHURL=
APIKEY=
9 changes: 9 additions & 0 deletions examples/pesa-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build
composer.lock
docs
vendor
coverage

.idea
/examples/http-client.private.env.json
/examples/my-simple.php
16 changes: 16 additions & 0 deletions examples/pesa-demo/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "openpesa/pesa-demo",
"description": "Simple SDK usage",
"type": "project",
"require": {
"php": ">=7.1",
"openpesa/pesa": "dev-develop"
},
"license": "MIT",
"authors": [
{
"name": "Alpha Olomi",
"email": "alphaolomi@gmail.com"
}
]
}
46 changes: 46 additions & 0 deletions examples/pesa-demo/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
require 'vendor/autoload.php';

use Openpesa\SDK\Forodha;
use GuzzleHttp\Client;

$username = 'sandbox';
$publicKey = 'MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEArv9yxA69XQKBo24BaF/D+fvlqmGdYjqLQ5WtNBb5tquqGvAvG3WMFETVUSow/LizQalxj2ElMVrUmzu5mGGkxK08bWEXF7a1DEvtVJs6nppIlFJc2SnrU14AOrIrB28ogm58JjAl5BOQawOXD5dfSk7MaAA82pVHoIqEu0FxA8BOKU+RGTihRU+ptw1j4bsAJYiPbSX6i71gfPvwHPYamM0bfI4CmlsUUR3KvCG24rB6FNPcRBhM3jDuv8ae2kC33w9hEq8qNB55uw51vK7hyXoAa+U7IqP1y6nBdlN25gkxEA8yrsl1678cspeXr+3ciRyqoRgj9RD/ONbJhhxFvt1cLBh+qwK2eqISfBb06eRnNeC71oBokDm3zyCnkOtMDGl7IvnMfZfEPFCfg5QgJVk1msPpRvQxmEsrX9MQRyFVzgy2CWNIb7c+jPapyrNwoUbANlN8adU1m6yOuoX7F49x+OjiG2se0EJ6nafeKUXw/+hiJZvELUYgzKUtMAZVTNZfT8jjb58j8GVtuS+6TM2AutbejaCV84ZK58E2CRJqhmjQibEUO6KPdD7oTlEkFy52Y1uOOBXgYpqMzufNPmfdqqqSM4dU70PO8ogyKGiLAIxCetMjjm6FCMEA3Kc8K0Ig7/XtFm9By6VxTJK1Mg36TlHaZKP6VzVLXMtesJECAwEAAQ==';
$authUrl = 'https://openapi.m-pesa.com/sandbox/ipg/v2/vodacomTZN/getSession/';
$apiKey = '';


$client = new Client([

This comment has been minimized.

Copy link
@leyluj

leyluj Oct 13, 2020

Collaborator

Mzee, Lets hide this from the examples, you don't want to confuse beginners(newbies) with Guzzle Client.

By default, it is initialized by the Forodha constructor, so lets hide it there. What do you say?

This comment has been minimized.

Copy link
@alphaolomi

alphaolomi Oct 13, 2020

Author Member

Strong point there, after finishing the example i noticed its getting long

This comment has been minimized.

Copy link
@alphaolomi

alphaolomi Oct 13, 2020

Author Member

will make it more concise

'timeout' => 300,
'headers' => [
'Accept' => 'application/json',
'Origin' => '*'
]
]);

$forodha = new Forodha([
'api_key' => $apiKey,
'public_key' => $publicKey,
'username' => $username,
'auth_url' => $authUrl,
], $client);


$data = [
'input_Amount' => 5000,
'input_CustomerMSISDN' => '000000000001',
'input_Country' => 'TZN',
'input_Currency' => 'TZS',
'input_ServiceProviderCode' => '000000',
'input_TransactionReference' => 'T12344Z',
'input_ThirdPartyConversationID' => '1e9b774d1da34af78412a498cbc28f5d',
'input_PurchasedItemsDesc' => 'Test Three Item'
];


try {
$result = $forodha->transact('c2b', $data);
print_r($result);
} catch (\Throwable $th) {
echo $th->getMessage();
}

0 comments on commit 4d91304

Please sign in to comment.