|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\Omnipay\PlatiOnline\Message; |
|
4
|
|
|
|
|
5
|
|
|
use ByTIC\Omnipay\PlatiOnline\Utils\Urls; |
|
6
|
|
|
use Omnipay\Common\Item; |
|
7
|
|
|
use Omnipay\Common\ItemBag; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class AuthorizeRequest |
|
11
|
|
|
* @package ByTIC\Omnipay\PlatiOnline\Message |
|
12
|
|
|
* |
|
13
|
|
|
* @method AuthorizeResponse send |
|
14
|
|
|
*/ |
|
15
|
|
|
class AuthorizeRequest extends AbstractRequest |
|
16
|
|
|
{ |
|
17
|
|
|
use Traits\HasSoapRequestTrait; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @return array |
|
21
|
|
|
* @throws \Omnipay\Common\Exception\InvalidRequestException |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getData(): array |
|
24
|
|
|
{ |
|
25
|
|
|
$this->validate('publicKey', 'loginId', 'website', 'amount', 'card'); |
|
26
|
|
|
$this->validateCard( |
|
27
|
|
|
'BillingPhone', |
|
28
|
|
|
'FirstName', |
|
29
|
|
|
'LastName', |
|
30
|
|
|
'BillingCountry', |
|
31
|
|
|
'BillingCity', |
|
32
|
|
|
'ShippingPhone', |
|
33
|
|
|
'ShippingCountry', |
|
34
|
|
|
'ShippingCity' |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
$data = []; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
$data['f_website'] = $this->getWebsite(); |
|
41
|
|
|
|
|
42
|
|
|
$data['f_order_number'] = $this->getTransactionId(); |
|
43
|
|
|
$data['f_order_string'] = $this->getDescription(); |
|
44
|
|
|
$data['f_amount'] = $this->getAmount(); |
|
45
|
|
|
$data['f_currency'] = $this->getCurrency(); |
|
46
|
|
|
|
|
47
|
|
|
// 0 - waiting forever, 20 - default (in minutes) |
|
48
|
|
|
$data['f_auth_minutes'] = 20; |
|
49
|
|
|
$data['f_language'] = $this->getLang(); // RO / EN / HU / IT / FR / DE / ES |
|
50
|
|
|
|
|
51
|
|
|
$data['customer_info'] = $this->generateCustomerInfo(); |
|
52
|
|
|
$data['shipping_info'] = $this->generateShippingInfo(); |
|
53
|
|
|
$data['transaction_relay_response'] = $this->generateRelayResponse(); |
|
54
|
|
|
|
|
55
|
|
|
//$f_request['tracking_script'] = 'tracking script'; |
|
56
|
|
|
|
|
57
|
|
|
$data['f_order_cart'] = $this->generateOrderCart(); |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
//shipping |
|
61
|
|
|
// $shipping = array(); |
|
62
|
|
|
// $shipping['name'] = substr('Shipping 1', 0, 250); |
|
63
|
|
|
// $shipping['price'] = (float)15.5; |
|
64
|
|
|
// $shipping['pimg'] = 0; |
|
65
|
|
|
// $shipping['vat'] = (float)2.5; |
|
66
|
|
|
// |
|
67
|
|
|
// $f_request['f_order_cart']['shipping'] = $shipping; |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
return $data; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function generateCustomerInfo(): array |
|
74
|
|
|
{ |
|
75
|
|
|
$card = $this->getCard(); |
|
76
|
|
|
|
|
77
|
|
|
$customerInfo = []; |
|
78
|
|
|
|
|
79
|
|
|
// must not be empty. If empty don't send this tag, it will be filled in PO interface |
|
80
|
|
|
$customerInfo['contact']['f_email'] = $card->getEmail(); |
|
81
|
|
|
|
|
82
|
|
|
// must not be empty, minimum 4 characters. If empty don't send this tag, it will be filled in PO interface |
|
83
|
|
|
$phone = $card->getBillingPhone(); |
|
84
|
|
|
$phone = $phone ? $phone : '----'; |
|
85
|
|
|
$customerInfo['contact']['f_phone'] = $phone; |
|
86
|
|
|
|
|
87
|
|
|
$customerInfo['contact']['f_mobile_number'] = $phone; |
|
88
|
|
|
|
|
89
|
|
|
// 1 - sms client notification 0 - no notification |
|
90
|
|
|
$customerInfo['contact']['f_send_sms'] = 1; |
|
91
|
|
|
|
|
92
|
|
|
// must not be empty. If empty don't send this tag, it will be filled in PO interface |
|
93
|
|
|
$customerInfo['contact']['f_first_name'] = $card->getBillingFirstName(); |
|
94
|
|
|
$customerInfo['contact']['f_last_name'] = $card->getBillingLastName(); |
|
95
|
|
|
//$customer_info['contact']['f_middle_name'] = ''; |
|
96
|
|
|
|
|
97
|
|
|
//invoice |
|
98
|
|
|
// $customer_info['invoice']['f_company'] = 'Test company'; // optional |
|
99
|
|
|
// $customer_info['invoice']['f_cui'] = '111111'; // optional |
|
100
|
|
|
// $customer_info['invoice']['f_reg_com'] = 'J55/99/2000'; // optional |
|
101
|
|
|
// $customer_info['invoice']['f_cnp'] = '9999999999999'; // optional |
|
102
|
|
|
// $customer_info['invoice']['f_zip'] = '999999'; // optional |
|
103
|
|
|
|
|
104
|
|
|
// must not be empty. If empty don't send this tag, it will be filled in PO interface |
|
105
|
|
|
$customerInfo['invoice']['f_country'] = $card->getBillingCountry(); |
|
106
|
|
|
|
|
107
|
|
|
// must not be empty. If empty don't send this tag, it will be filled in PO interface |
|
108
|
|
|
$state = $card->getBillingState(); |
|
109
|
|
|
$state = $state ? $state : '-'; |
|
110
|
|
|
$customerInfo['invoice']['f_state'] = $state; |
|
111
|
|
|
|
|
112
|
|
|
// must not be empty. If empty don't send this tag, it will be filled in PO interface |
|
113
|
|
|
$city = $card->getBillingCity(); |
|
114
|
|
|
$city = $city ? $city : '-'; |
|
115
|
|
|
$customerInfo['invoice']['f_city'] = $city; |
|
116
|
|
|
|
|
117
|
|
|
// must not be empty. If empty don't send this tag, it will be filled in PO interface |
|
118
|
|
|
$address = $card->getBillingAddress1(); |
|
119
|
|
|
$address = $address ? $address : '-'; |
|
120
|
|
|
$customerInfo['invoice']['f_address'] = $address; |
|
121
|
|
|
|
|
122
|
|
|
return $customerInfo; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
protected function generateShippingInfo(): array |
|
126
|
|
|
{ |
|
127
|
|
|
$card = $this->getCard(); |
|
128
|
|
|
|
|
129
|
|
|
$shipping_info = []; |
|
130
|
|
|
|
|
131
|
|
|
// 0 - different info, 1- same info as customer_info |
|
132
|
|
|
$shipping_info['same_info_as'] = 0; |
|
133
|
|
|
|
|
134
|
|
|
//contact |
|
135
|
|
|
$shipping_info['contact']['f_email'] = $card->getEmail(); |
|
136
|
|
|
|
|
137
|
|
|
$phone = $card->getShippingPhone(); |
|
138
|
|
|
$phone = $phone ? $phone : '----'; |
|
139
|
|
|
$shipping_info['contact']['f_phone'] = $phone; |
|
140
|
|
|
$shipping_info['contact']['f_mobile_number'] = $phone; |
|
141
|
|
|
|
|
142
|
|
|
// 1 - sms client notification 0 - no notification |
|
143
|
|
|
$shipping_info['contact']['f_send_sms'] = 1; |
|
144
|
|
|
$shipping_info['contact']['f_first_name'] = $card->getShippingFirstName(); |
|
145
|
|
|
$shipping_info['contact']['f_last_name'] = $card->getShippingLastName(); |
|
146
|
|
|
//$shipping_info['contact']['f_middle_name'] = ''; |
|
147
|
|
|
|
|
148
|
|
|
//address |
|
149
|
|
|
$shipping_info['address']['f_company'] = $card->getShippingCompany(); |
|
150
|
|
|
$shipping_info['address']['f_zip'] = $card->getShippingPostcode(); |
|
151
|
|
|
$shipping_info['address']['f_country'] = $card->getShippingCountry(); |
|
152
|
|
|
|
|
153
|
|
|
$state = $card->getShippingState(); |
|
154
|
|
|
$state = $state ? $state : '-'; |
|
155
|
|
|
$shipping_info['address']['f_state'] = $state; |
|
156
|
|
|
|
|
157
|
|
|
$city = $card->getShippingCity(); |
|
158
|
|
|
$city = $city ? $city : '-'; |
|
159
|
|
|
$shipping_info['address']['f_city'] = $city; |
|
160
|
|
|
|
|
161
|
|
|
$address = $card->getBillingAddress1(); |
|
162
|
|
|
$address = $address ? $address : '-'; |
|
163
|
|
|
$shipping_info['address']['f_address'] = substr($address, 0, 100); |
|
164
|
|
|
|
|
165
|
|
|
return $shipping_info; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
protected function generateRelayResponse(): array |
|
169
|
|
|
{ |
|
170
|
|
|
$relayResponse = []; |
|
171
|
|
|
$relayResponse['f_relay_response_url'] = $this->getReturnUrl(); |
|
172
|
|
|
|
|
173
|
|
|
// INFO f_relay_method |
|
174
|
|
|
// PTOR, POST_S2S_PO_PAGE, POST_S2S_MT_PAGE, SOAP_PO_PAGE, SOAP_MT_PAGE |
|
175
|
|
|
$relayResponse['f_relay_method'] = 'POST_S2S_PO_PAGE'; |
|
176
|
|
|
$relayResponse['f_relay_method'] = 'PTOR'; |
|
177
|
|
|
|
|
178
|
|
|
// Valoarea = 1 (default value; sistemul PO trimite rezultatul la f_relay_response_url prin metoda f_relay_method) |
|
179
|
|
|
// Valoarea = 0 (systemul PO trimite rezultatul doar pentru tranzactiile "Autorizate" si "In curs de verificare" la <f_relay_response_url> prin metoda <f_relay_method>) |
|
180
|
|
|
$relayResponse['f_post_declined'] = 1; |
|
181
|
|
|
|
|
182
|
|
|
// default 1 |
|
183
|
|
|
$relayResponse['f_relay_handshake'] = 1; |
|
184
|
|
|
|
|
185
|
|
|
return $relayResponse; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
protected function generateOrderCart(): array |
|
189
|
|
|
{ |
|
190
|
|
|
/** @var Item[]|ItemBag $items */ |
|
191
|
|
|
$items = $this->getItems(); |
|
192
|
|
|
$orderCart = []; |
|
193
|
|
|
|
|
194
|
|
|
if (!($items instanceof ItemBag)) { |
|
195
|
|
|
$itemData['prodid'] = 0; |
|
|
|
|
|
|
196
|
|
|
$itemData['name'] = substr($this->getDescription(), 0, 250); |
|
197
|
|
|
$itemData['description'] = substr($this->getDescription(), 0, 250); |
|
198
|
|
|
$itemData['qty'] = 1; |
|
199
|
|
|
|
|
200
|
|
|
// price WITOUT VAT for 1 piece of the product |
|
201
|
|
|
$itemData['itemprice'] = (float)$this->getAmount(); |
|
202
|
|
|
|
|
203
|
|
|
// VAT for 1 piece of the product * $item['qty'] |
|
204
|
|
|
$itemData['vat'] = (float)0; |
|
205
|
|
|
|
|
206
|
|
|
$itemData['stamp'] = date('Y-m-d'); |
|
207
|
|
|
$itemData['prodtype_id'] = 0; |
|
208
|
|
|
|
|
209
|
|
|
$orderCart[] = $itemData; |
|
210
|
|
|
|
|
211
|
|
|
return $orderCart; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
foreach ($items as $item) { |
|
215
|
|
|
$itemData = []; |
|
216
|
|
|
|
|
217
|
|
|
$itemData['prodid'] = 0; |
|
218
|
|
|
$itemData['name'] = substr($item->getName(), 0, 250); |
|
219
|
|
|
$itemData['description'] = substr($item->getDescription(), 0, 250); |
|
220
|
|
|
$itemData['qty'] = $item->getQuantity(); |
|
221
|
|
|
|
|
222
|
|
|
// price WITOUT VAT for 1 piece of the product |
|
223
|
|
|
$itemData['itemprice'] = (float)$item->getPrice(); |
|
224
|
|
|
|
|
225
|
|
|
// VAT for 1 piece of the product * $item['qty'] |
|
226
|
|
|
$itemData['vat'] = (float)0; |
|
227
|
|
|
|
|
228
|
|
|
$itemData['stamp'] = date('Y-m-d'); |
|
229
|
|
|
$itemData['prodtype_id'] = 0; |
|
230
|
|
|
|
|
231
|
|
|
$orderCart[] = $itemData; |
|
232
|
|
|
} |
|
233
|
|
|
return $orderCart; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* @param \SoapClient $soapClient |
|
238
|
|
|
* @param array $data |
|
239
|
|
|
*/ |
|
240
|
|
|
protected function runTransaction($soapClient, $data) |
|
241
|
|
|
{ |
|
242
|
|
|
$data['f_action'] = 2; |
|
243
|
|
|
|
|
244
|
|
|
return $this->runSoapRequest($soapClient, $data, 'po_auth_request'); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
protected function getSoapRequestValidationUrl(): string |
|
248
|
|
|
{ |
|
249
|
|
|
return Urls::$authXml; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
protected function getSoapResponseValidationUrl() |
|
253
|
|
|
{ |
|
254
|
|
|
return Urls::$authUrlXml; |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
|