def test_request_data_for_payment_channel_different_than_web(dummy_payment_data): # given return_url = "https://www.example.com" merchant_account = "MerchantTestAccount" data = {"is_valid": True, "paymentMethod": {"type": "scheme"}, "channel": "iOS"} dummy_payment_data.data = data native_3d_secure = True # when result = request_data_for_payment( dummy_payment_data, return_url, merchant_account, native_3d_secure ) # then assert result == { "amount": { "value": price_to_minor_unit( dummy_payment_data.amount, dummy_payment_data.currency ), "currency": dummy_payment_data.currency, }, "reference": dummy_payment_data.graphql_payment_id, "paymentMethod": {"type": "scheme"}, "returnUrl": return_url, "merchantAccount": merchant_account, "channel": "iOS", "additionalData": {"allow3DS2": "true"}, "shopperEmail": "*****@*****.**", }
def test_request_data_for_payment_without_shipping( dummy_payment_data, dummy_address_data ): # given return_url = "https://www.example.com" merchant_account = "MerchantTestAccount" origin_url = "https://www.example.com" data = { "is_valid": True, "riskData": {"clientData": "test_client_data"}, "paymentMethod": {"type": "scheme"}, "browserInfo": {"acceptHeader": "*/*", "colorDepth": 30, "language": "pl"}, "shopperIP": "123", "originUrl": origin_url, } dummy_payment_data.data = data dummy_payment_data.billing = dummy_address_data dummy_payment_data.shipping = None native_3d_secure = False # when result = request_data_for_payment( dummy_payment_data, return_url, merchant_account, native_3d_secure ) # then assert result == { "amount": { "value": price_to_minor_unit( dummy_payment_data.amount, dummy_payment_data.currency ), "currency": dummy_payment_data.currency, }, "reference": dummy_payment_data.graphql_payment_id, "paymentMethod": {"type": "scheme"}, "returnUrl": return_url, "merchantAccount": merchant_account, "origin": return_url, "shopperIP": data["shopperIP"], "browserInfo": data["browserInfo"], "channel": "web", "shopperEmail": "*****@*****.**", "shopperName": { "firstName": dummy_payment_data.billing.first_name, "lastName": dummy_payment_data.billing.last_name, }, "shopperReference": "*****@*****.**", "billingAddress": { "city": "WROCŁAW", "country": "PL", "houseNumberOrName": "Mirumee Software", "postalCode": "53-601", "stateOrProvince": "ZZ", "street": "Tęczowa 7", }, }
def test_request_data_for_payment_native_3d_secure(dummy_payment_data): # given return_url = "https://www.example.com" merchant_account = "MerchantTestAccount" origin_url = "https://www.example.com" data = { "is_valid": True, "riskData": { "clientData": "test_client_data" }, "paymentMethod": { "type": "scheme" }, "browserInfo": { "acceptHeader": "*/*", "colorDepth": 30, "language": "pl" }, "billingAddress": { "address": "test_address" }, "shopperIP": "123", "originUrl": origin_url, } dummy_payment_data.data = data native_3d_secure = True # when result = request_data_for_payment(dummy_payment_data, return_url, merchant_account, native_3d_secure) # then assert result == { "amount": { "value": to_adyen_price(dummy_payment_data.amount, dummy_payment_data.currency), "currency": dummy_payment_data.currency, }, "reference": dummy_payment_data.graphql_payment_id, "paymentMethod": { "type": "scheme" }, "returnUrl": return_url, "merchantAccount": merchant_account, "origin": origin_url, "shopperIP": data["shopperIP"], "billingAddress": data["billingAddress"], "browserInfo": data["browserInfo"], "channel": "web", "additionalData": { "allow3DS2": "true" }, "shopperEmail": "*****@*****.**", }
def test_request_data_for_payment_payment_not_valid(dummy_payment_data): # given dummy_payment_data.data = { "originUrl": "https://www.example.com", "is_valid": False, } native_3d_secure = False # when with pytest.raises(PaymentError) as e: request_data_for_payment( dummy_payment_data, "https://www.example.com", "MerchantTestAccount", native_3d_secure, ) # then assert str(e._excinfo[1]) == "Payment data are not valid."
def test_request_data_for_payment_channel_different_than_web( dummy_payment_data, dummy_address_data ): # given return_url = "https://www.example.com" merchant_account = "MerchantTestAccount" data = {"is_valid": True, "paymentMethod": {"type": "scheme"}, "channel": "iOS"} dummy_payment_data.data = data dummy_payment_data.billing = dummy_address_data dummy_payment_data.shipping = dummy_address_data native_3d_secure = True # when result = request_data_for_payment( dummy_payment_data, return_url, merchant_account, native_3d_secure ) # then assert result == { "amount": { "value": price_to_minor_unit( dummy_payment_data.amount, dummy_payment_data.currency ), "currency": dummy_payment_data.currency, }, "reference": dummy_payment_data.graphql_payment_id, "paymentMethod": {"type": "scheme"}, "returnUrl": return_url, "merchantAccount": merchant_account, "channel": "iOS", "additionalData": {"allow3DS2": "true"}, "shopperEmail": "*****@*****.**", "shopperName": { "firstName": dummy_payment_data.billing.first_name, "lastName": dummy_payment_data.billing.last_name, }, "shopperReference": "*****@*****.**", "deliveryAddress": { "city": "WROCŁAW", "country": "PL", "houseNumberOrName": "Mirumee Software", "postalCode": "53-601", "stateOrProvince": "ZZ", "street": "Tęczowa 7", }, "billingAddress": { "city": "WROCŁAW", "country": "PL", "houseNumberOrName": "Mirumee Software", "postalCode": "53-601", "stateOrProvince": "ZZ", "street": "Tęczowa 7", }, }
def test_request_data_for_payment_append_klarna_data(append_klarna_data_mock, dummy_payment_data): # given return_url = "https://www.example.com" merchant_account = "MerchantTestAccount" origin_url = "https://www.example.com" data = { "is_valid": True, "riskData": { "clientData": "test_client_data" }, "paymentMethod": { "type": "klarna" }, "browserInfo": { "acceptHeader": "*/*", "colorDepth": 30, "language": "pl" }, "billingAddress": { "address": "test_address" }, "shopperIP": "123", "originUrl": origin_url, } dummy_payment_data.data = data klarna_result = { "amount": { "value": to_adyen_price(dummy_payment_data.amount, dummy_payment_data.currency), "currency": dummy_payment_data.currency, }, "reference": dummy_payment_data.graphql_payment_id, "paymentMethod": { "type": "scheme" }, "returnUrl": return_url, "merchantAccount": merchant_account, "origin": return_url, "shopperIP": data["shopperIP"], "billingAddress": data["billingAddress"], "browserInfo": data["browserInfo"], "shopperLocale": "test_shopper", } append_klarna_data_mock.return_value = klarna_result native_3d_secure = False # when result = request_data_for_payment(dummy_payment_data, return_url, merchant_account, native_3d_secure) # then assert result == klarna_result
def test_request_data_for_payment_when_missing_city_and_count_area( dummy_payment_data, dummy_address_data): # given return_url = "https://www.example.com" merchant_account = "MerchantTestAccount" origin_url = "https://www.example.com" data = { "is_valid": True, "riskData": { "clientData": "test_client_data" }, "paymentMethod": { "type": "scheme" }, "browserInfo": { "acceptHeader": "*/*", "colorDepth": 30, "language": "pl" }, "shopperIP": "123", "originUrl": origin_url, } dummy_payment_data.data = data dummy_address_data.city = "" dummy_address_data.country_area = "" dummy_payment_data.billing = dummy_address_data dummy_payment_data.shipping = dummy_address_data native_3d_secure = False # when result = request_data_for_payment(dummy_payment_data, return_url, merchant_account, native_3d_secure) # then assert result["deliveryAddress"] == { "city": "ZZ", "country": "PL", "houseNumberOrName": "Mirumee Software", "postalCode": "53-601", "stateOrProvince": "", "street": "Tęczowa 7", } assert result["billingAddress"] == { "city": "ZZ", "country": "PL", "houseNumberOrName": "Mirumee Software", "postalCode": "53-601", "stateOrProvince": "", "street": "Tęczowa 7", }