1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\BPOINT\Message; |
4
|
|
|
|
5
|
|
|
use Omnipay\Common\Message\AbstractRequest; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* BPOINT Purchase Request |
9
|
|
|
*/ |
10
|
|
|
class PurchaseRequest extends AbstractRequest |
11
|
|
|
{ |
12
|
|
|
/** @var string */ |
13
|
|
|
protected $endpoint = 'https://www.bpoint.com.au/webapi/v3/txns/'; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
protected $action = 'processtxnauthkey'; |
17
|
|
|
|
18
|
7 |
|
public function getUsername() |
19
|
|
|
{ |
20
|
7 |
|
return $this->getParameter('username'); |
21
|
|
|
} |
22
|
|
|
|
23
|
15 |
|
public function setUsername($value) |
24
|
|
|
{ |
25
|
15 |
|
return $this->setParameter('username', $value); |
26
|
|
|
} |
27
|
|
|
|
28
|
7 |
|
public function getPassword() |
29
|
|
|
{ |
30
|
7 |
|
return $this->getParameter('password'); |
31
|
|
|
} |
32
|
|
|
|
33
|
15 |
|
public function setPassword($value) |
34
|
|
|
{ |
35
|
15 |
|
return $this->setParameter('password', $value); |
36
|
|
|
} |
37
|
|
|
|
38
|
7 |
|
public function getMerchantNumber() |
39
|
|
|
{ |
40
|
7 |
|
return $this->getParameter('merchantNumber'); |
41
|
|
|
} |
42
|
|
|
|
43
|
15 |
|
public function setMerchantNumber($value) |
44
|
|
|
{ |
45
|
15 |
|
return $this->setParameter('merchantNumber', $value); |
46
|
|
|
} |
47
|
|
|
|
48
|
4 |
|
public function getMerchantShortName() |
49
|
|
|
{ |
50
|
4 |
|
return $this->getParameter('merchantShortName'); |
51
|
|
|
} |
52
|
|
|
|
53
|
15 |
|
public function setMerchantShortName($value) |
54
|
|
|
{ |
55
|
15 |
|
return $this->setParameter('merchantShortName', $value); |
56
|
|
|
} |
57
|
|
|
|
58
|
7 |
|
public function getCustomerReferenceNumber1() |
59
|
|
|
{ |
60
|
7 |
|
return $this->getParameter('customerReferenceNumber1'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Set customer configurable reference #1 |
65
|
|
|
* |
66
|
|
|
* @param bool $value String, max 50 characters |
67
|
|
|
*/ |
68
|
11 |
|
public function setCustomerReferenceNumber1($value) |
69
|
|
|
{ |
70
|
11 |
|
return $this->setParameter('customerReferenceNumber1', $value); |
71
|
|
|
} |
72
|
|
|
|
73
|
7 |
|
public function getCustomerReferenceNumber2() |
74
|
|
|
{ |
75
|
7 |
|
return $this->getParameter('customerReferenceNumber2'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Set customer configurable reference #2 |
80
|
|
|
* |
81
|
|
|
* @param bool $value String, max 50 characters |
82
|
|
|
*/ |
83
|
11 |
|
public function setCustomerReferenceNumber2($value) |
84
|
|
|
{ |
85
|
11 |
|
return $this->setParameter('customerReferenceNumber2', $value); |
86
|
|
|
} |
87
|
|
|
|
88
|
7 |
|
public function getCustomerReferenceNumber3() |
89
|
|
|
{ |
90
|
7 |
|
return $this->getParameter('customerReferenceNumber3'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set customer configurable reference #3 |
95
|
|
|
* |
96
|
|
|
* @param bool $value String, max 50 characters |
97
|
|
|
*/ |
98
|
11 |
|
public function setCustomerReferenceNumber3($value) |
99
|
|
|
{ |
100
|
11 |
|
return $this->setParameter('customerReferenceNumber3', $value); |
101
|
|
|
} |
102
|
|
|
|
103
|
7 |
|
public function getGenerateToken() |
104
|
|
|
{ |
105
|
7 |
|
return $this->getParameter('generateToken'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Indicate whether or not to generate a token for the card used in the transaction |
110
|
|
|
* |
111
|
|
|
* @param bool $value Generate a token or not |
112
|
|
|
*/ |
113
|
11 |
|
public function setGenerateToken($value) |
114
|
|
|
{ |
115
|
11 |
|
return $this->setParameter('generateToken', $value); |
116
|
|
|
} |
117
|
|
|
|
118
|
2 |
|
public function getCustomerNumber() |
119
|
|
|
{ |
120
|
2 |
|
return $this->getParameter('customerNumber'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Set the unique customer ID in the merchant system |
125
|
|
|
* |
126
|
|
|
* @param bool $value Customer number to set |
127
|
|
|
*/ |
128
|
11 |
|
public function setCustomerNumber($value) |
129
|
|
|
{ |
130
|
11 |
|
return $this->setParameter('customerNumber', $value); |
131
|
|
|
} |
132
|
|
|
|
133
|
7 |
|
public function getData() |
134
|
|
|
{ |
135
|
7 |
|
$this->validate('username', 'password', 'merchantNumber', 'merchantShortName', 'amount', 'currency'); |
136
|
|
|
|
137
|
7 |
|
$amount = $this->getAmountInteger(); |
138
|
|
|
$data = array( |
139
|
|
|
'ProcessTxnData' => array( |
140
|
7 |
|
'Action' => $amount > 0 ? 'payment' : 'verify_only', |
141
|
7 |
|
'TestMode' => $this->getTestMode(), |
142
|
7 |
|
'Amount' => $this->getAmountInteger(), |
143
|
7 |
|
'Crn1' => $this->getCustomerReferenceNumber1(), |
144
|
7 |
|
'Crn2' => $this->getCustomerReferenceNumber2(), |
145
|
7 |
|
'Crn3' => $this->getCustomerReferenceNumber3(), |
146
|
7 |
|
'Currency' => $this->getCurrency(), |
147
|
|
|
// 1 - no; 3 - always (don't leave it up to system or customer) |
148
|
7 |
|
'TokenisationMode' => $this->getGenerateToken() ? 3 : 1, |
149
|
7 |
|
'MerchantReference' => $this->getTransactionId(), |
150
|
7 |
|
'SubType' => 'single', |
151
|
7 |
|
'Type' => 'internet', |
152
|
|
|
), |
153
|
7 |
|
'RedirectionUrl' => $this->getReturnUrl(), |
154
|
7 |
|
'WebHookUrl' => $this->getNotifyUrl(), |
155
|
|
|
); |
156
|
|
|
// add item details if available |
157
|
7 |
|
$items = $this->getItems(); |
158
|
7 |
|
if ($items) { |
159
|
1 |
|
$data['Order'] = array('OrderItems' => array()); |
160
|
1 |
|
foreach ($items as $item) { |
161
|
1 |
|
$data['Order']['OrderItems'][] = array( |
162
|
1 |
|
'Comments' => '', |
163
|
1 |
|
'Description' => $item->getDescription(), |
164
|
1 |
|
'GiftMessage' => '', |
165
|
1 |
|
'PartNumber' => '', |
166
|
1 |
|
'ProductCode' => $item->getName(), |
167
|
1 |
|
'Quantity' => $item->getQuantity(), |
168
|
1 |
|
'SKU' => '', |
169
|
1 |
|
'ShippingMethod' => '', |
170
|
1 |
|
'ShippingNumber' => '', |
171
|
|
|
// note: Item has no getPriceInteger; copied getCurrencyDecimalFactor() contents as it is private |
172
|
1 |
|
'UnitPrice' => (int) round($item->getPrice() * pow(10, $this->getCurrencyDecimalPlaces())), |
173
|
|
|
); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
// add customer details if available |
177
|
7 |
|
$card = $this->getCard(); |
178
|
7 |
|
if ($card) { |
179
|
2 |
|
$country = $card->getCountry(); |
180
|
2 |
|
$data['Customer'] = array( |
181
|
1 |
|
'Address' => array( |
182
|
2 |
|
'AddressLine1' => $card->getAddress1(), |
183
|
2 |
|
'AddressLine2' => $card->getAddress2(), |
184
|
2 |
|
'City' => $card->getCity(), |
185
|
|
|
// should be ISO Alpha-3 country code |
186
|
2 |
|
'CountryCode' => strlen($country) > 3 ? null : $country, |
187
|
2 |
|
'PostCode' => $card->getPostcode(), |
188
|
2 |
|
'State' => $card->getState(), |
189
|
|
|
), |
190
|
|
|
'ContactDetails' => array( |
191
|
2 |
|
'EmailAddress' => $card->getEmail(), |
192
|
|
|
), |
193
|
|
|
'PersonalDetails' => array( |
194
|
2 |
|
'FirstName' => $card->getFirstName(), |
195
|
2 |
|
'LastName' => $card->getLastName(), |
196
|
|
|
), |
197
|
|
|
); |
198
|
2 |
|
$data['EmailAddress'] = $card->getEmail(); |
199
|
2 |
|
$customerNumber = $this->getCustomerNumber(); |
200
|
2 |
|
if ($customerNumber) { |
201
|
2 |
|
$data['Customer']['CustomerNumber'] = $customerNumber; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
7 |
|
return $data; |
206
|
|
|
} |
207
|
|
|
|
208
|
2 |
|
public function sendData($data) |
209
|
|
|
{ |
210
|
|
|
// submit data as request to Authkey endpoint |
211
|
2 |
|
$httpResponse = $this->httpClient->request( |
212
|
2 |
|
'POST', |
213
|
2 |
|
$this->getEndpoint(), |
214
|
|
|
[ |
215
|
2 |
|
'Accept' => 'application/json', |
216
|
|
|
'Content-Type' => 'application/json', |
217
|
2 |
|
'Authorization' => $this->getAuthHeader(), |
218
|
|
|
], |
219
|
|
|
json_encode($data) |
220
|
4 |
|
); |
221
|
|
|
// get response data |
222
|
4 |
|
$responseData = json_decode($httpResponse->getBody()->getContents(), true); |
223
|
|
|
|
224
|
|
|
return $this->response = new PurchaseResponse($this, $responseData); |
225
|
5 |
|
} |
226
|
|
|
|
227
|
5 |
|
public function getEndpoint() |
228
|
|
|
{ |
229
|
|
|
return $this->endpoint.$this->action; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function getAuthHeader() |
233
|
|
|
{ |
234
|
|
|
return base64_encode($this->getUsername().'|'.$this->getMerchantNumber().':'.$this->getPassword()); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|