Skip to content

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

Create new stripe payment gateway

Jakub Draganek0e8725c13b08
diff --git a/saleor/payment/gateways/stripe_new/__init__.py b/saleor/payment/gateways/stripe_new/__init__.py
new file mode 100644
index 0000000000..9ae63d5189
--- /dev/null
+++ b/saleor/payment/gateways/stripe_new/__init__.py
@@ -0,0 +1,95 @@
+from typing import Dict
+
+import stripe
+
+from saleor.payment.gateways.stripe.utils import (
+ get_amount_for_stripe,
+ get_amount_from_stripe,
+ get_currency_for_stripe,
+ get_currency_from_stripe,
+)
+
+from ... import TransactionKind
+from ...interface import GatewayConfig, GatewayResponse, PaymentData
+from .forms import StripePaymentModalForm
+from .utils import get_amount_for_stripe, get_currency_for_stripe
+
+
+def get_client_token(**_):
+ """Not implemented for stripe gateway currently. The client token can be
+ generated by Stripe's checkout.js or stripe.js automatically.
+ """
+ return
+
+
+def authorize(
+ payment_information: PaymentData, config: GatewayConfig
+) -> GatewayResponse:
+ error, intent = None, None
+ kind = TransactionKind.CAPTURE if config.auto_capture else TransactionKind.AUTH
+ client = _get_client(**config.connection_params)
+ currency = get_currency_for_stripe(payment_information.currency)
+ stripe_amount = get_amount_for_stripe(payment_information.amount, currency)
+
+ try:
+ intent = client.PaymentIntent.create(
+ payment_method=payment_information.token,
+ amount=stripe_amount,
+ currency=currency,
+ confirmation_method="manual",
+ confirm=True,
+ capture_method="automatic" if config.auto_capture else "manual",
+ )
+ response = GatewayResponse(
+ is_success=intent.status in ("succeeded", "requires_capture"),
+ transaction_id=intent.id,
+ amount=get_amount_from_stripe(intent.amount, currency),
+ currency=get_currency_from_stripe(intent.currency),
+ error=None,
+ kind=kind,
+ raw_response=intent,
+ )
+ except stripe.error.StripeError as exc:
+ response = GatewayResponse(
+ is_success=False,
+ transaction_id=payment_information.token,
+ amount=payment_information.amount,
+ currency=payment_information.currency,
+ error=exc.user_message,
+ kind=kind,
+ raw_response=exc.json_body or {},
+ )
+ return response
+
+
+def capture(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:
+ pass
+
+
+def refund(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:
+ pass
+
+
+def void(payment_information: PaymentData, config: GatewayConfig) -> GatewayResponse:
+ pass
+
+
+def process_payment(
+ payment_information: PaymentData, config: GatewayConfig
+) -> GatewayResponse:
+ return authorize(payment_information, config)
+
+
+def create_form(
+ data: Dict, payment_information: PaymentData, connection_params: Dict
+) -> StripePaymentModalForm:
+ return StripePaymentModalForm(
+ data=data,
+ payment_information=payment_information,
+ gateway_params=connection_params,
+ )
+
+
+def _get_client(**connection_params):
+ stripe.api_key = connection_params.get("secret_key")
+ return stripe
diff --git a/saleor/payment/gateways/stripe_new/forms.py b/saleor/payment/gateways/stripe_new/forms.py
new file mode 100644
index 0000000000..93f8ea0ac3
--- /dev/null
+++ b/saleor/payment/gateways/stripe_new/forms.py
@@ -0,0 +1,85 @@
+from typing import Dict
+
+from django import forms
+from django.forms.utils import flatatt
+from django.forms.widgets import HiddenInput
+from django.utils.html import format_html
+from django.utils.translation import pgettext_lazy
+
+from ...interface import PaymentData
+from .utils import get_amount_for_stripe
+
+CHECKOUT_SCRIPT_URL = "https://checkout.stripe.com/checkout.js"
+CHECKOUT_DESCRIPTION = pgettext_lazy(
+ "Stripe payment gateway description", "Total payment"
+)
+
+
+class StripeCheckoutWidget(HiddenInput):
+ def __init__(
+ self, payment_information: PaymentData, gateway_params: Dict, *args, **kwargs
+ ):
+ attrs = kwargs.get("attrs", {})
+ kwargs["attrs"] = {
+ "class": "stripe-button",
+ "src": CHECKOUT_SCRIPT_URL,
+ "data-key": gateway_params.get("public_key"),
+ "data-amount": get_amount_for_stripe(
+ payment_information.amount, payment_information.currency
+ ),
+ "data-name": gateway_params.get("store_name"),
+ "data-image": gateway_params.get("store_image"),
+ "data-description": CHECKOUT_DESCRIPTION,
+ "data-currency": payment_information.currency,
+ "data-locale": gateway_params.get("locale"),
+ "data-allow-remember-me": "true"
+ if gateway_params.get("remember_me")
+ else "false",
+ "data-billing-address": "true"
+ if gateway_params.get("enable_billing_address")
+ else "false",
+ "data-zip-code": "true"
+ if gateway_params.get("enable_billing_address")
+ else "false",
+ "data-shipping-address": "true"
+ if gateway_params.get("enable_shipping_address")
+ else "false",
+ }
+
+ if gateway_params.get("prefill"):
+ kwargs["attrs"].update({"data-email": payment_information.customer_email})
+
+ kwargs["attrs"].update(attrs)
+ super(StripeCheckoutWidget, self).__init__(*args, **kwargs)
+
+ def render(self, name=None, value=None, attrs=None, renderer=None):
+ attrs = attrs or {}
+ attrs.update(self.attrs)
+ attrs.pop("id", None)
+ return format_html("<script{0}></script>", flatatt(attrs))
+
+
+class StripePaymentModalForm(forms.Form):
+ """The modal form of the Stripe payment provider.
+
+ At this moment partial-payment is not supported, but there is no need to
+ validate amount, which may be manually adjusted in the template,
+ since checkout.js can do that automatically.
+ """
+
+ stripeToken = forms.CharField(required=True, widget=HiddenInput)
+
+ def __init__(
+ self, payment_information: PaymentData, gateway_params: Dict, *args, **kwargs
+ ):
+ super().__init__(*args, **kwargs)
+
+ self.fields["stripe"] = forms.CharField(
+ widget=StripeCheckoutWidget(
+ payment_information=payment_information, gateway_params=gateway_params
+ ),
+ required=False,
+ )
+
+ def get_payment_token(self):
+ return self.cleaned_data["stripeToken"]
diff --git a/saleor/payment/gateways/stripe_new/utils.py b/saleor/payment/gateways/stripe_new/utils.py
new file mode 100644
index 0000000000..03523d4f91
--- /dev/null
+++ b/saleor/payment/gateways/stripe_new/utils.py
@@ -0,0 +1,91 @@
+from decimal import Decimal
+from typing import Dict
+
+from django_countries import countries
+
+# List of zero-decimal currencies
+# Since there is no public API in Stripe backend or helper function
+# in Stripe's Python library, this list is straight out of Stripe's docs
+# https://stripe.com/docs/currencies#zero-decimal
+from ...interface import AddressData, PaymentData
+
+ZERO_DECIMAL_CURRENCIES = [
+ "BIF",
+ "CLP",
+ "DJF",
+ "GNF",
+ "JPY",
+ "KMF",
+ "KRW",
+ "MGA",
+ "PYG",
+ "RWF",
+ "UGX",
+ "VND",
+ "VUV",
+ "XAF",
+ "XOF",
+ "XPF",
+]
+
+
+def get_amount_for_stripe(amount, currency):
+ """Get appropriate amount for stripe.
+ Stripe is using currency's smallest unit such as cents for USD and
+ stripe requires integer instead of decimal, so multiplying by 100
+ and converting to integer is required. But for zero-decimal currencies,
+ multiplying by 100 is not needed.
+ """
+ # Multiply by 100 for non-zero-decimal currencies
+ if currency.upper() not in ZERO_DECIMAL_CURRENCIES:
+ amount *= 100
+
+ # Using int(Decimal) directly may yield wrong result
+ # such as int(Decimal(24.24)*100) will equal to 2423
+ return int(amount.to_integral_value())
+
+
+def get_amount_from_stripe(amount, currency):
+ """Get appropriate amount from stripe."""
+ amount = Decimal(amount)
+
+ # Divide by 100 for non-zero-decimal currencies
+ if currency.upper() not in ZERO_DECIMAL_CURRENCIES:
+ # Using Decimal(amount / 100.0) will convert to decimal from float
+ # where precision may be lost
+ amount /= Decimal(100)
+
+ return amount
+
+
+def get_currency_for_stripe(currency):
+ """Convert Saleor's currency format to Stripe's currency format.
+ Stripe's currency is using lowercase while Saleor is using uppercase.
+ """
+ return currency.lower()
+
+
+def get_currency_from_stripe(currency):
+ """Convert Stripe's currency format to Saleor's currency format.
+ Stripe's currency is using lowercase while Saleor is using uppercase.
+ """
+ return currency.upper()
+
+
+def get_payment_billing_fullname(payment_information: PaymentData) -> str:
+ # Get billing name from payment
+ return "%s %s" % (
+ payment_information.billing.last_name,
+ payment_information.billing.first_name,
+ )
+
+
+def shipping_to_stripe_dict(shipping: AddressData) -> Dict:
+ return {
+ "line1": shipping.street_address_1,
+ "line2": shipping.street_address_2,
+ "city": shipping.city,
+ "state": shipping.country_area,
+ "postal_code": shipping.postal_code,
+ "country": dict(countries).get(shipping.country, ""),
+ }
diff --git a/saleor/settings.py b/saleor/settings.py
index 2bfd4c7fb9..a434000c4c 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -606,9 +606,11 @@ DUMMY = "dummy"
BRAINTREE = "braintree"
RAZORPAY = "razorpay"
STRIPE = "stripe"
+STRIPE_NEW = "stripe_new"
CHECKOUT_PAYMENT_GATEWAYS = {
- DUMMY: pgettext_lazy("Payment method name", "Dummy gateway")
+ DUMMY: pgettext_lazy("Payment method name", "Dummy gateway"),
+ STRIPE_NEW: pgettext_lazy("Payment method name", "Stripe gateway"),
}
PAYMENT_GATEWAYS = {
@@ -673,6 +675,29 @@ PAYMENT_GATEWAYS = {
},
},
},
+ STRIPE_NEW: {
+ "module": "saleor.payment.gateways.stripe_new",
+ "config": {
+ "store_card": get_bool_from_env("STRIPE_STORE_CARD", False),
+ "auto_capture": get_bool_from_env("STRIPE_AUTO_CAPTURE", True),
+ "template_path": "order/payment/stripe.html",
+ "connection_params": {
+ "public_key": os.environ.get("STRIPE_PUBLIC_KEY"),
+ "secret_key": os.environ.get("STRIPE_SECRET_KEY"),
+ "store_name": os.environ.get("STRIPE_STORE_NAME", "Saleor"),
+ "store_image": os.environ.get("STRIPE_STORE_IMAGE", None),
+ "prefill": get_bool_from_env("STRIPE_PREFILL", True),
+ "remember_me": os.environ.get("STRIPE_REMEMBER_ME", True),
+ "locale": os.environ.get("STRIPE_LOCALE", "auto"),
+ "enable_billing_address": os.environ.get(
+ "STRIPE_ENABLE_BILLING_ADDRESS", False
+ ),
+ "enable_shipping_address": os.environ.get(
+ "STRIPE_ENABLE_SHIPPING_ADDRESS", False
+ ),
+ },
+ },
+ },
}
GRAPHENE = {
diff --git a/tests/gateway/cassettes/test_authorize.yaml b/tests/gateway/cassettes/test_authorize.yaml
new file mode 100644
index 0000000000..3b964be893
--- /dev/null
+++ b/tests/gateway/cassettes/test_authorize.yaml
@@ -0,0 +1,478 @@
+interactions:
+- request:
+ body: payment_method=pm_card_pl&amount=4242&currency=usd&confirmation_method=manual&confirm=True
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '90'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - 86a2df12-11ff-478f-b6ab-86c6a3d7856b
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"id\": \"pi_1F4pVYIUmJaD6OqvP2f7TJJs\",\n \"object\": \"payment_intent\"\
+ ,\n \"amount\": 4242,\n \"amount_capturable\": 0,\n \"amount_received\"\
+ : 4242,\n \"application\": null,\n \"application_fee_amount\": null,\n \
+ \ \"canceled_at\": null,\n \"cancellation_reason\": null,\n \"capture_method\"\
+ : \"automatic\",\n \"charges\": {\n \"object\": \"list\",\n \"data\"\
+ : [\n {\n \"id\": \"ch_1F4pVYIUmJaD6OqvaIgZm1nV\",\n \"\
+ object\": \"charge\",\n \"amount\": 4242,\n \"amount_refunded\"\
+ : 0,\n \"application\": null,\n \"application_fee\": null,\n\
+ \ \"application_fee_amount\": null,\n \"balance_transaction\"\
+ : \"txn_1F4pVYIUmJaD6OqvPp8FXmy5\",\n \"billing_details\": {\n \
+ \ \"address\": {\n \"city\": null,\n \"country\"\
+ : null,\n \"line1\": null,\n \"line2\": null,\n \
+ \ \"postal_code\": null,\n \"state\": null\n },\n\
+ \ \"email\": null,\n \"name\": null,\n \"phone\"\
+ : null\n },\n \"captured\": true,\n \"created\": 1565185732,\n\
+ \ \"currency\": \"usd\",\n \"customer\": null,\n \"description\"\
+ : null,\n \"destination\": null,\n \"dispute\": null,\n \
+ \ \"failure_code\": null,\n \"failure_message\": null,\n \
+ \ \"fraud_details\": {\n },\n \"invoice\": null,\n \"\
+ livemode\": false,\n \"metadata\": {\n },\n \"on_behalf_of\"\
+ : null,\n \"order\": null,\n \"outcome\": {\n \"network_status\"\
+ : \"approved_by_network\",\n \"reason\": null,\n \"risk_level\"\
+ : \"normal\",\n \"risk_score\": 32,\n \"seller_message\"\
+ : \"Payment complete.\",\n \"type\": \"authorized\"\n },\n\
+ \ \"paid\": true,\n \"payment_intent\": \"pi_1F4pVYIUmJaD6OqvP2f7TJJs\"\
+ ,\n \"payment_method\": \"pm_1F4pVXIUmJaD6OqvO9uC5ok9\",\n \"\
+ payment_method_details\": {\n \"card\": {\n \"brand\"\
+ : \"visa\",\n \"checks\": {\n \"address_line1_check\"\
+ : null,\n \"address_postal_code_check\": null,\n \
+ \ \"cvc_check\": null\n },\n \"country\": \"PL\",\n\
+ \ \"exp_month\": 8,\n \"exp_year\": 2020,\n \
+ \ \"fingerprint\": \"aleqpF0PMAATcfmb\",\n \"funding\": \"credit\"\
+ ,\n \"last4\": \"0005\",\n \"three_d_secure\": null,\n\
+ \ \"wallet\": null\n },\n \"type\": \"card\"\n\
+ \ },\n \"receipt_email\": null,\n \"receipt_number\"\
+ : null,\n \"receipt_url\": \"https://pay.stripe.com/receipts/acct_1EzlmjIUmJaD6Oqv/ch_1F4pVYIUmJaD6OqvaIgZm1nV/rcpt_FZzUTCq6cC0URALvXaDNa9wHxDpO52d\"\
+ ,\n \"refunded\": false,\n \"refunds\": {\n \"object\"\
+ : \"list\",\n \"data\": [\n\n ],\n \"has_more\"\
+ : false,\n \"total_count\": 0,\n \"url\": \"/v1/charges/ch_1F4pVYIUmJaD6OqvaIgZm1nV/refunds\"\
+ \n },\n \"review\": null,\n \"shipping\": null,\n \
+ \ \"source\": null,\n \"source_transfer\": null,\n \"statement_descriptor\"\
+ : null,\n \"statement_descriptor_suffix\": null,\n \"status\"\
+ : \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n }\n ],\n \"has_more\": false,\n \"total_count\": 1,\n\
+ \ \"url\": \"/v1/charges?payment_intent=pi_1F4pVYIUmJaD6OqvP2f7TJJs\"\n\
+ \ },\n \"client_secret\": \"pi_1F4pVYIUmJaD6OqvP2f7TJJs_secret_H7CU82eglCDj0dXAJTNkQcGze\"\
+ ,\n \"confirmation_method\": \"manual\",\n \"created\": 1565185732,\n \"\
+ currency\": \"usd\",\n \"customer\": null,\n \"description\": null,\n \"\
+ invoice\": null,\n \"last_payment_error\": null,\n \"livemode\": false,\n\
+ \ \"metadata\": {\n },\n \"next_action\": null,\n \"on_behalf_of\": null,\n\
+ \ \"payment_method\": \"pm_1F4pVXIUmJaD6OqvO9uC5ok9\",\n \"payment_method_options\"\
+ : {\n \"card\": {\n \"request_three_d_secure\": \"automatic\"\n \
+ \ }\n },\n \"payment_method_types\": [\n \"card\"\n ],\n \"receipt_email\"\
+ : null,\n \"review\": null,\n \"setup_future_usage\": null,\n \"shipping\"\
+ : null,\n \"source\": null,\n \"statement_descriptor\": null,\n \"statement_descriptor_suffix\"\
+ : null,\n \"status\": \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '3996'
+ Content-Type:
+ - application/json
+ Date:
+ - Wed, 07 Aug 2019 13:48:53 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - 86a2df12-11ff-478f-b6ab-86c6a3d7856b
+ original-request:
+ - req_8S93V2YnPF1OyS
+ request-id:
+ - req_8S93V2YnPF1OyS
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 200
+ message: OK
+- request:
+ body: payment_method=pm_card_pl&amount=4242&currency=usd&confirmation_method=manual&confirm=True&capture_method=automatic
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '115'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - 6afa5daf-7c45-4835-a9be-f9acd81ff14f
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"id\": \"pi_1F5BoRIUmJaD6Oqv03Ly45Q1\",\n \"object\": \"payment_intent\"\
+ ,\n \"amount\": 4242,\n \"amount_capturable\": 0,\n \"amount_received\"\
+ : 4242,\n \"application\": null,\n \"application_fee_amount\": null,\n \
+ \ \"canceled_at\": null,\n \"cancellation_reason\": null,\n \"capture_method\"\
+ : \"automatic\",\n \"charges\": {\n \"object\": \"list\",\n \"data\"\
+ : [\n {\n \"id\": \"ch_1F5BoRIUmJaD6Oqv55kNLyfv\",\n \"\
+ object\": \"charge\",\n \"amount\": 4242,\n \"amount_refunded\"\
+ : 0,\n \"application\": null,\n \"application_fee\": null,\n\
+ \ \"application_fee_amount\": null,\n \"balance_transaction\"\
+ : \"txn_1F5BoRIUmJaD6OqvkYKclkL0\",\n \"billing_details\": {\n \
+ \ \"address\": {\n \"city\": null,\n \"country\"\
+ : null,\n \"line1\": null,\n \"line2\": null,\n \
+ \ \"postal_code\": null,\n \"state\": null\n },\n\
+ \ \"email\": null,\n \"name\": null,\n \"phone\"\
+ : null\n },\n \"captured\": true,\n \"created\": 1565271471,\n\
+ \ \"currency\": \"usd\",\n \"customer\": null,\n \"description\"\
+ : null,\n \"destination\": null,\n \"dispute\": null,\n \
+ \ \"failure_code\": null,\n \"failure_message\": null,\n \
+ \ \"fraud_details\": {\n },\n \"invoice\": null,\n \"\
+ livemode\": false,\n \"metadata\": {\n },\n \"on_behalf_of\"\
+ : null,\n \"order\": null,\n \"outcome\": {\n \"network_status\"\
+ : \"approved_by_network\",\n \"reason\": null,\n \"risk_level\"\
+ : \"normal\",\n \"risk_score\": 32,\n \"seller_message\"\
+ : \"Payment complete.\",\n \"type\": \"authorized\"\n },\n\
+ \ \"paid\": true,\n \"payment_intent\": \"pi_1F5BoRIUmJaD6Oqv03Ly45Q1\"\
+ ,\n \"payment_method\": \"pm_1F5BoRIUmJaD6OqvAffLcapg\",\n \"\
+ payment_method_details\": {\n \"card\": {\n \"brand\"\
+ : \"visa\",\n \"checks\": {\n \"address_line1_check\"\
+ : null,\n \"address_postal_code_check\": null,\n \
+ \ \"cvc_check\": null\n },\n \"country\": \"PL\",\n\
+ \ \"exp_month\": 8,\n \"exp_year\": 2020,\n \
+ \ \"fingerprint\": \"aleqpF0PMAATcfmb\",\n \"funding\": \"credit\"\
+ ,\n \"last4\": \"0005\",\n \"three_d_secure\": null,\n\
+ \ \"wallet\": null\n },\n \"type\": \"card\"\n\
+ \ },\n \"receipt_email\": null,\n \"receipt_number\"\
+ : null,\n \"receipt_url\": \"https://pay.stripe.com/receipts/acct_1EzlmjIUmJaD6Oqv/ch_1F5BoRIUmJaD6Oqv55kNLyfv/rcpt_FaMXtDcFUBkt6KlWuXdhQKQq9X09xVf\"\
+ ,\n \"refunded\": false,\n \"refunds\": {\n \"object\"\
+ : \"list\",\n \"data\": [\n\n ],\n \"has_more\"\
+ : false,\n \"total_count\": 0,\n \"url\": \"/v1/charges/ch_1F5BoRIUmJaD6Oqv55kNLyfv/refunds\"\
+ \n },\n \"review\": null,\n \"shipping\": null,\n \
+ \ \"source\": null,\n \"source_transfer\": null,\n \"statement_descriptor\"\
+ : null,\n \"statement_descriptor_suffix\": null,\n \"status\"\
+ : \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n }\n ],\n \"has_more\": false,\n \"total_count\": 1,\n\
+ \ \"url\": \"/v1/charges?payment_intent=pi_1F5BoRIUmJaD6Oqv03Ly45Q1\"\n\
+ \ },\n \"client_secret\": \"pi_1F5BoRIUmJaD6Oqv03Ly45Q1_secret_zNPgyxupLvz7U94FKGG4cGqQs\"\
+ ,\n \"confirmation_method\": \"manual\",\n \"created\": 1565271471,\n \"\
+ currency\": \"usd\",\n \"customer\": null,\n \"description\": null,\n \"\
+ invoice\": null,\n \"last_payment_error\": null,\n \"livemode\": false,\n\
+ \ \"metadata\": {\n },\n \"next_action\": null,\n \"on_behalf_of\": null,\n\
+ \ \"payment_method\": \"pm_1F5BoRIUmJaD6OqvAffLcapg\",\n \"payment_method_options\"\
+ : {\n \"card\": {\n \"request_three_d_secure\": \"automatic\"\n \
+ \ }\n },\n \"payment_method_types\": [\n \"card\"\n ],\n \"receipt_email\"\
+ : null,\n \"review\": null,\n \"setup_future_usage\": null,\n \"shipping\"\
+ : null,\n \"source\": null,\n \"statement_descriptor\": null,\n \"statement_descriptor_suffix\"\
+ : null,\n \"status\": \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '3996'
+ Content-Type:
+ - application/json
+ Date:
+ - Thu, 08 Aug 2019 13:37:52 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - 6afa5daf-7c45-4835-a9be-f9acd81ff14f
+ original-request:
+ - req_Xs3SMl52WIayjo
+ request-id:
+ - req_Xs3SMl52WIayjo
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 200
+ message: OK
+- request:
+ body: payment_method=pm_card_pl&amount=4242&currency=usd&confirmation_method=manual&confirm=True&capture_method=automatic
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '115'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - 45bb4ac7-3a97-4979-8867-141ee1d598af
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"id\": \"pi_1F5BqtIUmJaD6OqvcyF3TbaZ\",\n \"object\": \"payment_intent\"\
+ ,\n \"amount\": 4242,\n \"amount_capturable\": 0,\n \"amount_received\"\
+ : 4242,\n \"application\": null,\n \"application_fee_amount\": null,\n \
+ \ \"canceled_at\": null,\n \"cancellation_reason\": null,\n \"capture_method\"\
+ : \"automatic\",\n \"charges\": {\n \"object\": \"list\",\n \"data\"\
+ : [\n {\n \"id\": \"ch_1F5BqtIUmJaD6OqvIghCPbWH\",\n \"\
+ object\": \"charge\",\n \"amount\": 4242,\n \"amount_refunded\"\
+ : 0,\n \"application\": null,\n \"application_fee\": null,\n\
+ \ \"application_fee_amount\": null,\n \"balance_transaction\"\
+ : \"txn_1F5BqtIUmJaD6Oqv6RKzEmxT\",\n \"billing_details\": {\n \
+ \ \"address\": {\n \"city\": null,\n \"country\"\
+ : null,\n \"line1\": null,\n \"line2\": null,\n \
+ \ \"postal_code\": null,\n \"state\": null\n },\n\
+ \ \"email\": null,\n \"name\": null,\n \"phone\"\
+ : null\n },\n \"captured\": true,\n \"created\": 1565271623,\n\
+ \ \"currency\": \"usd\",\n \"customer\": null,\n \"description\"\
+ : null,\n \"destination\": null,\n \"dispute\": null,\n \
+ \ \"failure_code\": null,\n \"failure_message\": null,\n \
+ \ \"fraud_details\": {\n },\n \"invoice\": null,\n \"\
+ livemode\": false,\n \"metadata\": {\n },\n \"on_behalf_of\"\
+ : null,\n \"order\": null,\n \"outcome\": {\n \"network_status\"\
+ : \"approved_by_network\",\n \"reason\": null,\n \"risk_level\"\
+ : \"normal\",\n \"risk_score\": 12,\n \"seller_message\"\
+ : \"Payment complete.\",\n \"type\": \"authorized\"\n },\n\
+ \ \"paid\": true,\n \"payment_intent\": \"pi_1F5BqtIUmJaD6OqvcyF3TbaZ\"\
+ ,\n \"payment_method\": \"pm_1F5BqsIUmJaD6OqvuktcY6sD\",\n \"\
+ payment_method_details\": {\n \"card\": {\n \"brand\"\
+ : \"visa\",\n \"checks\": {\n \"address_line1_check\"\
+ : null,\n \"address_postal_code_check\": null,\n \
+ \ \"cvc_check\": null\n },\n \"country\": \"PL\",\n\
+ \ \"exp_month\": 8,\n \"exp_year\": 2020,\n \
+ \ \"fingerprint\": \"aleqpF0PMAATcfmb\",\n \"funding\": \"credit\"\
+ ,\n \"last4\": \"0005\",\n \"three_d_secure\": null,\n\
+ \ \"wallet\": null\n },\n \"type\": \"card\"\n\
+ \ },\n \"receipt_email\": null,\n \"receipt_number\"\
+ : null,\n \"receipt_url\": \"https://pay.stripe.com/receipts/acct_1EzlmjIUmJaD6Oqv/ch_1F5BqtIUmJaD6OqvIghCPbWH/rcpt_FaMaP0ugMSJhcczaMpqMi6fkcpSaBAk\"\
+ ,\n \"refunded\": false,\n \"refunds\": {\n \"object\"\
+ : \"list\",\n \"data\": [\n\n ],\n \"has_more\"\
+ : false,\n \"total_count\": 0,\n \"url\": \"/v1/charges/ch_1F5BqtIUmJaD6OqvIghCPbWH/refunds\"\
+ \n },\n \"review\": null,\n \"shipping\": null,\n \
+ \ \"source\": null,\n \"source_transfer\": null,\n \"statement_descriptor\"\
+ : null,\n \"statement_descriptor_suffix\": null,\n \"status\"\
+ : \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n }\n ],\n \"has_more\": false,\n \"total_count\": 1,\n\
+ \ \"url\": \"/v1/charges?payment_intent=pi_1F5BqtIUmJaD6OqvcyF3TbaZ\"\n\
+ \ },\n \"client_secret\": \"pi_1F5BqtIUmJaD6OqvcyF3TbaZ_secret_T2aC8t512p9jFOwskIxyqQI3d\"\
+ ,\n \"confirmation_method\": \"manual\",\n \"created\": 1565271623,\n \"\
+ currency\": \"usd\",\n \"customer\": null,\n \"description\": null,\n \"\
+ invoice\": null,\n \"last_payment_error\": null,\n \"livemode\": false,\n\
+ \ \"metadata\": {\n },\n \"next_action\": null,\n \"on_behalf_of\": null,\n\
+ \ \"payment_method\": \"pm_1F5BqsIUmJaD6OqvuktcY6sD\",\n \"payment_method_options\"\
+ : {\n \"card\": {\n \"request_three_d_secure\": \"automatic\"\n \
+ \ }\n },\n \"payment_method_types\": [\n \"card\"\n ],\n \"receipt_email\"\
+ : null,\n \"review\": null,\n \"setup_future_usage\": null,\n \"shipping\"\
+ : null,\n \"source\": null,\n \"statement_descriptor\": null,\n \"statement_descriptor_suffix\"\
+ : null,\n \"status\": \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '3996'
+ Content-Type:
+ - application/json
+ Date:
+ - Thu, 08 Aug 2019 13:40:24 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - 45bb4ac7-3a97-4979-8867-141ee1d598af
+ original-request:
+ - req_YUZwIYFjguCgKX
+ request-id:
+ - req_YUZwIYFjguCgKX
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 200
+ message: OK
+- request:
+ body: payment_method=pm_card_pl&amount=4242&currency=usd&confirmation_method=manual&confirm=True&capture_method=automatic
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '115'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - b03a30c0-feeb-442c-99d4-042d1763d0a6
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"id\": \"pi_1F5BsOIUmJaD6Oqvmh5vBJIA\",\n \"object\": \"payment_intent\"\
+ ,\n \"amount\": 4242,\n \"amount_capturable\": 0,\n \"amount_received\"\
+ : 4242,\n \"application\": null,\n \"application_fee_amount\": null,\n \
+ \ \"canceled_at\": null,\n \"cancellation_reason\": null,\n \"capture_method\"\
+ : \"automatic\",\n \"charges\": {\n \"object\": \"list\",\n \"data\"\
+ : [\n {\n \"id\": \"ch_1F5BsOIUmJaD6OqvbM6tKDjc\",\n \"\
+ object\": \"charge\",\n \"amount\": 4242,\n \"amount_refunded\"\
+ : 0,\n \"application\": null,\n \"application_fee\": null,\n\
+ \ \"application_fee_amount\": null,\n \"balance_transaction\"\
+ : \"txn_1F5BsOIUmJaD6OqvoDuvgoCK\",\n \"billing_details\": {\n \
+ \ \"address\": {\n \"city\": null,\n \"country\"\
+ : null,\n \"line1\": null,\n \"line2\": null,\n \
+ \ \"postal_code\": null,\n \"state\": null\n },\n\
+ \ \"email\": null,\n \"name\": null,\n \"phone\"\
+ : null\n },\n \"captured\": true,\n \"created\": 1565271716,\n\
+ \ \"currency\": \"usd\",\n \"customer\": null,\n \"description\"\
+ : null,\n \"destination\": null,\n \"dispute\": null,\n \
+ \ \"failure_code\": null,\n \"failure_message\": null,\n \
+ \ \"fraud_details\": {\n },\n \"invoice\": null,\n \"\
+ livemode\": false,\n \"metadata\": {\n },\n \"on_behalf_of\"\
+ : null,\n \"order\": null,\n \"outcome\": {\n \"network_status\"\
+ : \"approved_by_network\",\n \"reason\": null,\n \"risk_level\"\
+ : \"normal\",\n \"risk_score\": 8,\n \"seller_message\"\
+ : \"Payment complete.\",\n \"type\": \"authorized\"\n },\n\
+ \ \"paid\": true,\n \"payment_intent\": \"pi_1F5BsOIUmJaD6Oqvmh5vBJIA\"\
+ ,\n \"payment_method\": \"pm_1F5BsOIUmJaD6OqvM6mSN7La\",\n \"\
+ payment_method_details\": {\n \"card\": {\n \"brand\"\
+ : \"visa\",\n \"checks\": {\n \"address_line1_check\"\
+ : null,\n \"address_postal_code_check\": null,\n \
+ \ \"cvc_check\": null\n },\n \"country\": \"PL\",\n\
+ \ \"exp_month\": 8,\n \"exp_year\": 2020,\n \
+ \ \"fingerprint\": \"aleqpF0PMAATcfmb\",\n \"funding\": \"credit\"\
+ ,\n \"last4\": \"0005\",\n \"three_d_secure\": null,\n\
+ \ \"wallet\": null\n },\n \"type\": \"card\"\n\
+ \ },\n \"receipt_email\": null,\n \"receipt_number\"\
+ : null,\n \"receipt_url\": \"https://pay.stripe.com/receipts/acct_1EzlmjIUmJaD6Oqv/ch_1F5BsOIUmJaD6OqvbM6tKDjc/rcpt_FaMbz3hC4CA0NuWiuFFISgfPltn2h4U\"\
+ ,\n \"refunded\": false,\n \"refunds\": {\n \"object\"\
+ : \"list\",\n \"data\": [\n\n ],\n \"has_more\"\
+ : false,\n \"total_count\": 0,\n \"url\": \"/v1/charges/ch_1F5BsOIUmJaD6OqvbM6tKDjc/refunds\"\
+ \n },\n \"review\": null,\n \"shipping\": null,\n \
+ \ \"source\": null,\n \"source_transfer\": null,\n \"statement_descriptor\"\
+ : null,\n \"statement_descriptor_suffix\": null,\n \"status\"\
+ : \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n }\n ],\n \"has_more\": false,\n \"total_count\": 1,\n\
+ \ \"url\": \"/v1/charges?payment_intent=pi_1F5BsOIUmJaD6Oqvmh5vBJIA\"\n\
+ \ },\n \"client_secret\": \"pi_1F5BsOIUmJaD6Oqvmh5vBJIA_secret_bpJHb3g4rDKbYxIlWakCkartF\"\
+ ,\n \"confirmation_method\": \"manual\",\n \"created\": 1565271716,\n \"\
+ currency\": \"usd\",\n \"customer\": null,\n \"description\": null,\n \"\
+ invoice\": null,\n \"last_payment_error\": null,\n \"livemode\": false,\n\
+ \ \"metadata\": {\n },\n \"next_action\": null,\n \"on_behalf_of\": null,\n\
+ \ \"payment_method\": \"pm_1F5BsOIUmJaD6OqvM6mSN7La\",\n \"payment_method_options\"\
+ : {\n \"card\": {\n \"request_three_d_secure\": \"automatic\"\n \
+ \ }\n },\n \"payment_method_types\": [\n \"card\"\n ],\n \"receipt_email\"\
+ : null,\n \"review\": null,\n \"setup_future_usage\": null,\n \"shipping\"\
+ : null,\n \"source\": null,\n \"statement_descriptor\": null,\n \"statement_descriptor_suffix\"\
+ : null,\n \"status\": \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '3995'
+ Content-Type:
+ - application/json
+ Date:
+ - Thu, 08 Aug 2019 13:41:57 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - b03a30c0-feeb-442c-99d4-042d1763d0a6
+ original-request:
+ - req_Yp2Xralp4YSSas
+ request-id:
+ - req_Yp2Xralp4YSSas
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 200
+ message: OK
+version: 1
diff --git a/tests/gateway/cassettes/test_authorize_error_response.yaml b/tests/gateway/cassettes/test_authorize_error_response.yaml
new file mode 100644
index 0000000000..43c7ef709a
--- /dev/null
+++ b/tests/gateway/cassettes/test_authorize_error_response.yaml
@@ -0,0 +1,278 @@
+interactions:
+- request:
+ body: payment_method=abcdefghijklmnoprstquwz&amount=4242&currency=usd&confirmation_method=manual&confirm=True
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '103'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - 6172c460-3a9c-424e-a190-036c7406ea53
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-Telemetry:
+ - '{"last_request_metrics": {"request_id": "req_8S93V2YnPF1OyS", "request_duration_ms":
+ 75}}'
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"error\": {\n \"code\": \"resource_missing\",\n \"doc_url\"\
+ : \"https://stripe.com/docs/error-codes/resource-missing\",\n \"message\"\
+ : \"No such payment_method: abcdefghijklmnoprstquwz\",\n \"param\": \"\
+ payment_method\",\n \"type\": \"invalid_request_error\"\n }\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '257'
+ Content-Type:
+ - application/json
+ Date:
+ - Thu, 08 Aug 2019 13:01:25 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - 6172c460-3a9c-424e-a190-036c7406ea53
+ original-request:
+ - req_6K0JNwQccyE7q0
+ request-id:
+ - req_6K0JNwQccyE7q0
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 400
+ message: Bad Request
+- request:
+ body: payment_method=abcdefghijklmnoprstquwz&amount=4242&currency=usd&confirmation_method=manual&confirm=True&capture_method=automatic
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '128'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - 86b391dc-2c40-4b7d-a879-2a2c4eea9829
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-Telemetry:
+ - '{"last_request_metrics": {"request_id": "req_Xs3SMl52WIayjo", "request_duration_ms":
+ 1640}}'
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"error\": {\n \"code\": \"resource_missing\",\n \"doc_url\"\
+ : \"https://stripe.com/docs/error-codes/resource-missing\",\n \"message\"\
+ : \"No such payment_method: abcdefghijklmnoprstquwz\",\n \"param\": \"\
+ payment_method\",\n \"type\": \"invalid_request_error\"\n }\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '257'
+ Content-Type:
+ - application/json
+ Date:
+ - Thu, 08 Aug 2019 13:37:52 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - 86b391dc-2c40-4b7d-a879-2a2c4eea9829
+ original-request:
+ - req_RuacIvBFwUqhLp
+ request-id:
+ - req_RuacIvBFwUqhLp
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 400
+ message: Bad Request
+- request:
+ body: payment_method=abcdefghijklmnoprstquwz&amount=4242&currency=usd&confirmation_method=manual&confirm=True&capture_method=automatic
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '128'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - 62996bcb-2954-48a3-9916-209c5993b74d
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-Telemetry:
+ - '{"last_request_metrics": {"request_id": "req_YUZwIYFjguCgKX", "request_duration_ms":
+ 1539}}'
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"error\": {\n \"code\": \"resource_missing\",\n \"doc_url\"\
+ : \"https://stripe.com/docs/error-codes/resource-missing\",\n \"message\"\
+ : \"No such payment_method: abcdefghijklmnoprstquwz\",\n \"param\": \"\
+ payment_method\",\n \"type\": \"invalid_request_error\"\n }\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '257'
+ Content-Type:
+ - application/json
+ Date:
+ - Thu, 08 Aug 2019 13:40:24 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - 62996bcb-2954-48a3-9916-209c5993b74d
+ original-request:
+ - req_02IDhq6m8xrUYO
+ request-id:
+ - req_02IDhq6m8xrUYO
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 400
+ message: Bad Request
+- request:
+ body: payment_method=abcdefghijklmnoprstquwz&amount=4242&currency=usd&confirmation_method=manual&confirm=True&capture_method=automatic
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '128'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - 19b4617d-3ac2-4e6a-9437-6968cc4f7a0d
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-Telemetry:
+ - '{"last_request_metrics": {"request_id": "req_Yp2Xralp4YSSas", "request_duration_ms":
+ 1884}}'
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"error\": {\n \"code\": \"resource_missing\",\n \"doc_url\"\
+ : \"https://stripe.com/docs/error-codes/resource-missing\",\n \"message\"\
+ : \"No such payment_method: abcdefghijklmnoprstquwz\",\n \"param\": \"\
+ payment_method\",\n \"type\": \"invalid_request_error\"\n }\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '257'
+ Content-Type:
+ - application/json
+ Date:
+ - Thu, 08 Aug 2019 13:41:58 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - 19b4617d-3ac2-4e6a-9437-6968cc4f7a0d
+ original-request:
+ - req_KxLRnayybvlIeS
+ request-id:
+ - req_KxLRnayybvlIeS
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 400
+ message: Bad Request
+version: 1
diff --git a/tests/gateway/cassettes/test_authorize_without_capture.yaml b/tests/gateway/cassettes/test_authorize_without_capture.yaml
new file mode 100644
index 0000000000..b9b126d5df
--- /dev/null
+++ b/tests/gateway/cassettes/test_authorize_without_capture.yaml
@@ -0,0 +1,124 @@
+interactions:
+- request:
+ body: payment_method=pm_card_pl&amount=4242&currency=usd&confirmation_method=manual&confirm=True&capture_method=manual
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '112'
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Idempotency-Key:
+ - 9776ddc6-aff7-4265-aa0b-d1836d01f8d1
+ User-Agent:
+ - Stripe/v1 PythonBindings/2.33.0
+ X-Stripe-Client-Telemetry:
+ - '{"last_request_metrics": {"request_id": "req_KxLRnayybvlIeS", "request_duration_ms":
+ 627}}'
+ X-Stripe-Client-User-Agent:
+ - '{"bindings_version": "2.33.0", "lang": "python", "publisher": "stripe", "httplib":
+ "requests", "lang_version": "3.7.4", "platform": "Darwin-18.7.0-x86_64-i386-64bit",
+ "uname": "Darwin mbp-jakub.lan 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun
+ 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64 i386"}'
+ method: POST
+ uri: https://api.stripe.com/v1/payment_intents
+ response:
+ body:
+ string: "{\n \"id\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD\",\n \"object\": \"payment_intent\"\
+ ,\n \"amount\": 4242,\n \"amount_capturable\": 4242,\n \"amount_received\"\
+ : 0,\n \"application\": null,\n \"application_fee_amount\": null,\n \"\
+ canceled_at\": null,\n \"cancellation_reason\": null,\n \"capture_method\"\
+ : \"manual\",\n \"charges\": {\n \"object\": \"list\",\n \"data\":\
+ \ [\n {\n \"id\": \"ch_1F5BsRIUmJaD6Oqvl2WF1xdU\",\n \"\
+ object\": \"charge\",\n \"amount\": 4242,\n \"amount_refunded\"\
+ : 0,\n \"application\": null,\n \"application_fee\": null,\n\
+ \ \"application_fee_amount\": null,\n \"balance_transaction\"\
+ : null,\n \"billing_details\": {\n \"address\": {\n \
+ \ \"city\": null,\n \"country\": null,\n \"line1\"\
+ : null,\n \"line2\": null,\n \"postal_code\": null,\n\
+ \ \"state\": null\n },\n \"email\": null,\n \
+ \ \"name\": null,\n \"phone\": null\n },\n \
+ \ \"captured\": false,\n \"created\": 1565271719,\n \"currency\"\
+ : \"usd\",\n \"customer\": null,\n \"description\": null,\n\
+ \ \"destination\": null,\n \"dispute\": null,\n \"failure_code\"\
+ : null,\n \"failure_message\": null,\n \"fraud_details\": {\n\
+ \ },\n \"invoice\": null,\n \"livemode\": false,\n \
+ \ \"metadata\": {\n },\n \"on_behalf_of\": null,\n \
+ \ \"order\": null,\n \"outcome\": {\n \"network_status\"\
+ : \"approved_by_network\",\n \"reason\": null,\n \"risk_level\"\
+ : \"normal\",\n \"risk_score\": 10,\n \"seller_message\"\
+ : \"Payment complete.\",\n \"type\": \"authorized\"\n },\n\
+ \ \"paid\": true,\n \"payment_intent\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD\"\
+ ,\n \"payment_method\": \"pm_1F5BsQIUmJaD6OqvbB4aOcJX\",\n \"\
+ payment_method_details\": {\n \"card\": {\n \"brand\"\
+ : \"visa\",\n \"checks\": {\n \"address_line1_check\"\
+ : null,\n \"address_postal_code_check\": null,\n \
+ \ \"cvc_check\": null\n },\n \"country\": \"PL\",\n\
+ \ \"exp_month\": 8,\n \"exp_year\": 2020,\n \
+ \ \"fingerprint\": \"aleqpF0PMAATcfmb\",\n \"funding\": \"credit\"\
+ ,\n \"last4\": \"0005\",\n \"three_d_secure\": null,\n\
+ \ \"wallet\": null\n },\n \"type\": \"card\"\n\
+ \ },\n \"receipt_email\": null,\n \"receipt_number\"\
+ : null,\n \"receipt_url\": \"https://pay.stripe.com/receipts/acct_1EzlmjIUmJaD6Oqv/ch_1F5BsRIUmJaD6Oqvl2WF1xdU/rcpt_FaMbtUmGgcY6xnKYCxzQgjVlAwLno4y\"\
+ ,\n \"refunded\": false,\n \"refunds\": {\n \"object\"\
+ : \"list\",\n \"data\": [\n\n ],\n \"has_more\"\
+ : false,\n \"total_count\": 0,\n \"url\": \"/v1/charges/ch_1F5BsRIUmJaD6Oqvl2WF1xdU/refunds\"\
+ \n },\n \"review\": null,\n \"shipping\": null,\n \
+ \ \"source\": null,\n \"source_transfer\": null,\n \"statement_descriptor\"\
+ : null,\n \"statement_descriptor_suffix\": null,\n \"status\"\
+ : \"succeeded\",\n \"transfer_data\": null,\n \"transfer_group\"\
+ : null\n }\n ],\n \"has_more\": false,\n \"total_count\": 1,\n\
+ \ \"url\": \"/v1/charges?payment_intent=pi_1F5BsRIUmJaD6Oqvz2XMKZCD\"\n\
+ \ },\n \"client_secret\": \"pi_1F5BsRIUmJaD6Oqvz2XMKZCD_secret_FnZ8ApzrD4JVONWgCbLGbKAdI\"\
+ ,\n \"confirmation_method\": \"manual\",\n \"created\": 1565271719,\n \"\
+ currency\": \"usd\",\n \"customer\": null,\n \"description\": null,\n \"\
+ invoice\": null,\n \"last_payment_error\": null,\n \"livemode\": false,\n\
+ \ \"metadata\": {\n },\n \"next_action\": null,\n \"on_behalf_of\": null,\n\
+ \ \"payment_method\": \"pm_1F5BsQIUmJaD6OqvbB4aOcJX\",\n \"payment_method_options\"\
+ : {\n \"card\": {\n \"request_three_d_secure\": \"automatic\"\n \
+ \ }\n },\n \"payment_method_types\": [\n \"card\"\n ],\n \"receipt_email\"\
+ : null,\n \"review\": null,\n \"setup_future_usage\": null,\n \"shipping\"\
+ : null,\n \"source\": null,\n \"statement_descriptor\": null,\n \"statement_descriptor_suffix\"\
+ : null,\n \"status\": \"requires_capture\",\n \"transfer_data\": null,\n\
+ \ \"transfer_group\": null\n}\n"
+ headers:
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '3975'
+ Content-Type:
+ - application/json
+ Date:
+ - Thu, 08 Aug 2019 13:41:59 GMT
+ Server:
+ - nginx
+ Strict-Transport-Security:
+ - max-age=31556926; includeSubDomains; preload
+ access-control-allow-credentials:
+ - 'true'
+ access-control-allow-methods:
+ - GET, POST, HEAD, OPTIONS, DELETE
+ access-control-allow-origin:
+ - '*'
+ access-control-expose-headers:
+ - Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
+ access-control-max-age:
+ - '300'
+ cache-control:
+ - no-cache, no-store
+ idempotency-key:
+ - 9776ddc6-aff7-4265-aa0b-d1836d01f8d1
+ original-request:
+ - req_z1CtFdtgNMk5eX
+ request-id:
+ - req_z1CtFdtgNMk5eX
+ stripe-version:
+ - '2019-05-16'
+ status:
+ code: 200
+ message: OK
+version: 1
diff --git a/tests/gateway/test_stripe_new.py b/tests/gateway/test_stripe_new.py
new file mode 100644
index 0000000000..d221960413
--- /dev/null
+++ b/tests/gateway/test_stripe_new.py
@@ -0,0 +1,130 @@
+from decimal import Decimal
+from math import isclose
+import os
+
+import pytest
+
+from saleor.payment import ChargeStatus
+from saleor.payment.gateways.stripe_new import TransactionKind, authorize, capture
+from saleor.payment.interface import GatewayConfig
+from saleor.payment.utils import create_payment_information
+
+TRANSACTION_AMOUNT = Decimal(42.42)
+TRANSACTION_REFUND_AMOUNT = Decimal(24.24)
+TRANSACTION_CURRENCY = "USD"
+PAYMENT_METHOD_CARD_SIMPLE = "pm_card_pl"
+
+# Set to True if recording new cassette with sandbox using credentials in env
+RECORD = True
+
+
+def gateway_config():
+ return GatewayConfig(
+ gateway_name="stripe_new",
+ auto_capture=True,
+ template_path="template.html",
+ connection_params={
+ "public_key": "public",
+ "secret_key": "secret",
+ "store_name": "Saleor",
+ "store_image": "image.gif",
+ "prefill": True,
+ "remember_me": True,
+ "locale": "auto",
+ "enable_billing_address": False,
+ "enable_shipping_address": False,
+ },
+ )
+
+
+def sandbox_gateway_config(gateway_config):
+ if RECORD:
+ connection_params = {
+ "public_key": os.environ.get("STRIPE_PUBLIC_KEY"),
+ "secret_key": os.environ.get("STRIPE_SECRET_KEY"),
+ }
+ gateway_config.connection_params.update(connection_params)
+ return gateway_config
+
+
+def stripe_payment(payment_dummy):
+ payment_dummy.total = TRANSACTION_AMOUNT
+ payment_dummy.currency = TRANSACTION_CURRENCY
+ return payment_dummy
+
+
[email protected](filter_headers=["authorization"])
+def test_authorize(sandbox_gateway_config, stripe_payment):
+ payment_info = create_payment_information(
+ stripe_payment, PAYMENT_METHOD_CARD_SIMPLE
+ )
+ response = authorize(payment_info, sandbox_gateway_config)
+ assert not response.error
+ assert response.kind == TransactionKind.CAPTURE
+ assert isclose(response.amount, TRANSACTION_AMOUNT)
+ assert response.currency == TRANSACTION_CURRENCY
+ assert response.is_success is True
+
+
[email protected](filter_headers=["authorization"])
+def test_authorize_error_response(stripe_payment, sandbox_gateway_config):
+ INVALID_METHOD = "abcdefghijklmnoprstquwz"
+ payment_info = create_payment_information(stripe_payment, INVALID_METHOD)
+ response = authorize(payment_info, sandbox_gateway_config)
+
+ assert response.error == "No such payment_method: " + INVALID_METHOD
+ assert response.transaction_id == INVALID_METHOD
+ assert response.kind == TransactionKind.CAPTURE
+ assert not response.is_success
+ assert response.amount == stripe_payment.total
+ assert response.currency == stripe_payment.currency
+
+
[email protected](filter_headers=["authorization"])
+def test_authorize_without_capture(stripe_payment, sandbox_gateway_config):
+ sandbox_gateway_config.auto_capture = False
+ payment_info = create_payment_information(
+ stripe_payment, PAYMENT_METHOD_CARD_SIMPLE
+ )
+ response = authorize(payment_info, sandbox_gateway_config)
+ assert not response.error
+ assert response.kind == TransactionKind.AUTH
+ assert isclose(response.amount, TRANSACTION_AMOUNT)
+ assert response.currency == TRANSACTION_CURRENCY
+ assert response.is_success is True
+
+
+# @pytest.fixture()
+# def stripe_authorized_payment(stripe_payment):
+# stripe_payment.charge_status = ChargeStatus.NOT_CHARGED
+# stripe_payment.save(update_fields=["charge_status"])
+#
+# return stripe_payment
+#
+#
+# @pytest.mark.integration
+# @pytest.mark.vcr(filter_headers=["authorization"])
+# def test_capture(
+# stripe_authorized_payment,
+# gateway_config,
+# stripe_charge_success_response,
+# ):
+# payment = stripe_authorized_payment
+# payment_info = create_payment_information(payment, amount=TRANSACTION_AMOUNT)
+# response = stripe_charge_success_response
+#
+# response = capture(payment_info, gateway_config)
+#
+# assert not response.error
+# assert response.transaction_id == PAYMENT_METHOD_CARD_SIMPLE
+# assert response.kind == TransactionKind.CAPTURE
+# assert response.is_success
+# assert isclose(response.amount, TRANSACTION_AMOUNT)
+# assert response.currency == TRANSACTION_CURRENCY
+# assert response.raw_response == stripe_charge_success_response