Skip to content

Commit fe09887

Browse files
committed
Wallet balance improvement and deferred mobile money collection
1 parent e19a8ae commit fe09887

File tree

5 files changed

+98
-5
lines changed

5 files changed

+98
-5
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 jilenloa
3+
Copyright (c) 2023 jilenloa
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This library makes it easy for PHP developers to integrate with One4All TPP onli
99

1010
It's supported on PHP 5.5+
1111

12+
## Using the Library
1213
```php
1314
use MyOne4All\TppClient;
1415
use MyOne4All\Exceptions\TppException;
@@ -17,16 +18,33 @@ use MyOne4All\NetworkCodes;
1718

1819
$tppClient = new TppClient("apikey", "apisecret", "retailer");
1920

21+
```
22+
23+
## Get Balance
24+
```php
25+
# ecredit balance
2026
echo $tppClient->getBalance(); # 0.0
2127

28+
# mobile money collection balance
29+
echo $tppClient->getBalance(TppClient::WALLET_TYPE_MOBILE_MONEY_COLLECTION); # 0.0
30+
31+
# mobile money credit balance
32+
echo $tppClient->getBalance(TppClient::WALLET_TYPE_MOBILE_MONEY_CREDIT); # 0.0
33+
```
34+
35+
## Send Airtime
36+
```php
2237
// send airtime implementation
2338
$airtime_response = $tppClient->sendAirtime("0245667942", 1, "trans03423423", NetworkCodes::AUTO_DETECT);
2439
if($airtime_response->isSuccessful()){
2540
echo "airtime sent";
2641
}else{
2742
echo "Failed: ".$airtime_response->getErrorMessage();
2843
}
44+
```
2945

46+
## Send Data Bundle
47+
```php
3048
// send internet data implementation
3149
$data_code = "DAILY_20MB";
3250
$transaction_reference = "trans03423423";
@@ -36,7 +54,24 @@ if($bundle_response->isSuccessful()){
3654
}else{
3755
echo "Failed: ".$bundle_response->getErrorMessage();
3856
}
57+
```
58+
59+
## Send Flexi Data Bundle
60+
```php
61+
// send internet data implementation
62+
$data_code = "flexi_data_bundle";
63+
$transaction_reference = "trans03423423";
64+
$amount = 10;
65+
$bundle_response = $tppClient->sendFlexiDataBundle("0245667942", $amount, $data_code, $transaction_reference, NetworkCodes::MTN_GH);
66+
if($bundle_response->isSuccessful()){
67+
echo "internet bundle sent";
68+
}else{
69+
echo "Failed: ".$bundle_response->getErrorMessage();
70+
}
71+
```
3972

73+
## Send Mobile Money
74+
```php
4075

4176
// send mobile money implementation
4277
$transaction_reference = "trans03423423";
@@ -51,7 +86,10 @@ if($momo_response->isSuccessful()){
5186
}else{
5287
echo "Failed: ".$momo_response->getErrorMessage();
5388
}
89+
```
5490

91+
## Receive Mobile Money
92+
```php
5593
// receive mobile money implementation
5694
$transaction_reference = "trans03423423";
5795
$amount = 1;
@@ -63,7 +101,27 @@ if($momo_response->isSuccessful()){
63101
}else{
64102
echo "Failed: ".$momo_response->getErrorMessage();
65103
}
104+
```
105+
## Receive Mobile Money on USSD
106+
When working with USSD sessions, it is important there is a delay between the closing of the current session and the payment prompt. Use the delay parameter to specify the number of seconds to delay the payment prompt after the current USSD session ends.
107+
```php
108+
// receive mobile money implementation
109+
$transaction_reference = "trans03423423";
110+
$amount = 1;
111+
$payer_number = "0245667XXX";
112+
// the last parameter represents the number of seconds to delay the payment prompt
113+
$momo_response = $tppClient->receiveMobileMoney($payer_number, $amount, $transaction_reference, 5);
114+
if($momo_response->isSuccessful()){
115+
// check transaction status later to confirm receipt
116+
echo "mobile money payment request initiated";
117+
}else{
118+
echo "Failed: ".$momo_response->getErrorMessage();
119+
}
120+
```
121+
122+
## Send SMS
66123

124+
```php
67125
$sms_message = "hello world";
68126
$sms_sender_id = "One4All";
69127
$transaction_reference = "sms11";
@@ -74,7 +132,11 @@ if($sms_response->isSuccessful()){
74132
echo "Failed: ".$sms_response->getErrorMessage();
75133
}
76134

135+
```
77136

137+
## Query Bundle List
138+
We recommend you cache this list for at least 24 hours to avoid unnecessary API calls.
139+
```php
78140

79141
echo NetworkCodes::AUTO_DETECT; # 0
80142
echo NetworkCodes::MTN_GH; # 4

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jilenloa/tppmyone4all-php",
33
"description": "PHP Library to integration myone4all tpp service easily",
4-
"version": "0.0.6",
4+
"version": "1.0.0",
55
"type": "library",
66
"license": "MIT",
77
"authors": [

src/NetworkCodes.php

+8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ class NetworkCodes
1313
{
1414
const AUTO_DETECT = 0;
1515

16+
/**
17+
* @deprecated
18+
*/
1619
const AIRTEL_GH = 1;
20+
const AT_GH = 1;
1721
const EXPRESSO_GH = 2;
1822
const GLO_GH = 3;
1923
const MTN_GH = 4;
24+
25+
/**
26+
* @deprecated
27+
*/
2028
const TIGO_GH = 5;
2129
const VODAFONE_GH = 6;
2230

src/TppClient.php

+26-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class TppClient
2525

2626
const COUNTRY_GHANA = 'gh';
2727
const COUNTRY_CONGO = 'drc';
28+
const WALLET_TYPE_ECREDIT = 'e-credit';
29+
const WALLET_TYPE_MOBILE_MONEY_CREDIT = 'mobile-money-credit-account';
30+
const WALLET_TYPE_MOBILE_MONEY_COLLECTION = 'mobile-money-collection-account';
2831

2932
/**
3033
* Client constructor.
@@ -71,8 +74,8 @@ private function getHttpClient(){
7174
* @return string|double
7275
* @throws ClientException
7376
*/
74-
public function getBalance(){
75-
$response = $this->getHttpClient()->get("/api/TopUpApi/balance");
77+
public function getBalance($wallet_type = self::WALLET_TYPE_ECREDIT){
78+
$response = $this->getHttpClient()->get("/api/TopUpApi/balance?type={$wallet_type}");
7679
$response_array = json_decode($response->getBody()->getContents(), true);
7780
return $response_array['balance'];
7881
}
@@ -119,6 +122,21 @@ public function sendDataBundle($recipient, $data_code, $transaction_reference, $
119122
return new TppResponse($response_array);
120123
}
121124

125+
public function sendFlexiDataBundle($recipient, $amount, $data_code, $transaction_reference, $network){
126+
$params = array(
127+
'retailer' => $this->retailer,
128+
'recipient' => $recipient,
129+
'data_code' => $data_code,
130+
'network' => $network,
131+
'trxn' => $transaction_reference,
132+
'amount' => $amount
133+
);
134+
135+
$response = $this->getHttpClient()->get("/api/TopUpApi/dataBundle?".http_build_query($params));
136+
$response_array = json_decode($response->getBody()->getContents(), true);
137+
return new TppResponse($response_array);
138+
}
139+
122140
/**
123141
* @param $recipient
124142
* @param $amount
@@ -141,15 +159,20 @@ public function sendMobileMoney($recipient, $amount, $transaction_reference){
141159
* @param $payer_number
142160
* @param $amount
143161
* @param $transaction_reference
162+
* @param int $delay_seconds
144163
* @return TppResponse
145164
* @throws ClientException
146165
*/
147-
public function receiveMobileMoney($payer_number, $amount, $transaction_reference){
166+
public function receiveMobileMoney($payer_number, $amount, $transaction_reference, $delay_seconds = 0){
148167
$params = array(
149168
'amount' => $amount,
150169
'recipient' => $payer_number,
151170
'trxn' => $transaction_reference
152171
);
172+
173+
if($delay_seconds && $delay_seconds > 0){
174+
$params['delay'] = $delay_seconds;
175+
}
153176
$response = $this->getHttpClient()->get("/api/TopUpApi/c2b?".http_build_query($params));
154177
$response_array = json_decode($response->getBody()->getContents(), true);
155178
return new TppResponse($response_array);

0 commit comments

Comments
 (0)