Skip to content

Commit

Permalink
support challangeRequested property on create order request
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkozaczenko committed May 21, 2024
1 parent 696112f commit 09059c8
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ private function prepareOrderRequest(Capture $request, TokenInterface $token, Mo
$model->additionalDescription(),
$model->visibleDescription(),
$model->statementDescription(),
$model->cardOnFile()
$model->cardOnFile(),
threeDsAuthentication: $model->threeDsAuthentication(),
);
}

Expand Down
12 changes: 12 additions & 0 deletions src/Enum/ChallengeRequestedType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Answear\Payum\PayU\Enum;

enum ChallengeRequestedType: string
{
case Yes = 'YES';
case No = 'NO';
case Mandate = 'MANDATE';
}
2 changes: 2 additions & 0 deletions src/Enum/ModelFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ enum ModelFields
public const EXT_REFUND_ID = 'extRefundId';
public const PROPERTIES = 'properties';
public const CARD_ON_FILE = 'cardOnFile';
public const THREE_DS_AUTHENTICATION = 'threeDsAuthentication';
public const CHALLENGE_REQUESTED = 'challangeRequested';
}
13 changes: 13 additions & 0 deletions src/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Answear\Payum\PayU\Model;

use Answear\Payum\PayU\Enum\CardOnFileEnum;
use Answear\Payum\PayU\Enum\ChallengeRequestedType;
use Answear\Payum\PayU\Enum\ModelFields;
use Answear\Payum\PayU\Enum\OrderStatus;
use Answear\Payum\PayU\Enum\PayMethodType;
Expand All @@ -13,6 +14,7 @@
use Answear\Payum\PayU\ValueObject\Buyer;
use Answear\Payum\PayU\ValueObject\Product;
use Answear\Payum\PayU\ValueObject\Request\Order\PayMethod;
use Answear\Payum\PayU\ValueObject\Request\Order\ThreeDsAuthentication;
use Answear\Payum\PayU\ValueObject\Response;
use Payum\Core\Bridge\Spl\ArrayObject;

Expand Down Expand Up @@ -188,6 +190,17 @@ public function setCardOnFile(?CardOnFileEnum $cardOnFileEnum): void
$this[ModelFields::CARD_ON_FILE] = $cardOnFileEnum?->value;
}

public function threeDsAuthentication(): ?ThreeDsAuthentication
{
if (!isset($this[ModelFields::THREE_DS_AUTHENTICATION])) {
return null;
}

return new ThreeDsAuthentication(
ChallengeRequestedType::from($this[ModelFields::THREE_DS_AUTHENTICATION][ModelFields::CHALLENGE_REQUESTED])
);
}

public function setPayUResponse(Response\OrderCreatedResponse $orderCreatedResponse): void
{
$this[ModelFields::PAYU_RESPONSE] = $orderCreatedResponse->toArray();
Expand Down
25 changes: 25 additions & 0 deletions src/ValueObject/Request/Order/ThreeDsAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Answear\Payum\PayU\ValueObject\Request\Order;

use Answear\Payum\PayU\Enum\ChallengeRequestedType;

class ThreeDsAuthentication
{
public function __construct(
public readonly ChallengeRequestedType $challengeRequested,
) {
}

/**
* @return array<string, string|int|array|null>
*/
public function toArray(): array
{
return [
'challangeRequested' => $this->challengeRequested->value,
];
}
}
3 changes: 3 additions & 0 deletions src/ValueObject/Request/OrderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Answear\Payum\PayU\ValueObject\Buyer;
use Answear\Payum\PayU\ValueObject\Product;
use Answear\Payum\PayU\ValueObject\Request\Order\PayMethod;
use Answear\Payum\PayU\ValueObject\Request\Order\ThreeDsAuthentication;
use Webmozart\Assert\Assert;

class OrderRequest
Expand Down Expand Up @@ -38,6 +39,7 @@ public function __construct(
public readonly ?string $statementDescription = null,
public ?CardOnFileEnum $cardOnFile = null,
public ?string $recurring = null,
public ?ThreeDsAuthentication $threeDsAuthentication = null,
) {
Assert::notEmpty($this->products);
Assert::allIsInstanceOf($this->products, Product::class);
Expand All @@ -64,6 +66,7 @@ public function toArray(string $merchantPosId): array
'buyer' => $this->buyer?->toArray(),
'products' => array_map(static fn(Product $product) => $product->toArray(), $this->products),
'payMethods' => null === $this->payMethod ? null : ['payMethod' => $this->payMethod->toArray()],
'threeDsAuthentication' => $this->threeDsAuthentication?->toArray(),
'cardOnFile' => $this->cardOnFile?->value,
'recurring' => $this->recurring,
];
Expand Down

0 comments on commit 09059c8

Please sign in to comment.