Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix tests of payment method
Pacu2f46bfb8297b8
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex ac2d126cc7..44bcdbd3ce 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -355,7 +355,8 @@ class OrderMarkAsPaidForm(forms.Form):# FIXME add more fields to the payment methoddefaults = {'total': self.order.total,- 'captured_amount': self.order.total.gross}+ 'captured_amount': self.order.total.gross,+ **get_billing_data(self.order)}PaymentMethod.objects.get_or_create(variant=CustomPaymentChoices.MANUAL,charge_status=ChargeStatus.CHARGED, order=self.order,diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 1c9bd6d24a..b083f56c3e 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -128,7 +128,7 @@ class PaymentMethodCapture(BaseMutation):return PaymentMethodCapture(errors=errors)try:- gateway_capture(payment_method, amount=amount)+ gateway_capture(payment_method, amount)except PaymentError as exc:msg = str(exc)cls.add_error(field=None, message=msg, errors=errors)diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 21b25c89ee..32af056608 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -52,27 +52,13 @@ def validate_payment_method(view):can be performed on it."""@wraps(view)- def func(payment_method: PaymentMethod, *args, **kwargs):+ def func(payment_method, *args, **kwargs):if not payment_method.is_active:raise PaymentError('This payment method is no longer active.')- return view(payment_method=payment_method, *args, **kwargs)+ return view(*args, payment_method, **kwargs)return func-def validate_positive_amount(view):- """Decorate a view to check if payment method is active, so any actions- can be performed on it.- """- @wraps(view)- def func(amount: Decimal, *args, **kwargs):- if amount <= 0:- raise PaymentError('Amount should be a positive number.')- amount = Money(amount, currency=settings.DEFAULT_CURRENCY)- return view(*args, amount=amount, **kwargs)- return func---def create_payment_method(**payment_data):payment_method, _ = PaymentMethod.objects.get_or_create(**payment_data)return payment_method@@ -120,10 +106,12 @@ def gateway_authorize(@validate_payment_method-@validate_positive_amountdef gateway_capture(payment_method: PaymentMethod,amount: Decimal) -> Transaction:+ if amount <= 0:+ raise PaymentError('Amount should be a positive number.')+ amount = Money(amount, currency=settings.DEFAULT_CURRENCY)if payment_method.charge_status not in {ChargeStatus.CHARGED,ChargeStatus.NOT_CHARGED}:@@ -166,10 +154,12 @@ def gateway_void(payment_method) -> Transaction:@validate_payment_method-@validate_positive_amountdef gateway_refund(payment_method,amount: Decimal) -> Transaction:+ if amount <= 0:+ raise PaymentError('Amount should be a positive number.')+ amount = Money(amount, currency=settings.DEFAULT_CURRENCY)if amount > payment_method.captured_amount:raise PaymentError('Cannot refund more than captured')if not payment_method.charge_status == ChargeStatus.CHARGED: