Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix bug where capture should get token from authorized transactions
Unknown87d6001dd66a
diff --git a/saleor/payment/gateways/stripe/__init__.py b/saleor/payment/gateways/stripe/__init__.pyindex ffd65adf95..5ac4716ebd 100644--- a/saleor/payment/gateways/stripe/__init__.py+++ b/saleor/payment/gateways/stripe/__init__.py@@ -47,13 +47,20 @@ def capture(payment, amount, **connection_params):amount = amount or payment.totalstripe_amount = get_amount_for_stripe(amount, payment.currency)- try:- # Retrieve stripe charge and capture specific amount- stripe_charge = client.Charge.retrieve(payment.token)- response = stripe_charge.capture(amount=stripe_amount)- except stripe.error.StripeError as exc:- response = _get_error_response_from_exc(exc)- error = exc.user_message+ capture_txn = payment.transactions.filter(+ kind=TransactionKind.AUTH, is_success=True).first()++ if capture_txn is not None:+ try:+ # Retrieve stripe charge and capture specific amount+ stripe_charge = client.Charge.retrieve(capture_txn.token)+ response = stripe_charge.capture(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_AUTHORIZED+ response = dict()# Create transactiontxn = _create_transaction(@@ -138,7 +145,7 @@ def void(payment, **connection_params):response = _get_error_response_from_exc(exc)error = exc.user_messageelse:- error = errors.ORDER_NOT_CHARGED+ error = errors.ORDER_NOT_AUTHORIZEDresponse = dict()# Create transactiondiff --git a/saleor/payment/gateways/stripe/errors.py b/saleor/payment/gateways/stripe/errors.pyindex ae928352bf..38901f799c 100644--- a/saleor/payment/gateways/stripe/errors.py+++ b/saleor/payment/gateways/stripe/errors.py@@ -1,4 +1,6 @@from django.utils.translation import pgettext_lazy+ORDER_NOT_AUTHORIZED = pgettext_lazy(+ 'Stripe payment error', 'Order was not authorized.')ORDER_NOT_CHARGED = pgettext_lazy('Stripe payment error', 'Order was not charged.')