Skip to content

Commit 06bc618

Browse files
committed
GCASH model created and unit test for that model
1 parent 807ddb4 commit 06bc618

File tree

4 files changed

+470
-47
lines changed

4 files changed

+470
-47
lines changed

WebService/Model/GCashModel.php

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
3+
/**
4+
* First Global Data
5+
*
6+
* @category DEX_API
7+
* @package Api\WebServiceBundle\Tests\Controller
8+
* @author Anit Shrestha Manandhar <[email protected]>
9+
* @license http://firstglobalmoney.com/license description
10+
* @version v1.0.0
11+
* @link (remittanceController, http://firsglobaldata.com)
12+
*/
13+
14+
namespace Model;
15+
16+
use Model\TransactionModel as Transaction;
17+
use Model\WebServiceModel as WebService;
18+
19+
/**
20+
* Bridge to call TB DBAL
21+
*
22+
* @category DEX_API
23+
* @package Api\WebServiceBundle\Tests\Controller
24+
* @author Anit Shrestha Manandhar <[email protected]>
25+
* @license http://firstglobalmoney.com/license Usage License
26+
* @version v1.0.0
27+
* @link (remittanceController, http://firsglobaldata.com)
28+
*/
29+
30+
class GCashModel extends WebService
31+
{
32+
33+
private $_transactionObj;
34+
private $_check;
35+
36+
/**
37+
* If sets Dex parameter to $parameter variable and checks if the transaction existes for refNo from that parameter
38+
*
39+
* @param array $postParameters Dex parameter
40+
*
41+
* @return void
42+
*/
43+
public function __construct($postParameters)
44+
{
45+
$this->parameters = $postParameters;
46+
$this->_transactionObj = new Transaction();
47+
$this->_check = $this->checkRefNoTransactionExists($postParameters['refNo']);
48+
}
49+
50+
/**
51+
* Show remittance details.
52+
*
53+
* @return void
54+
*/
55+
public function showRemittanceDetail()
56+
{
57+
if ($this->_check==true) {
58+
59+
if ($this->return['status'] == 'approved') {
60+
$this->formatReturnData('showApproved');
61+
62+
} elseif ($this->return['status'] == 'paid') {
63+
$this->formatReturnData('showPaid');
64+
65+
} else {
66+
$this->return = '3';
67+
}
68+
}
69+
70+
}
71+
72+
/**
73+
* Checks if status is approved then updates status to Paid
74+
*
75+
* @return void
76+
*/
77+
public function tagAsCompleted()
78+
{
79+
if ($this->_check==true) {
80+
81+
if ($this->return['status'] == 'approved') {
82+
$this->_transactionObj->connection->update('f1_transactions', array('status' => 'paid'), array('control_number' => $this->return['control_number']));
83+
$this->formatReturnData('update');
84+
85+
86+
} elseif ($this->return['status'] == 'paid') {
87+
$this->return = '2';
88+
89+
} else {
90+
$this->return = '3';
91+
92+
}
93+
}
94+
}
95+
/**
96+
* It checks if status is Paid or not in Transaction Table
97+
*
98+
* @return void
99+
*/
100+
public function inquireTagAsCompleted()
101+
{
102+
if ($this->_check==true) {
103+
104+
if ($this->return['status'] == 'paid') {
105+
$this->formatReturnData('update');
106+
} else {
107+
$this->return = '1';
108+
}
109+
}
110+
}
111+
112+
/**
113+
* [checkRefNoTransactionExists description]
114+
*
115+
* @param varchar $refNo reference number
116+
*
117+
* @return void
118+
*/
119+
public function checkRefNoTransactionExists($refNo)
120+
{
121+
$this->return = $this->_transactionObj->connection->fetchAssoc('SELECT f.status,f.control_number,f.remitting_amount,fc.firstName,fc.lastName,fc.middleName,fc.phone,fc.street FROM f1_transactions f JOIN f1_customer fc ON fc.id=f.beneficiary_id WHERE f.control_number = ?', array($refNo));
122+
$state=count($this->return);
123+
if ($state<2) {
124+
$this->return = '4';
125+
}
126+
return ($state<2)?false:true;
127+
}
128+
129+
/**
130+
* Set return data to error code 5 for incorrect username and password
131+
*
132+
* @return void
133+
*/
134+
public function getUnAuthorizedData()
135+
{
136+
$this->return ='5';
137+
}
138+
139+
/**
140+
* sets return variable to GCASH formated string according to $type
141+
*
142+
* @param string $type update/get/check
143+
*
144+
* @return void
145+
*/
146+
public function formatReturnData($type)
147+
{
148+
if ($type=='showApproved') {
149+
$this->return=$this->return['control_number'].'|0|'.$this->return['remitting_amount'].'|'.$this->return['lastName'].'|'.$this->return['firstName'].'|'.
150+
$this->return['middleName'].'|null|null|null|'.$this->return['street'].'|'.$this->return['phone'];
151+
}
152+
if ($type=='showPaid') {
153+
$this->return=$this->return['control_number'].'|1|'.$this->return['remitting_amount'].'|'.$this->return['lastName'].'|'.$this->return['firstName'].'|'.
154+
$this->return['middleName'].'|null|null|null|'.$this->return['street'].'|'.$this->return['phone'];
155+
}
156+
if ($type=='update') {
157+
$this->return=$this->parameters['traceNo'].'|'.$this->return['control_number'].'|0|'.$this->return['remitting_amount'].'|'.$this->return['lastName'].'|'.
158+
$this->return['firstName'].'|'.$this->return['middleName'].'|null|null|null|'.$this->return['street'].'|'.$this->return['phone'];
159+
}
160+
161+
}
162+
163+
/**
164+
* set return data
165+
*
166+
* @return string
167+
*/
168+
public function getReturn()
169+
{
170+
return $this->return;
171+
}
172+
}

WebService/Model/MLhuillierModel.php

Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@
3030
class MLhuillierModel extends WebService
3131
{
3232

33-
private $transactionObj;
34-
private $check;
33+
private $_transactionObj;
34+
private $_check;
3535

36+
/**
37+
* If sets Dex parameter to $parameter variable and checks if the transaction existes for refNo from that parameter
38+
*
39+
* @param array $postParameters Dex parameter
40+
*
41+
* @return void
42+
*/
3643
public function __construct($postParameters)
3744
{
3845
$this->parameters = $postParameters;
39-
$this->transactionObj = new Transaction();
40-
$this->check = $this->checkRefNoTransactionExists($postParameters['refNo']);
46+
$this->_transactionObj = new Transaction();
47+
$this->_check = $this->checkRefNoTransactionExists($postParameters['refNo']);
4148
}
4249

4350
/**
@@ -47,94 +54,117 @@ public function __construct($postParameters)
4754
*/
4855
public function showRemittanceDetail()
4956
{
50-
if($this->check==true)
51-
{
52-
if ($this->return['status'] == 'approved') {
53-
$this->formatReturnData('get');
57+
if ($this->_check==true) {
5458

55-
} elseif ($this->return['status'] == 'paid') {
56-
$this->return = $this->parameters['sessionID'].'|1';
59+
if ($this->return['status'] == 'approved') {
60+
$this->formatReturnData('get');
5761

58-
} else {
62+
} elseif ($this->return['status'] == 'paid') {
63+
$this->return = $this->parameters['sessionID'].'|1';
64+
65+
} else {
5966
$this->return = $this->parameters['sessionID'] .'|3';
60-
}
6167
}
68+
}
6269

6370
}
6471

72+
/**
73+
* Checks if status is approved then updates status to Paid
74+
*
75+
* @return void
76+
*/
6577
public function tagAsCompleted()
6678
{
67-
if($this->check==true)
68-
{
69-
if ($this->return['status'] == 'approved') {
70-
$this->transactionObj->connection->update('f1_transactions', array('status' => 'paid'), array('control_number' => $this->return['control_number']));
79+
if ($this->_check==true) {
80+
81+
if ($this->return['status'] == 'approved') {
82+
$this->_transactionObj->connection->update('f1_transactions', array('status' => 'paid'), array('control_number' => $this->return['control_number']));
7183
$this->formatReturnData('update');
7284

7385

74-
} elseif ($this->return['status'] == 'paid') {
86+
} elseif ($this->return['status'] == 'paid') {
7587
$this->return = $this->parameters['sessionID'].'|2';
7688

77-
} else {
89+
} else {
7890
$this->return = $this->parameters['sessionID'].'|3';
7991

80-
}
8192
}
93+
}
8294
}
83-
95+
/**
96+
* It checks if status is Paid or not in Transaction Table
97+
*
98+
* @return void
99+
*/
84100
public function inquireTagAsCompleted()
85101
{
86-
if($this->check==true)
87-
{
88-
if ($this->return['status'] == 'paid') {
102+
if ($this->_check==true) {
103+
104+
if ($this->return['status'] == 'paid') {
89105
$this->formatReturnData('check');
90-
} else {
91-
$this->return = $this->parameters['sessionID'].'|3';
92-
}
106+
} else {
107+
$this->return = $this->parameters['sessionID'].'|1';
93108
}
109+
}
94110
}
95111

112+
/**
113+
* [checkRefNoTransactionExists description]
114+
*
115+
* @param varchar $refNo reference number
116+
*
117+
* @return void
118+
*/
96119
public function checkRefNoTransactionExists($refNo)
97120
{
98-
$this->return = $this->transactionObj->connection->fetchAssoc('SELECT c.name,f.status,f.control_number,f.remitting_amount,fc.firstName,fc.lastName,fc.middleName,fc.mobile,fc.street FROM f1_transactions f JOIN f1_customer fc ON fc.id=f.beneficiary_id JOIN f1_currencies c ON c.id=f.receiving_currency_id WHERE f.control_number = ?', array($refNo));
121+
$this->return = $this->_transactionObj->connection->fetchAssoc('SELECT c.name,f.status,f.control_number,f.remitting_amount,fc.firstName,fc.lastName,fc.middleName,fc.mobile,fc.street FROM f1_transactions f JOIN f1_customer fc ON fc.id=f.beneficiary_id JOIN f1_currencies c ON c.id=f.receiving_currency_id WHERE f.control_number = ?', array($refNo));
99122
$state=count($this->return);
100-
if($state<2)
101-
{
123+
if ($state<2) {
102124
$this->return = $this->parameters['sessionID'].'|4';
103-
104-
}
125+
}
105126
return ($state<2)?false:true;
106127
}
107128

129+
/**
130+
* Set return data to error code 5 for incorrect username and password
131+
*
132+
* @return void
133+
*/
108134
public function getUnAuthorizedData()
109135
{
110136
$this->return = $this->parameters['sessionID'] .'|5';
111137
}
112138

113139
/**
114-
* Set return data
140+
* sets return variable to Mulhiller formated string according to $type
115141
*
142+
* @param string $type update/get/check
143+
*
116144
* @return void
117145
*/
118146
public function formatReturnData($type)
119147
{
120-
if($type=='update')
121-
{
148+
if ($type=='update') {
122149
$this->return=$this->parameters['sessionID'].'|0|'.$this->parameters['traceNo'].'|'.$this->return['control_number'].'|'.$this->return['remitting_amount'].'|'.$this->return['name'].'|'.$this->return['lastName'].'|'.$this->return['firstName'].'|'.
123150
$this->return['middleName'].'|'.$this->return['street'].'|zero';
124151
}
125-
if($type=='get')
126-
{
152+
if ($type=='get') {
127153
$this->return= $this->parameters['sessionID'].'|0|'.$this->return['control_number'].'|'.$this->return['remitting_amount'].'|'.$this->return['name'].'|'.$this->return['lastName'].'|'.$this->return['firstName'].'|'.
128154
$this->return['middleName'].'|'.$this->return['street'].'|'.$this->return['mobile'];
129155
}
130-
if($type=='check')
131-
{
156+
if ($type=='check') {
132157
$this->return=$this->parameters['sessionID'].'|0|'.$this->parameters['traceNo'].'|'.$this->return['control_number'].'|'.$this->return['remitting_amount'].'|'.$this->return['name'].'|'.$this->return['lastName'].'|'.$this->return['firstName'].'|'.
133158
$this->return['middleName'].'|'.$this->return['street'].'|zero';
134159
}
135160

136161
}
137162

163+
/**
164+
* set return data
165+
*
166+
* @return string
167+
*/
138168
public function getReturn()
139169
{
140170
return $this->return;

0 commit comments

Comments
 (0)