diff --git a/composer.json b/composer.json index 92513f6..e708c87 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -11,6 +11,10 @@ { "name": "Valentin Damyanov", "email": "valentin.damyanov@ampeco.global" + }, + { + "name": "Bozhidar Gyurov", + "email": "bozhidar.gyurov@ampeco.global" } ], "require": { diff --git a/src/CommonParameters.php b/src/CommonParameters.php index 4f4220d..5b391cc 100644 --- a/src/CommonParameters.php +++ b/src/CommonParameters.php @@ -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'); + } } diff --git a/src/Gateway.php b/src/Gateway.php index 0c066ac..a1b1d0d 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -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; @@ -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); + } } diff --git a/src/Message/InitialPurchaseRequest.php b/src/Message/InitialPurchaseRequest.php new file mode 100644 index 0000000..0155996 --- /dev/null +++ b/src/Message/InitialPurchaseRequest.php @@ -0,0 +1,50 @@ + [ + '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); + } +} diff --git a/src/Message/InitialPurchaseResponse.php b/src/Message/InitialPurchaseResponse.php new file mode 100644 index 0000000..a8918f6 --- /dev/null +++ b/src/Message/InitialPurchaseResponse.php @@ -0,0 +1,21 @@ +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; + } +} diff --git a/src/Message/Response.php b/src/Message/Response.php index 9be7d1c..abce626 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -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) { @@ -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