Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Merge pull request #5937 from mirumee/add-adyen-support-for-3d-secure

Iga Karbowiake5965da37c02
diff --cc saleor/payment/gateways/adyen/tests/test_plugin.py
index 7f9a59d3ab,ef1aecc59a..dd8405efba
--- a/saleor/payment/gateways/adyen/tests/test_plugin.py
+++ b/saleor/payment/gateways/adyen/tests/test_plugin.py
@@@ -84,26 -87,134 +87,145 @@@ def test_process_payment_with_auto_capt
assert response.currency == checkout_with_items.currency
assert response.transaction_id == "853596624248395G" # ID returned by Adyen
assert response.error is None
+ assert response.action_required_data is None
+
+
+ @pytest.mark.vcr
+ @mock.patch("saleor.payment.gateways.adyen.plugin.api_call")
+ def test_process_payment_additional_action(
+ api_call_mock, payment_adyen_for_checkout, checkout_with_items, adyen_plugin
+ ):
+ payment_adyen_for_checkout.extra_data = ""
+ payment_adyen_for_checkout.save(update_fields=["extra_data"])
+ payment_data = "Ab02b4c0!B"
+ action_data = {
+ "method": "GET",
+ "paymentData": payment_data,
+ "paymentMethodType": "ideal",
+ "type": "redirect",
+ "url": "https://test.adyen.com/hpp/redirectIdeal.shtml?brandCode=ideal",
+ }
+ message = {
+ "resultCode": "RedirectShopper",
+ "action": action_data,
+ "details": [{"key": "payload", "type": "text"}],
+ "pspReference": "882595494831959A",
+ }
+ api_call_mock.return_value.message = message
+
+ payment_info = create_payment_information(
+ payment_adyen_for_checkout,
+ additional_data={"paymentMethod": {"paymentdata": ""}},
+ )
+ adyen_plugin = adyen_plugin(auto_capture=True)
+ response = adyen_plugin.process_payment(payment_info, None)
+ assert response.is_success is True
+ assert response.action_required is True
+ assert response.kind == TransactionKind.AUTH
+ assert response.amount == Decimal("1234")
+ assert response.currency == checkout_with_items.currency
+ assert response.transaction_id == "882595494831959A"
+ assert response.error is None
+ assert response.action_required_data == action_data
+
+ payment_adyen_for_checkout.refresh_from_db()
+ assert payment_adyen_for_checkout.extra_data == json.dumps(
+ [{"payment_data": payment_data, "parameters": ["payload"]}]
+ )
+
+
+ @pytest.mark.vcr
+ @mock.patch("saleor.payment.gateways.adyen.plugin.api_call")
+ def test_process_payment_additional_action_payment_does_not_exists(
+ api_call_mock, payment_adyen_for_checkout, checkout_with_items, adyen_plugin
+ ):
+ action_data = {
+ "method": "GET",
+ "paymentData": "Ab02b4c0!B",
+ "paymentMethodType": "ideal",
+ "type": "redirect",
+ "url": "https://test.adyen.com/hpp/redirectIdeal.shtml?brandCode=ideal",
+ }
+ message = {
+ "resultCode": "RedirectShopper",
+ "action": action_data,
+ "details": [{"key": "payload", "type": "text"}],
+ "pspReference": "882595494831959A",
+ }
+ api_call_mock.return_value.message = message
+
+ payment_info = create_payment_information(
+ payment_adyen_for_checkout,
+ additional_data={"paymentMethod": {"paymentdata": ""}},
+ )
+
+ Payment.objects.all().delete()
+
+ adyen_plugin = adyen_plugin(auto_capture=True)
+
+ with pytest.raises(PaymentError) as e:
+ adyen_plugin.process_payment(payment_info, None)
+
+ assert str(e.value) == "Payment cannot be performed. Payment does not exists."
+
+
+ @pytest.mark.vcr
+ @mock.patch("saleor.payment.gateways.adyen.plugin.api_call")
+ def test_process_payment_additional_action_checkout_does_not_exists(
+ api_call_mock, payment_adyen_for_checkout, checkout_with_items, adyen_plugin
+ ):
+ action_data = {
+ "method": "GET",
+ "paymentData": "Ab02b4c0!B",
+ "paymentMethodType": "ideal",
+ "type": "redirect",
+ "url": "https://test.adyen.com/hpp/redirectIdeal.shtml?brandCode=ideal",
+ }
+ message = {
+ "resultCode": "RedirectShopper",
+ "action": action_data,
+ "details": [{"key": "payload", "type": "text"}],
+ "pspReference": "882595494831959A",
+ }
+ api_call_mock.return_value.message = message
+
+ payment_info = create_payment_information(
+ payment_adyen_for_checkout,
+ additional_data={"paymentMethod": {"paymentdata": ""}},
+ )
+
+ payment_adyen_for_checkout.checkout = None
+ payment_adyen_for_checkout.save()
+
+ adyen_plugin = adyen_plugin(auto_capture=True)
+
+ with pytest.raises(PaymentError) as e:
+ adyen_plugin.process_payment(payment_info, None)
+
+ assert (
+ str(e.value)
+ == "Payment cannot be performed. Checkout for this payment does not exist."
+ )
[email protected](reason="To finish when additional auth data schema will be known")
def test_confirm_payment(payment_adyen_for_order, adyen_plugin):
- return # test it when we will have additional auth data
- payment_info = create_payment_information(
- payment_adyen_for_order,
- # additional_data=...
+ payment_info = create_payment_information(payment_adyen_for_order,)
+ gateway_response = GatewayResponse(
+ kind=TransactionKind.AUTH,
+ action_required=False,
+ transaction_id="882595494831959A",
+ is_success=True,
+ amount=payment_info.amount,
+ currency=payment_info.currency,
+ error="",
+ raw_response={},
+ )
+
+ auth_transaction = create_transaction(
+ payment=payment_adyen_for_order,
+ payment_information=payment_info,
+ kind=TransactionKind.AUTH,
+ gateway_response=gateway_response,
)
adyen_plugin = adyen_plugin()
response = adyen_plugin.confirm_payment(payment_info, None)