Skip to content

Commit

Permalink
UNZER-457 refactor sending recurrence type oneclick
Browse files Browse the repository at this point in the history
  • Loading branch information
René Gust committed Jul 22, 2024
1 parent 047dd5b commit dd62120
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"require": {
"unzerdev/php-sdk": "^v3.4.1",
"webmozart/path-util": "^2.3.0",
"guzzlehttp/guzzle": "^7.7"
"guzzlehttp/guzzle": "^7.7",
"ext-json": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.*",
Expand Down
32 changes: 21 additions & 11 deletions src/PaymentExtensions/UnzerPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OxidSolutionCatalysts\Unzer\Service\Unzer as UnzerService;
use OxidSolutionCatalysts\Unzer\Service\UnzerSDKLoader;
use OxidSolutionCatalysts\Unzer\Traits\ServiceContainer;
use UnzerSDK\Constants\RecurrenceTypes;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Resources\Basket as UnzerResourceBasket;
use UnzerSDK\Resources\Customer;
Expand Down Expand Up @@ -156,12 +157,11 @@ public function execute(
$userModel->save();
}

if ($paymentType instanceof UnzerSDKPaymentTypeCard || $paymentType instanceof Paypal) {
$savePayment = $request->getRequestParameter('oscunzersavepayment');
if ($savePayment && $this->existsInSavedPaymentsList($userModel)) {
$savePayment = false;
}
$session->setVariable('oscunzersavepayment', $savePayment);
if ($this->isSafePaymentClickedByUserInRequest($paymentType)) {
$session->setVariable(
'oscunzersavepayment',
$this->existsInSavedPaymentsList($userModel) ? $request->getRequestParameter('oscunzersavepayment') : false
);
}

if ($userModel->getId()) {
Expand Down Expand Up @@ -324,10 +324,11 @@ public function existsInSavedPaymentsList(User $user): bool
if ($currentPayment) {
$currentPaymentType = $currentPayment->getPaymentType();
foreach ($savedUserPayments as $savedPayment) {
if ($currentPaymentType instanceof UnzerSDKPaymentTypeCard) {
if ($this->areCardsEqual($currentPaymentType, $savedPayment)) {
if (
$currentPaymentType instanceof UnzerSDKPaymentTypeCard
&& $this->areCardsEqual($currentPaymentType, $savedPayment)
) {
return true;
}
}
if (
($currentPaymentType instanceof Paypal) &&
Expand Down Expand Up @@ -385,7 +386,11 @@ private function performDefaultTransaction(
$customer,
$this->unzerOrderId,
$this->unzerService->getShopMetadata($this->paymentMethod),
$uzrBasket
$uzrBasket,
null,
null,
null,
$this->isSafePaymentClickedByUserInRequest($paymentType) ? RecurrenceTypes::ONE_CLICK : null
);
}

Expand Down Expand Up @@ -424,7 +429,12 @@ private function performTransactionForSavedPayment(
true,
null,
null,
\UnzerSDK\Constants\RecurrenceTypes::ONE_CLICK
RecurrenceTypes::ONE_CLICK
);
}

private function isSafePaymentClickedByUserInRequest(BasePaymentType $paymentType) {

Check failure on line 436 in src/PaymentExtensions/UnzerPayment.php

View workflow job for this annotation

GitHub Actions / styles (8.0)

Method OxidSolutionCatalysts\Unzer\PaymentExtensions\UnzerPayment::isSafePaymentClickedByUserInRequest() has no return type specified.

Check failure on line 436 in src/PaymentExtensions/UnzerPayment.php

View workflow job for this annotation

GitHub Actions / styles (8.0)

Method OxidSolutionCatalysts\Unzer\PaymentExtensions\UnzerPayment::isSafePaymentClickedByUserInRequest() has no return type specified.

Check failure on line 436 in src/PaymentExtensions/UnzerPayment.php

View workflow job for this annotation

GitHub Actions / styles (8.0)

Method OxidSolutionCatalysts\Unzer\PaymentExtensions\UnzerPayment::isSafePaymentClickedByUserInRequest() has no return type specified.
return ($paymentType instanceof UnzerSDKPaymentTypeCard || $paymentType instanceof Paypal)
&& Registry::getRequest()->getRequestParameter('oscunzersavepayment');
}
}

0 comments on commit dd62120

Please sign in to comment.