Skip to content

Commit 491643a

Browse files
truly available payments for a change after the order is made are now returned from the backend (#3922)
2 parents 12531dc + 407d30b commit 491643a

File tree

6 files changed

+22
-44
lines changed

6 files changed

+22
-44
lines changed

src/Model/Order/OrderPaymentsConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
class OrderPaymentsConfig
1010
{
1111
/**
12-
* @param \Shopsys\FrameworkBundle\Model\Payment\Payment $currentPayment
12+
* @param \Shopsys\FrameworkBundle\Model\Payment\Payment|null $currentPayment
1313
* @param \Shopsys\FrameworkBundle\Model\Payment\Payment[] $availablePayments
1414
*/
1515
public function __construct(
16-
public readonly Payment $currentPayment,
16+
public readonly ?Payment $currentPayment,
1717
public readonly array $availablePayments,
1818
) {
1919
}

src/Model/Order/OrderPaymentsConfigFactory.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,25 @@ public function createForOrder(Order $order): OrderPaymentsConfig
2626
{
2727
$payments = $this->paymentFacade->getVisibleForOrder($order);
2828

29-
$currentPayment = $order->getPayment();
29+
$currentPayment = $order->isMaxTransactionCountReached() ? null : $order->getPayment();
30+
31+
if ($currentPayment !== null && !in_array($currentPayment, $payments, true)) {
32+
$currentPayment = null;
33+
}
34+
3035
$availablePayments = array_filter(
3136
$payments,
32-
static fn (Payment $payment) => $payment->getId() !== $currentPayment->getId(),
37+
static function (Payment $payment) use ($order, $currentPayment) {
38+
if ($payment->getId() === $currentPayment?->getId()) {
39+
return false;
40+
}
41+
42+
if ($order->isMaxTransactionCountReached()) {
43+
return !$payment->isGatewayPayment();
44+
}
45+
46+
return true;
47+
},
3348
);
3449

3550
return new OrderPaymentsConfig($currentPayment, $availablePayments);

src/Model/Resolver/Settings/MaxAllowedPaymentTransactionsQuery.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Resources/config/graphql-types/ModelType/Order/OrderDecorator.types.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ OrderDecorator:
108108
lastExternalPaymentUrl:
109109
type: "String"
110110
description: "URL for accessing the last payment transaction on a gateway without invoking the new payment transaction. Depending on the payment status, user might see the payment details or even retry the transaction if possible."
111-
paymentTransactionsCount:
112-
type: "Int!"
113-
description: "Count of the payment transactions related to the order"
114111
isPaid:
115112
type: "Boolean!"
116113
description: "Indicates whether the order is paid successfully with GoPay payment type"

src/Resources/config/graphql-types/ModelType/Order/OrderPaymentsConfig.types.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ OrderPaymentsConfigDecorator:
44
config:
55
fields:
66
currentPayment:
7-
type: "Payment!"
8-
description: "Current payment method used in the order"
7+
type: "Payment"
8+
description: "Current payment method used in the order. Null if the original payment is not available anymore due to the reached limit of max payment transactions count."
99
availablePayments:
1010
type: "[Payment!]!"
11-
description: "All available payment methods for the order (excluding the current one)"
11+
description: "All currently available payment methods for the order (excluding the current one)"

src/Resources/config/graphql-types/ModelType/Settings/SettingsDecorator.types.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ SettingsDecorator:
88
type: "SeoSetting!"
99
resolve: "@=query('seoSettingsQuery')"
1010
description: "Settings related to SEO"
11-
maxAllowedPaymentTransactions:
12-
type: Int!
13-
resolve: "@=query('maxAllowedPaymentTransactionsQuery')"
14-
description: "Max allowed payment transactions (how many times is user allowed to try the same payment)"
1511
pricing:
1612
type: "PricingSetting!"
1713
resolve: "@=query('pricingSettingsQuery')"

0 commit comments

Comments
 (0)