Skip to content

Commit 9c2b804

Browse files
committed
Mini-update
* purchase() should include authorization and capture * explicitly mark as e-commerce transactions * shift request method to class property
1 parent df4b884 commit 9c2b804

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/Message/CompletePurchaseRequest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
class CompletePurchaseRequest extends PurchaseRequest
1111
{
12+
protected $requestMethod = 'GET';
13+
1214
public function getHostedCheckoutId()
1315
{
1416
return $this->getParameter('hostedCheckoutId');
@@ -33,9 +35,4 @@ protected function getAction()
3335
{
3436
return '/v2/'.$this->getMerchantId().'/hostedcheckouts/'.$this->getHostedCheckoutId();
3537
}
36-
37-
protected function getRequestMethod()
38-
{
39-
return 'GET';
40-
}
4138
}

src/Message/PurchaseRequest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class PurchaseRequest extends AbstractRequest
2222
/** @var string */
2323
protected $testEndpoint = 'https://payment.preprod.direct.worldline-solutions.com';
2424

25+
/** @var string Can be "FINAL_AUTHORIZATION" "PRE_AUTHORIZATION" or "SALE" */
26+
protected $authorizationMode = 'SALE';
27+
protected $requestMethod = 'POST';
28+
2529
public function getApiKey()
2630
{
2731
return $this->getParameter('apiKey');
@@ -135,6 +139,10 @@ public function getData()
135139
}
136140

137141
$data = [
142+
'cardPaymentMethodSpecificInput' => [
143+
'authorizationMode' => 'SALE',
144+
'transactionChannel' => 'ECOMMERCE',
145+
],
138146
'hostedCheckoutSpecificInput' => [
139147
// if adding locale, validate locale against known formats
140148
// @see https://docs.direct.worldline-solutions.com/en/integration/basic-integration-methods/hosted-checkout-page#chooselanguageversion
@@ -198,13 +206,12 @@ public function getEndpoint()
198206

199207
public function sendData($data)
200208
{
201-
$requestMethod = $this->getRequestMethod();
202-
$contentType = $this->getRequestMethod() == 'POST' ? 'application/json; charset=utf-8' : '';
209+
$contentType = $this->requestMethod == 'POST' ? 'application/json; charset=utf-8' : '';
203210
$now = new DateTime('now', new DateTimeZone('GMT'));
204211
$dateTime = $now->format("D, d M Y H:i:s T");
205212
$endpointAction = $this->getAction();
206213

207-
$message = $requestMethod."\n".$contentType."\n".$dateTime."\n".$endpointAction."\n";
214+
$message = $this->requestMethod."\n".$contentType."\n".$dateTime."\n".$endpointAction."\n";
208215
$signature = $this->createSignature($message, $this->getApiSecret());
209216

210217
$headers = [
@@ -216,7 +223,7 @@ public function sendData($data)
216223
$body = json_encode($data);
217224

218225
$httpResponse = $this->httpClient->request(
219-
$requestMethod,
226+
$this->requestMethod,
220227
$this->getEndpoint(),
221228
$headers,
222229
$body
@@ -271,9 +278,4 @@ protected function getItemPriceInteger($item)
271278

272279
return (int) $money->getAmount();
273280
}
274-
275-
protected function getRequestMethod()
276-
{
277-
return 'POST';
278-
}
279281
}

0 commit comments

Comments
 (0)