-
Notifications
You must be signed in to change notification settings - Fork 12
/
MaibClient.php
247 lines (225 loc) · 10 KB
/
MaibClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
namespace Fruitware\MaibApi;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Command\Guzzle\DescriptionInterface;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
use GuzzleHttp\Event\CompleteEvent;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Message\Response;
use GuzzleHttp\Stream\Stream;
class MaibClient extends GuzzleClient
{
/**
* @param ClientInterface $client
* @param DescriptionInterface $description
* @param array $config
*/
public function __construct(ClientInterface $client = null, DescriptionInterface $description = null, array $config = [])
{
$client = $client instanceof ClientInterface ? $client : new Client();
$description = $description instanceof DescriptionInterface ? $description : new MaibDescription();
parent::__construct($client, $description, $config);
$cachedResponse = new Response(200);
$this->getHttpClient()->getEmitter()->on(
'complete',
function (CompleteEvent $e) use ($cachedResponse) {
$array1 = explode(PHP_EOL, trim((string)$e->getResponse()->getBody()));
$result = array();
foreach($array1 as $key => $value) {
$array2 = explode(':', $value);
$result[$array2[0]] = isset($array2[1])? trim( $array2[1] ) : '';
}
$stream = Stream::factory(json_encode($result));
$cachedResponse->setBody($stream);
$e->intercept($cachedResponse);
}
);
}
/**
* @param string $name
* @param array $arguments
*
* @return array
* @throws BadResponseException
* @throws \Exception
*/
public function __call($name, array $arguments)
{
try {
$response = parent::__call($name, $arguments);
return json_decode($response['additionalProperties'], true);
}
catch (\Exception $ex) {
throw $ex;
}
}
/**
* Registering transactions
* @param float $amount
* @param int $currency
* @param string $clientIpAddr
* @param string $description
* @param string $language
* start SMS transaction. This is simplest form that charges amount to customer instantly.
* @return array TRANSACTION_ID
* TRANSACTION_ID - transaction identifier (28 characters in base64 encoding)
* error - in case of an error
*/
public function registerSmsTransaction($amount, $currency, $clientIpAddr, $description = '', $language = 'ru')
{
$args = [
'command' => 'v',
'amount' => (string)($amount * 100),
'msg_type' => 'SMS',
'currency' => (string)$currency,
'client_ip_addr' => $clientIpAddr,
'description' => $description,
'language' => $language
];
return parent::registerSmsTransaction($args);
}
/**
* Registering DMS authorization
* * @param float $amount
* * @param int $currency
* * @param string $clientIpAddr
* * @param string $description
* * @param string $language
* DMS is different from SMS, dms_start_authorization blocks amount, and than we use dms_make_transaction to charge customer.
* @return array TRANSACTION_ID
* TRANSACTION_ID - transaction identifier (28 characters in base64 encoding)
* error - in case of an error
*/
public function registerDmsAuthorization($amount, $currency, $clientIpAddr, $description = '', $language = 'ru')
{
$args = [
'command' => 'a',
'amount' => (string)($amount * 100),
'currency' => (string)$currency,
'msg_type' => 'DMS',
'client_ip_addr' => $clientIpAddr,
'description' => $description,
'language' => $language
];
return parent::registerDmsAuthorization($args);
}
/**
* Executing a DMS transaction
* @param string $authId
* @param float $amount
* @param int $currency
* @param string $clientIpAddr
* @param string $description
* @param string $language
* @return array RESULT, RESULT_CODE, BRN, APPROVAL_CODE, CARD_NUMBER, error
* RESULT - transaction results: OK - successful transaction, FAILED - failed transaction
* RESULT_CODE - transaction result code returned from Card Suite Processing RTPS (3 digits)
* BRN - retrieval reference number returned from Card Suite Processing RTPS (12 characters)
* APPROVAL_CODE - approval code returned from Card Suite Processing RTPS (max 6 characters)
* CARD_NUMBER - masked card number
* error - in case of an error
*/
public function makeDMSTrans($authId, $amount, $currency, $clientIpAddr, $description = '', $language = 'ru'){
$args = [
'command' => 't',
'trans_id' => $authId,
'amount' => (string)($amount * 100),
'currency' => (string)$currency,
'client_ip_addr' => $clientIpAddr,
'msg_type' => 'DMS',
'description' => $description,
'language' => $language
];
return parent::makeDMSTrans($args);
}
/**
* Transaction result
* @param string $transId
* @param string $clientIpAddr
* @return array RESULT, RESULT_PS, RESULT_CODE, 3DSECURE, RRN, APPROVAL_CODE, CARD_NUMBER, AAV, RECC_PMNT_ID, RECC_PMNT_EXPIRY, MRCH_TRANSACTION_ID
* RESULT - OK - successfully completed transaction,
* FAILED - transaction has failed,
* CREATED - transaction just registered in the system,
* PENDING - transaction is not accomplished yet,
* DECLINED - transaction declined by ECOMM,
* REVERSED - transaction is reversed,
* AUTOREVERSED - transaction is reversed by autoreversal,
* TIMEOUT - transaction was timed out
* RESULT_PS - transaction result, Payment Server interpretation (shown only if configured to return ECOMM2 specific details
* FINISHED - successfully completed payment,
* CANCELLED - cancelled payment,
* RETURNED - returned payment,
* ACTIVE - registered and not yet completed payment.
* RESULT_CODE - transaction result code returned from Card Suite Processing RTPS (3 digits)
* 3DSECURE - AUTHENTICATED - successful 3D Secure authorization
* DECLINED - failed 3D Secure authorization
* NOTPARTICIPATED - cardholder is not a member of 3D Secure scheme
* NO_RANGE - card is not in 3D secure card range defined by issuer
* ATTEMPTED - cardholder 3D secure authorization using attempts ACS server
* UNAVAILABLE - cardholder 3D secure authorization is unavailable
* ERROR - error message received from ACS server
* SYSERROR - 3D secure authorization ended with system error
* UNKNOWNSCHEME - 3D secure authorization was attempted by wrong card scheme (Dinners club, American Express)
* RRN - retrieval reference number returned from Card Suite Processing RTPS
* APPROVAL_CODE - approval code returned from Card Suite Processing RTPS (max 6 characters)
* CARD_NUMBER - Masked card number
* AAV - FAILED the results of the verification of hash value in AAV merchant name (only if failed)
* RECC_PMNT_ID - Reoccurring payment (if available) identification in Payment Server.
* RECC_PMNT_EXPIRY - Reoccurring payment (if available) expiry date in Payment Server in form of YYMM
* MRCH_TRANSACTION_ID - Merchant Transaction Identifier (if available) for Payment - shown if it was sent as additional parameter on Payment registration.
* The RESULT_CODE and 3DSECURE fields are informative only and can be not shown. The fields RRN and APPROVAL_CODE appear for successful transactions only, for informative purposes, and they facilitate tracking the transactions in Card Suite Processing RTPS system.
* error - In case of an error
* warning - In case of warning (reserved for future use).
*/
public function getTransactionResult($transId, $clientIpAddr)
{
$args = [
'command' => 'c',
'trans_id' => $transId,
'client_ip_addr' => $clientIpAddr,
];
return parent::getTransactionResult($args);
}
/**
* Transaction reversal
* @param string $transId
* @param string $amount reversal amount in fractional units (up to 12 characters). For DMS authorizations only full amount can be reversed, i.e., the reversal and authorization amounts have to match. In other cases partial reversal is also available.
* @return array RESULT, RESULT_CODE
* RESULT - OK - successful reversal transaction
* REVERSED - transaction has already been reversed
* FAILED - failed to reverse transaction (transaction status remains as it was)
* RESULT_CODE - reversal result code returned from Card Suite Processing RTPS (3 digits)
* error - In case of an error
* warning - In case of warning (reserved for future use).
*/
public function revertTransaction($transId, $amount)
{
$args = array(
'command' => 'r',
'trans_id' => $transId,
'amount' => (string)($amount * 100),
);
return parent::revertTransaction($args);
}
/**
* needs to be run once every 24 hours.
* this tells bank to process all transactions of that day SMS or DMS that were success
* in case of DMS only confirmed and sucessful transactions will be processed
* @return array RESULT, RESULT_CODE, FLD_075, FLD_076, FLD_087, FLD_088
* RESULT - OK - successful end of business day
* FAILED - failed end of business day
* RESULT_CODE - end-of-business-day code returned from Card Suite Processing RTPS (3 digits)
* FLD_075 - the number of credit reversals (up to 10 digits), shown only if result_code begins with 5
* FLD_076 - the number of debit transactions (up to 10 digits), shown only if result_code begins with 5
* FLD_087 - total amount of credit reversals (up to 16 digits), shown only if result_code begins with 5
* FLD_088 - total amount of debit transactions (up to 16 digits), shown only if result_code begins with 5
*/
public function closeDay()
{
$args = [
'command' => 'b',
];
return parent::closeDay($args);
}
}