Skip to content

Commit

Permalink
3DS handling
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinDamyanovAmpeco committed Jul 4, 2024
1 parent 3b958eb commit 57f8c2b
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ampeco/omnipay-wl-valina",
"description": "Omnipay plugin for Worldline Valina",
"version": "1.0.0",
"version": "1.1.0",
"type": "library",
"license": "MIT",
"autoload": {
Expand All @@ -11,6 +11,10 @@
{
"name": "Valentin Damyanov",
"email": "valentin.damyanov@ampeco.global"
},
{
"name": "Bozhidar Gyurov",
"email": "bozhidar.gyurov@ampeco.global"
}
],
"require": {
Expand Down
10 changes: 10 additions & 0 deletions src/CommonParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ public function getApiSecret()
{
return $this->getParameter('api_secret');
}

public function setHostedTokenizationId($value): void
{
$this->setParameter('hostedTokenizationId', $value);
}

public function getHostedTokenizationId()
{
return $this->getParameter('hostedTokenizationId');
}
}
6 changes: 6 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Ampeco\OmnipayWlValina\Message\CaptureRequest;
use Ampeco\OmnipayWlValina\Message\CreateCardRequest;
use Ampeco\OmnipayWlValina\Message\DeleteCardRequest;
use Ampeco\OmnipayWlValina\Message\InitialPurchaseRequest;
use Ampeco\OmnipayWlValina\Message\NotificationRequest;
use Ampeco\OmnipayWlValina\Message\PurchaseRequest;
use Ampeco\OmnipayWlValina\Message\VoidRequest;
Expand Down Expand Up @@ -64,4 +65,9 @@ public function void(array $parameters)
{
return $this->createRequest(VoidRequest::class, $parameters);
}

public function initialPurchase(array $parameters)
{
return $this->createRequest(InitialPurchaseRequest::class, $parameters);
}
}
50 changes: 50 additions & 0 deletions src/Message/InitialPurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Ampeco\OmnipayWlValina\Message;

class InitialPurchaseRequest extends AbstractRequest
{
public function getEndpoint(): string
{
return '/payments';
}

public function getRequestMethod(): string
{
return 'POST';
}

public function getData(): array
{
return [
'cardPaymentMethodSpecificInput' => [
'authorizationMode' => 'FINAL_AUTHORIZATION',
'transactionChannel' => 'ECOMMERCE',
'returnUrl' => $this->getReturnUrl(),
'threeDSecure' => [
'skipAuthentication' => false,
'challengeIndicator' => 'no-preference',
],
],
'order' => [
'amountOfMoney' => [
//EUR is a 2-decimals currency, the value 1234 will result in EUR 12.34
'amount' => number_format($this->getAmount(), 2, '', ''),
'currencyCode' => $this->getCurrency(),
],
'customer' => [
'device' => [
'acceptHeader' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'userAgent' => 'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/75.0.3770.142Safari/537.36',
],
],
],
'hostedTokenizationId' => $this->getHostedTokenizationId(),
];
}

protected function createResponse(array $data, int $statusCode): Response
{
return $this->response = new InitialPurchaseResponse($this, $data, $statusCode);
}
}
21 changes: 21 additions & 0 deletions src/Message/InitialPurchaseResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Ampeco\OmnipayWlValina\Message;

class InitialPurchaseResponse extends Response
{
public function isSuccessful(): bool
{
return parent::isSuccessful() && in_array(@$this->data['payment']['status'], [self::STATUS_REDIRECTED, self::STATUS_PENDING_CAPTURE]);
}

public function getRedirectUrl()
{
return $this->data['merchantAction']['redirectData']['redirectURL'] ?? null;
}

public function getTransactionReference(): ?string
{
return $this->data['payment']['id'] ?? null;
}
}
3 changes: 2 additions & 1 deletion src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Response extends AbstractResponse
const STATUS_CAPTURED = 'CAPTURED';
const STATUS_PENDING_CAPTURE = 'PENDING_CAPTURE';
const STATUS_CAPTURE_REQUESTED = 'CAPTURE_REQUESTED';
const STATUS_REDIRECTED = 'REDIRECTED';

public function __construct(RequestInterface $request, $data, protected int $code)
{
Expand All @@ -21,7 +22,7 @@ public function __construct(RequestInterface $request, $data, protected int $cod
*/
public function isSuccessful(): bool
{
return $this->code >= 200;
return $this->code >= 200 && $this->code < 300;
}

public function getTransactionReference(): ?string
Expand Down

0 comments on commit 57f8c2b

Please sign in to comment.