Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix a bug where logic of refund/logic is not handled correctly
Unknown7193c161a6f6
diff --git a/saleor/payment/gateways/stripe/__init__.py b/saleor/payment/gateways/stripe/__init__.pyindex 6745e03d54..95de44b0da 100644--- a/saleor/payment/gateways/stripe/__init__.py+++ b/saleor/payment/gateways/stripe/__init__.py@@ -104,19 +104,20 @@ def refund(payment, amount, **connection_params):capture_txn = payment.transactions.filter(kind=TransactionKind.CHARGE, is_success=True).first()- if not capture_txn:++ if capture_txn is not None:+ try:+ # Retrieve stripe charge and refund specific amount+ stripe_charge = client.Charge.retrieve(capture_txn.token)+ response = client.Refund.create(+ charge=stripe_charge.id, amount=stripe_amount)+ except stripe.error.StripeError as exc:+ response = _get_error_response_from_exc(exc)+ error = exc.user_message+ else:error = errors.ORDER_NOT_CHARGEDresponse = dict()- try:- # Retrieve stripe charge and refund specific amount- stripe_charge = client.Charge.retrieve(capture_txn.token)- response = client.Refund.create(- charge=stripe_charge.id, amount=stripe_amount)- except stripe.error.StripeError as exc:- response = _get_error_response_from_exc(exc)- error = exc.user_message-# Create transactiontxn = _create_transaction(payment=payment,@@ -132,18 +133,19 @@ def void(payment, **connection_params):capture_txn = payment.transactions.filter(kind=TransactionKind.CHARGE, is_success=True).first()- if not capture_txn:++ if capture_txn is not None:+ try:+ # Retrieve stripe charge and refund all+ stripe_charge = client.Charge.retrieve(capture_txn.token)+ response = client.Refund.create(charge=stripe_charge.id)+ except stripe.error.StripeError as exc:+ response = _get_error_response_from_exc(exc)+ error = exc.user_message+ else:error = errors.ORDER_NOT_CHARGEDresponse = dict()- try:- # Retrieve stripe charge and refund all- stripe_charge = client.Charge.retrieve(capture_txn.token)- response = client.Refund.create(charge=stripe_charge.id)- except stripe.error.StripeError as exc:- response = _get_error_response_from_exc(exc)- error = exc.user_message-# Create transactiontxn = _create_transaction(payment=payment,diff --git a/saleor/payment/gateways/stripe/errors.py b/saleor/payment/gateways/stripe/errors.pyindex 74450fe2c1..ae928352bf 100644--- a/saleor/payment/gateways/stripe/errors.py+++ b/saleor/payment/gateways/stripe/errors.py@@ -1,4 +1,4 @@from django.utils.translation import pgettext_lazyORDER_NOT_CHARGED = pgettext_lazy(- 'Razorpay payment error', 'Order was not charged.')+ 'Stripe payment error', 'Order was not charged.')