-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): added pesa demo example
- Loading branch information
1 parent
bda2517
commit 4d91304
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
USERNAME=sandbox | ||
PUBLICKEY= | ||
AUTHURL= | ||
APIKEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
alphaolomi
Author
Member
|
||
'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(); | ||
} |
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?