Skip to content

Commit

Permalink
Merge pull request #4500 from NyanKiyoshi/api/checkout/payment
Browse files Browse the repository at this point in the history
Order is no longer created when the payment was unsuccessful in the API
  • Loading branch information
maarcingebala committed Jul 22, 2019
2 parents 51b587f + 2981de6 commit e43d26c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix searches and pickers - #4487 by @dominik-zeglen
- Fix dashboard menu styles - #4491 by @benekex2
- Do not allow random ids to appear in snapshots - #4495 by @dominik-zeglen
- Order is no longer created when the payment was unsuccessful in the API - #4500 by @NyanKiyoshi

## 2.8.0

Expand Down
3 changes: 3 additions & 0 deletions saleor/graphql/checkout/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ def perform_mutation(cls, _root, info, checkout_id, store_source):
if txn.is_success and txn.customer_id and user.is_authenticated:
store_customer_id(user, payment.gateway, txn.customer_id)

if not txn.is_success:
raise PaymentError(txn.error)

except PaymentError as e:
abort_order_data(order_data)
raise ValidationError(str(e))
Expand Down
19 changes: 15 additions & 4 deletions tests/api/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from saleor.graphql.core.utils import str_to_enum
from saleor.order.models import Order
from saleor.payment import PaymentError
from saleor.payment.models import Transaction
from saleor.shipping import ShippingMethodType
from saleor.shipping.models import ShippingMethod
from tests.api.utils import get_graphql_content
Expand Down Expand Up @@ -1048,6 +1049,18 @@ def test_checkout_complete(
).exists(), "Checkout should have been deleted"


def _process_payment_raise_error(*args, **kwargs):
raise PaymentError("Oops! Something went wrong.")


def _process_payment_transaction_returns_error(*args, **kwargs):
return Transaction(error="Oops! Something went wrong.", is_success=False)


@pytest.mark.parametrize(
"side_effect",
(_process_payment_raise_error, _process_payment_transaction_returns_error),
)
@patch("saleor.graphql.checkout.mutations.gateway_process_payment")
def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(
mocked_process_payment,
Expand All @@ -1057,12 +1070,10 @@ def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(
payment_dummy,
address,
shipping_method,
side_effect,
):
def _process_payment(*args, **kwargs):
raise PaymentError("Oops! Something went wrong.")

expected_voucher_usage_count = voucher.used
mocked_process_payment.side_effect = _process_payment
mocked_process_payment.side_effect = side_effect

checkout = checkout_with_voucher
checkout.shipping_address = address
Expand Down

0 comments on commit e43d26c

Please sign in to comment.