Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Rename Payment Provider to Payment GAteway, Payment's variant to Payment's gateway
Pacu24d9419b52efa
diff --git a/docs/architecture/payments.rst b/docs/architecture/payments.rstindex bca8d6984d..a3e5f138e5 100644--- a/docs/architecture/payments.rst+++ b/docs/architecture/payments.rst@@ -7,8 +7,8 @@ Supported GatewaysThe default configuration uses the `dummy` backend.It's meant to allow developers to easily simulate different payment results.-Supported payment providers:-^^^^^^^^^^^^^^^^^^^^^^^^^^^^+Supported payment gateways:+^^^^^^^^^^^^^^^^^^^^^^^^^^^* Braintree (supports PayPal and Credit Cards)@@ -29,7 +29,7 @@ Authorization and capture is a two-step process.Firstly the funds are locked on the payer's account but are not transferred to your bank.-Then depending on the provider and the card type, you have between a few days and a month to charge the card for an amount not exceeding the authorized amount.+Then depending on the gateway and the card type, you have between a few days and a month to charge the card for an amount not exceeding the authorized amount.This is very useful when an exact price cannot be determined until after the order is prepared,or we want to capture the money as soon as we ship the order.diff --git a/docs/guides/payments.rst b/docs/guides/payments.rstindex 27d5708650..983b9f88ea 100644--- a/docs/guides/payments.rst+++ b/docs/guides/payments.rst@@ -6,11 +6,11 @@ PaymentsIntegrating a new Payment Gateway into Saleor----------------------------------------------We are using a universal flow, that each provider should fulfill, there are+We are using a universal flow, that each gateway should fulfill, there areseveral methods that should be implemented.Your changes should live under the-``saleor.payment.providers.<provider name>`` module.+``saleor.payment.gateways.<gateway name>`` module... note::@@ -22,7 +22,7 @@ get_transaction_token(**connection_params)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^A transaction token is a signed data blob that includes configuration and-authorization information required by the payment provider.+authorization information required by the payment gateway.These should not be reused; a new transaction token should be generated foreach payment request.@@ -33,7 +33,7 @@ Example.. code-block:: pythondef get_transaction_token(**connection_params: Dict) -> str:- gateway = get_gateway(**connection_params)+ gateway = get_payment_gateway(**connection_params)transaction_token = gateway.transaction_token.generate()return transaction_token@@ -61,7 +61,7 @@ Exampletransaction_type=TransactionType.AUTH,amount=payment.total,currency=payment.currency,- gateway_response=get_gateway_response(response),+ gateway_response=get_payment_gateway_response(response),token=response.transaction.id,is_success=response.is_success)return txn, response['error']@@ -97,7 +97,7 @@ Examplecurrency=payment.currency,token=response.transaction.id,is_success=response.is_success,- gateway_response=get_gateway_response(response))+ gateway_response=get_payment_gateway_response(response))return txn, response['error']capture(payment, amount, **connection_params)@@ -130,7 +130,7 @@ Examplecurrency=payment.currency,token=response.transaction.id,is_success=response.is_success,- gateway_response=get_gateway_response(response))+ gateway_response=get_payment_gateway_response(response))return txn, response['error']void(payment, **connection_params)@@ -160,7 +160,7 @@ Exampletransaction_type=TransactionType.VOID,amount=payment.total,currency=payment.currency,- gateway_response=get_gateway_response(response),+ gateway_response=get_payment_gateway_response(response),token=response.transaction.id,is_success=response.is_success)return txn, response['error']@@ -191,14 +191,14 @@ Returns| ``transaction_token`` | `str` | Unique transaction's token that will be used on the purpose of completing the payment process. |+-----------------------+---------------+-----------------------------------------------------------------------------------------------------------+-Adding new payment provider in the settings--------------------------------------------+Adding new payment gateway to the settings+------------------------------------------.. code-block:: python- PAYMENT_PROVIDERS = {+ PAYMENT_GATEWAYS = {'braintree': {- 'module': 'saleor.payment.providers.braintree',+ 'module': 'saleor.payment.gateways.braintree','connection_params': {'sandbox_mode': get_bool_from_env('BRAINTREE_SANDBOX_MODE', True),'merchant_id': os.environ.get('BRAINTREE_MERCHANT_ID'),@@ -211,14 +211,14 @@ Adding new payment provider in the settingsPlease take a moment to consider the example settings above.- ``braintree``- Provider's name, which will be used to identify the gateway+ Gateway's name, which will be used to identify the gatewayduring the payment process.- It's stored in the ``Payment`` model under the ``variant`` value.+ It's stored in the ``Payment`` model under the ``gateway`` value.- ``module``The path to the integration module(assuming that your changes live within the- ``saleor.payment.providers.braintree.__init__.py`` file)+ ``saleor.payment.gateways.braintree.__init__.py`` file)- ``connection_params``List of parameters used for connecting to the payment's gateway.@@ -229,8 +229,8 @@ Please take a moment to consider the example settings above.This is very useful for development but make sure you useproduction mode when deploying to a production server.-Enabling new payment provider------------------------------+Enabling new payment gateway+-----------------------------Last but not least, if you want to enable your payment provider in the checkout-process, add it's name to the ``CHECKOUT_PAYMENT_CHOICES`` setting.+Last but not least, if you want to enable your payment gateway in the checkout+process, add it's name to the ``CHECKOUT_PAYMENT_GATEWAYS`` setting.diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex e2fe2904c9..7326a32f2b 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -27,7 +27,11 @@ from ...menu.models import Menufrom ...order.models import Fulfillment, Orderfrom ...order.utils import update_order_statusfrom ...page.models import Page+<<<<<<< HEADfrom ...payment import ChargeStatus, TransactionType+=======+from ...payment import ChargeStatus, TransactionType, get_payment_gateway+>>>>>>> Rename Payment Provider to Payment GAteway, Payment's variant to Payment's gatewayfrom ...payment.models import Paymentfrom ...payment.utils import get_billing_datafrom ...product.models import (@@ -409,8 +413,7 @@ def create_payment(order):ChargeStatus.CHARGED,ChargeStatus.NOT_CHARGED])payment = Payment.objects.create(- charge_status=status,- variant='default',+ gateway=settings.DUMMY,customer_ip_address=fake.ipv4(),is_active=True,order=order,@@ -418,23 +421,23 @@ def create_payment(order):currency=order.total.gross.currency,**get_billing_data(order))- provider, provider_params = get_provider(payment.variant)- transaction_token = provider.get_transaction_token(**provider_params)+ gateway, gateway_params = get_payment_gateway(payment.gateway)+ transaction_token = gateway.get_transaction_token(**gateway_params)# Create authorization transaction- gateway_authorize(payment, transaction_token, **provider_params)+ gateway_authorize(payment, transaction_token, **gateway_params)# 20% chance to void the transaction at this stageif random.choice([0, 0, 0, 0, 1]):- gateway_void(payment, **provider_params)+ gateway_void(payment, **gateway_params)return payment# 25% to end the payment at the authorization stageif not random.choice([1, 1, 1, 0]):return payment# Create capture transaction- gateway_capture(payment, payment.total, **provider_params)+ gateway_capture(payment, payment.total, **gateway_params)# 25% to refund the paymentif random.choice([0, 0, 0, 1]):- gateway_refund(payment, payment.total, **provider_params)+ gateway_refund(payment, payment.total, **gateway_params)return paymentdiff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 3a822100e8..9bb9450214 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -299,7 +299,7 @@ class RefundPaymentForm(ManagePaymentForm):def clean(self):super().clean()- if self.payment.variant == CustomPaymentChoices.MANUAL:+ if self.payment.gateway == CustomPaymentChoices.MANUAL:raise forms.ValidationError(pgettext_lazy('Payment form error',@@ -359,7 +359,7 @@ class OrderMarkAsPaidForm(forms.Form):'currency': self.order.total.gross.currency,**get_billing_data(self.order)}Payment.objects.get_or_create(- variant=CustomPaymentChoices.MANUAL,+ gateway=CustomPaymentChoices.MANUAL,charge_status=ChargeStatus.CHARGED, order=self.order,defaults=defaults)diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex d69eee64a3..6537e2df6a 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -97,7 +97,7 @@ def clean_void_payment(payment, errors):def clean_refund_payment(payment, amount, errors):- if payment.variant == CustomPaymentChoices.MANUAL:+ if payment.gateway == CustomPaymentChoices.MANUAL:errors.append(Error(field='payment',message='Manual payments can not be refunded.'))@@ -297,7 +297,7 @@ class OrderMarkAsPaid(BaseMutation):'currency': order.total.gross.currency,**get_billing_data(order)}Payment.objects.get_or_create(- variant=CustomPaymentChoices.MANUAL,+ gateway=CustomPaymentChoices.MANUAL,charge_status=ChargeStatus.CHARGED, order=order,defaults=defaults)diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex f7f2ba488a..bddbdd710f 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -62,7 +62,7 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):payment = create_payment(total=input['amount'],currency=settings.DEFAULT_CURRENCY,- variant=input['gateway'],+ gateway=input['gateway'],billing_email=checkout.email,is_active=True,extra_data=extra_data,diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.pyindex 401c416492..bf8788acb9 100644--- a/saleor/graphql/payment/types.py+++ b/saleor/graphql/payment/types.py@@ -1,11 +1,11 @@import graphenefrom graphene import relay-from ...payment import PROVIDERS_ENUM, ChargeStatus, models+from ...payment import GATEWAYS_ENUM, ChargeStatus, modelsfrom ..core.types.common import CountableDjangoObjectTypefrom ..core.utils import str_to_enum-PaymentGatewayEnum = graphene.Enum.from_enum(PROVIDERS_ENUM)+PaymentGatewayEnum = graphene.Enum.from_enum(GATEWAYS_ENUM)PaymentChargeStatusEnum = graphene.Enum('PaymentChargeStatusEnum',[(str_to_enum(code.upper()), code) for code, name in ChargeStatus.CHOICES])diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 52c2e8acf1..d5f11ede2f 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -677,6 +677,11 @@ input FulfillmentUpdateTrackingInput {notifyCustomer: Boolean}+enum GatewaysEnum {+ DUMMY+ BRAINTREE+}+scalar GenericScalartype Geolocalization {@@ -1208,7 +1213,7 @@ type PasswordReset {type Payment implements Node {id: ID!- variant: String!+ gateway: String!isActive: Boolean!created: DateTime!modified: DateTime!@@ -1258,7 +1263,7 @@ type PaymentCountableEdge {}input PaymentInput {- gateway: ProvidersEnum+ gateway: GatewaysEnumcheckoutId: IDtransactionToken: String!amount: Decimal!@@ -1557,11 +1562,6 @@ type ProductVariantUpdate {productVariant: ProductVariant}-enum ProvidersEnum {- DUMMY- BRAINTREE-}-type Query {attributes(query: String, inCategory: ID, before: String, after: String, first: Int, last: Int): AttributeCountableConnectioncategories(query: String, level: Int, before: String, after: String, first: Int, last: Int): CategoryCountableConnection@@ -1591,7 +1591,7 @@ type Query {page(id: ID, slug: String): Pagepages(query: String, before: String, after: String, first: Int, last: Int): PageCountableConnectionpayment(id: ID): Payment- paymentTransactionToken(gateway: ProvidersEnum): String+ paymentTransactionToken(gateway: GatewaysEnum): Stringpayments(before: String, after: String, first: Int, last: Int): PaymentCountableConnectionsale(id: ID!): Salesales(query: String, before: String, after: String, first: Int, last: Int): SaleCountableConnectiondiff --git a/saleor/order/forms.py b/saleor/order/forms.pyindex c899ac8f72..ffdaf8f509 100644--- a/saleor/order/forms.py+++ b/saleor/order/forms.py@@ -8,11 +8,11 @@ from ..payment.models import Paymentfrom .models import OrderPAYMENT_CHOICES = [- (k, v) for k, v in settings.CHECKOUT_PAYMENT_CHOICES.items()]+ (k, v) for k, v in settings.CHECKOUT_PAYMENT_GATEWAYS.items()]class PaymentsForm(forms.Form):- variant = forms.ChoiceField(+ gateway = forms.ChoiceField(label=pgettext_lazy('Payments form label', 'Payment Method'),choices=PAYMENT_CHOICES,initial=PAYMENT_CHOICES[0][0],diff --git a/saleor/order/urls.py b/saleor/order/urls.pyindex 9d22725f19..5caa92caff 100644--- a/saleor/order/urls.py+++ b/saleor/order/urls.py@@ -7,7 +7,7 @@ urlpatterns = [url(r'^%s/$' % (TOKEN_PATTERN,), views.details, name='details'),url(r'^%s/payment/$' % (TOKEN_PATTERN,),views.payment, name='payment'),- url(r'^%s/payment/(?P<variant>[-\w]+)/$' % (TOKEN_PATTERN,),+ url(r'^%s/payment/(?P<gateway>[-\w]+)/$' % (TOKEN_PATTERN,),views.start_payment, name='payment'),url(r'^%s/cancel-payment/$' % (TOKEN_PATTERN,), views.cancel_payment,name='cancel-payment'),diff --git a/saleor/order/views.py b/saleor/order/views.pyindex 5b14c6df29..ce1ad5c9c3 100644--- a/saleor/order/views.py+++ b/saleor/order/views.py@@ -15,7 +15,7 @@ from . import FulfillmentStatusfrom ..account.forms import LoginFormfrom ..account.models import Userfrom ..core.utils import get_client_ip-from ..payment import ChargeStatus, PaymentError, TransactionType, get_provider+from ..payment import ChargeStatus, PaymentError, TransactionType, get_payment_gatewayfrom ..payment.forms import get_form_for_paymentfrom ..payment.models import Paymentfrom ..payment.utils import get_billing_data@@ -75,9 +75,9 @@ def payment(request, token):payment_form = PaymentsForm(form_data)# FIXME: redirect if there is only one paymentif payment_form.is_valid():- payment = payment_form.cleaned_data['variant']+ payment = payment_form.cleaned_data['gateway']return redirect(- 'order:payment', token=order.token, variant=payment)+ 'order:payment', token=order.token, gateway=payment)ctx = {'order': order, 'payment_form': payment_form, 'payments': payments,'waiting_payment': waiting_payment,@@ -86,22 +86,22 @@ def payment(request, token):@check_order_status-def start_payment(request, order, variant):+def start_payment(request, order, gateway):defaults = {'customer_ip_address': get_client_ip(request),**get_billing_data(order)}- if variant not in settings.CHECKOUT_PAYMENT_CHOICES:- raise Http404('%r is not a valid payment variant' % (variant,))+ if gateway not in settings.CHECKOUT_PAYMENT_GATEWAYS:+ raise Http404('%r is not a valid payment gateway' % (gateway,))with transaction.atomic():payment, _ = Payment.objects.get_or_create(- variant=variant, is_active=True, order=order, defaults=defaults,+ gateway=gateway, is_active=True, order=order, defaults=defaults,total=order.total.gross.amount, currency=order.total.gross.currency)if (order.is_fully_paid()or payment.charge_status == ChargeStatus.FULLY_REFUNDED):return redirect(order.get_absolute_url())- provider, provider_params = get_provider(payment.variant)- transaction_token = provider.get_transaction_token(**provider_params)+ gateway, gateway_params = get_payment_gateway(payment.gateway)+ transaction_token = gateway.get_transaction_token(**gateway_params)form = get_form_for_payment(payment)form = form(data=request.POST or None, instance=payment)if form.is_valid():@@ -111,7 +111,7 @@ def start_payment(request, order, variant):form.add_error(None, exc.message)else:return redirect(order.get_absolute_url())- template = 'order/payment/%s.html' % variant+ template = 'order/payment/%s.html' % gatewayctx = {'form': form, 'payment': payment,'transaction_token': transaction_token, 'order': order}diff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.pyindex 29136c0753..ed62ddb145 100644--- a/saleor/payment/__init__.py+++ b/saleor/payment/__init__.py@@ -66,23 +66,23 @@ class ChargeStatus:(FULLY_REFUNDED, pgettext_lazy('payment status', 'Fully refunded'))]-PROVIDERS_ENUM = Enum(- 'ProvidersEnum',+GATEWAYS_ENUM = Enum(+ 'GatewaysEnum',{key.upper(): key.lower()- for key in settings.PAYMENT_PROVIDERS})+ for key in settings.PAYMENT_GATEWAYS})-def get_provider(provider_name):- if provider_name not in settings.CHECKOUT_PAYMENT_CHOICES:- raise ValueError('%s is not allowed provider' % provider_name)- if provider_name not in settings.PAYMENT_PROVIDERS:+def get_payment_gateway(gateway_name):+ if gateway_name not in settings.CHECKOUT_PAYMENT_GATEWAYS:+ raise ValueError('%s is not allowed gateway' % gateway_name)+ if gateway_name not in settings.PAYMENT_GATEWAYS:raise ImproperlyConfigured(- 'Payment provider %s is not configured.' % provider_name)- provider_module = importlib.import_module(- settings.PAYMENT_PROVIDERS[provider_name]['module'])- provider_params = settings.PAYMENT_PROVIDERS[provider_name][+ 'Payment gateway %s is not configured.' % gateway_name)+ gateway_module = importlib.import_module(+ settings.PAYMENT_GATEWAYS[gateway_name]['module'])+ gateway_params = settings.PAYMENT_GATEWAYS[gateway_name]['connection_params']- return provider_module, provider_params+ return gateway_module, gateway_paramsdef can_be_voided(payment):diff --git a/saleor/payment/forms.py b/saleor/payment/forms.pyindex 6810acc2ea..e842a58a33 100644--- a/saleor/payment/forms.py+++ b/saleor/payment/forms.py@@ -3,17 +3,17 @@ from django.conf import settingsfrom django.core.exceptions import ValidationErrorfrom django.utils.translation import pgettext_lazy-from . import ChargeStatus, TransactionType, get_provider+from . import ChargeStatus, TransactionType, get_payment_gatewayfrom .models import Paymentfrom .utils import gateway_authorize, gateway_capture, gateway_refunddef get_form_for_payment(payment):- if payment.variant == settings.DUMMY:+ if payment.gateway == settings.DUMMY:return DummyPaymentForm- elif payment.variant == settings.BRAINTREE:+ elif payment.gateway == settings.BRAINTREE:return BraintreePaymentForm- raise ValueError('Unknown payment provider')+ raise ValueError('Unknown payment gateway')class DummyPaymentForm(forms.Form):@@ -28,8 +28,8 @@ class DummyPaymentForm(forms.Form):def process_payment(self):# FIXME add tests- provider, provider_params = get_provider(self.instance.variant)- transaction_token = provider.get_transaction_token(**provider_params)+ gateway, gateway_params = get_payment_gateway(self.instance.gateway)+ transaction_token = gateway.get_transaction_token(**gateway_params)charge_status = self.cleaned_data['charge_status']self.instance.authorize(transaction_token)if charge_status == ChargeStatus.NOT_CHARGED:diff --git a/saleor/payment/providers/__init__.py b/saleor/payment/gateways/__init__.pysimilarity index 100%rename from saleor/payment/providers/__init__.pyrename to saleor/payment/gateways/__init__.pydiff --git a/saleor/payment/providers/braintree/__init__.py b/saleor/payment/gateways/braintree/__init__.pysimilarity index 96%rename from saleor/payment/providers/braintree/__init__.pyrename to saleor/payment/gateways/braintree/__init__.pyindex 9264efd7d1..2354397efb 100644--- a/saleor/payment/providers/braintree/__init__.py+++ b/saleor/payment/gateways/braintree/__init__.py@@ -120,7 +120,7 @@ def extract_gateway_response(braintree_result) -> Dict:return gateway_response-def get_gateway(sandbox_mode, merchant_id, public_key, private_key):+def get_braintree_gateway(sandbox_mode, merchant_id, public_key, private_key):if not all([merchant_id, private_key, public_key]):raise ImproperlyConfigured('Incorrectly configured Braintree gateway.')environment = braintree_sdk.Environment.Sandbox@@ -137,7 +137,7 @@ def get_gateway(sandbox_mode, merchant_id, public_key, private_key):def get_transaction_token(**connection_params: Dict) -> str:- gateway = get_gateway(**connection_params)+ gateway = get_braintree_gateway(**connection_params)transaction_token = gateway.client_token.generate()return transaction_token@@ -146,7 +146,7 @@ def authorize(payment: Payment,transaction_token: str,**connection_params: Dict) -> Tuple[Transaction, str]:- gateway = get_gateway(**connection_params)+ gateway = get_braintree_gateway(**connection_params)try:result = gateway.transaction.sale({'amount': str(payment.total),@@ -176,7 +176,7 @@ def capture(payment: Payment,amount: Decimal,**connection_params: Dict) -> Tuple[Transaction, str]:- gateway = get_gateway(**connection_params)+ gateway = get_braintree_gateway(**connection_params)auth_transaction = payment.transactions.filter(transaction_type=TransactionType.AUTH, is_success=True).first()try:@@ -206,7 +206,7 @@ def capture(def void(payment: Payment,**connection_params: Dict) -> Tuple[Transaction, str]:- gateway = get_gateway(**connection_params)+ gateway = get_braintree_gateway(**connection_params)auth_transaction = payment.transactions.filter(transaction_type=TransactionType.AUTH, is_success=True).first()try:@@ -233,7 +233,7 @@ def refund(payment: Payment,amount: Decimal,**connection_params: Dict) -> Tuple[Transaction, str]:- gateway = get_gateway(**connection_params)+ gateway = get_braintree_gateway(**connection_params)capture_txn = payment.transactions.filter(transaction_type=TransactionType.CAPTURE, is_success=True).first()try:diff --git a/saleor/payment/providers/dummy/__init__.py b/saleor/payment/gateways/dummy/__init__.pysimilarity index 100%rename from saleor/payment/providers/dummy/__init__.pyrename to saleor/payment/gateways/dummy/__init__.pydiff --git a/saleor/payment/migrations/0001_initial.py b/saleor/payment/migrations/0001_initial.pyindex 8288bad4eb..f5492d157c 100644--- a/saleor/payment/migrations/0001_initial.py+++ b/saleor/payment/migrations/0001_initial.py@@ -22,7 +22,7 @@ class Migration(migrations.Migration):name='PaymentMethod',fields=[('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),- ('variant', models.CharField(max_length=255)),+ ('gateway', models.CharField(max_length=255)),('is_active', models.BooleanField(default=True)),('created', models.DateTimeField(auto_now_add=True)),('modified', models.DateTimeField(auto_now=True)),diff --git a/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py b/saleor/payment/migrations/0002_transfer_payment_to_payment_method.pyindex 79432c60a5..33370cbf77 100644--- a/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py+++ b/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py@@ -98,7 +98,7 @@ def transfer_payments_to_payment_methods(apps, schema_editor):'tax': pay.tax}payment_method = PaymentMethod.objects.create(order=pay.order,- variant=pay.variant,+ gateway=pay.variant,created=pay.created,modified=pay.modified,billing_first_name=pay.billing_first_name,diff --git a/saleor/payment/models.py b/saleor/payment/models.pyindex faa95ab01c..4b72a47f2a 100644--- a/saleor/payment/models.py+++ b/saleor/payment/models.py@@ -26,7 +26,7 @@ class Payment(models.Model):"""# FIXME we should provide an option to store the card for later usage# FIXME probably we should have pending status- variant = models.CharField(max_length=255)+ gateway = models.CharField(max_length=255)is_active = models.BooleanField(default=True)#: Creation date and timecreated = models.DateTimeField(auto_now_add=True)@@ -52,7 +52,7 @@ class Payment(models.Model):extra_data = models.TextField(blank=True, default='')token = models.CharField(max_length=36, blank=True, default='')- #: Currency code (may be provider-specific)+ #: Currency code (may be gateway-specific)# FIXME: ISO4217 validator?currency = models.CharField(max_length=10)#: Total amount (gross)@@ -71,8 +71,8 @@ class Payment(models.Model):Order, null=True, related_name='payments', on_delete=models.PROTECT)def __repr__(self):- return 'Payment(variant=%s, is_active=%s, created=%s, charge_status=%s)' % (- self.variant, self.is_active, self.created, self.charge_status)+ return 'Payment(gateway=%s, is_active=%s, created=%s, charge_status=%s)' % (+ self.gateway, self.is_active, self.created, self.charge_status)def __iter__(self):return iter(self.transactions.all())@@ -127,7 +127,7 @@ class Payment(models.Model):return (self.is_active andself.charge_status == ChargeStatus.CHARGED and- self.variant != CustomPaymentChoices.MANUAL)+ self.gateway != CustomPaymentChoices.MANUAL)class Transaction(models.Model):@@ -143,7 +143,7 @@ class Transaction(models.Model):# FIXME probably we should have error/pending/success status instead of# a bool, eg for payments with 3d secureis_success = models.BooleanField(default=False)- #: Currency code (may be provider-specific)+ #: Currency code (may be gateway-specific)# FIXME: ISO4217 validator?currency = models.CharField(max_length=10)#: Total amount (gross)diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 8491bc10f5..71c9e12120 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -7,7 +7,7 @@ from django.conf import settingsfrom django.db import transactionfrom prices import Money-from . import ChargeStatus, PaymentError, can_be_voided, get_provider+from . import ChargeStatus, PaymentError, can_be_voided, get_payment_gatewayfrom ..core import analyticsfrom ..order import OrderEvents, OrderEventsEmailsfrom ..order.emails import send_payment_confirmation@@ -15,20 +15,20 @@ from .models import Payment, Transactionlogger = logging.getLogger(__name__)-PAYMENT_ERRORS = {-'incorrect_number':-'invalid_number':-'invalid_expiry_date':-'invalid_cvc':-'expired_card':-'incorrect_cvc':-'incorrect_zip':-'incorrect_address':-'card_declined':-'processing_error':-'call_issuer':-'pick_up_card':-}+# PAYMENT_ERRORS = {+# 'incorrect_number':+# 'invalid_number':+# 'invalid_expiry_date':+# 'invalid_cvc':+# 'expired_card':+# 'incorrect_cvc':+# 'incorrect_zip':+# 'incorrect_address':+# 'card_declined':+# 'processing_error':+# 'call_issuer':+# 'pick_up_card':+# }def get_billing_data(order):data = {}if order.billing_address:@@ -101,10 +101,10 @@ def create_transaction(return txn-def gateway_get_transaction_token(provider_name: str):+def gateway_get_transaction_token(gateway_name: str):# FIXME Add tests- provider, provider_params = get_provider(provider_name)- return provider.get_transaction_token(**provider_params)+ gateway, gateway_params = get_payment_gateway(gateway_name)+ return gateway.get_transaction_token(**gateway_params)@validate_payment@@ -112,10 +112,10 @@ def gateway_authorize(payment: Payment, transaction_token: str) -> Transaction:if not payment.charge_status == ChargeStatus.NOT_CHARGED:raise PaymentError('Charged transactions cannot be authorized again.')- provider, provider_params = get_provider(payment.variant)+ gateway, gateway_params = get_payment_gateway(payment.gateway)with transaction.atomic():- txn, error = provider.authorize(- payment, transaction_token, **provider_params)+ txn, error = gateway.authorize(+ payment, transaction_token, **gateway_params)# FIXME Create an order event ?if not txn.is_success:raise PaymentError(error)@@ -133,10 +133,10 @@ def gateway_capture(payment: Payment, amount: Decimal) -> Transaction:payment.total - payment.captured_amount):raise PaymentError('Unable to capture more than authorized amount.')- provider, provider_params = get_provider(payment.variant)+ gateway, gateway_params = get_payment_gateway(payment.gateway)with transaction.atomic():- txn, error = provider.capture(- payment, amount=amount, **provider_params)+ txn, error = gateway.capture(+ payment, amount=amount, **gateway_params)if txn.is_success:payment.charge_status = ChargeStatus.CHARGEDpayment.captured_amount += txn.amount@@ -154,9 +154,9 @@ def gateway_capture(payment: Payment, amount: Decimal) -> Transaction:def gateway_void(payment) -> Transaction:if not can_be_voided(payment):raise PaymentError('Only pre-authorized transactions can be voided.')- provider, provider_params = get_provider(payment.variant)+ gateway, gateway_params = get_payment_gateway(payment.gateway)with transaction.atomic():- txn, error = provider.void(payment, **provider_params)+ txn, error = gateway.void(payment, **gateway_params)if txn.is_success:payment.is_active = Falsepayment.save(update_fields=['is_active'])@@ -176,9 +176,9 @@ def gateway_refund(payment, amount: Decimal) -> Transaction:raise PaymentError('Refund is possible only when transaction is captured.')- provider, provider_params = get_provider(payment.variant)+ gateway, gateway_params = get_payment_gateway(payment.gateway)with transaction.atomic():- txn, error = provider.refund(payment, amount, **provider_params)+ txn, error = gateway.refund(payment, amount, **gateway_params)if txn.is_success:changed_fields = ['captured_amount']payment.captured_amount -= txn.amountdiff --git a/saleor/settings.py b/saleor/settings.pyindex 53bc86d6bb..69d5e43c2e 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -546,16 +546,16 @@ SERIALIZATION_MODULES = {DUMMY = 'dummy'BRAINTREE = 'braintree'-CHECKOUT_PAYMENT_CHOICES = {- DUMMY: pgettext_lazy('Payment method name', 'Dummy provider')+CHECKOUT_PAYMENT_GATEWAYS = {+ DUMMY: pgettext_lazy('Payment method name', 'Dummy gateway')}-PAYMENT_PROVIDERS = {+PAYMENT_GATEWAYS = {DUMMY: {- 'module': 'saleor.payment.providers.dummy',+ 'module': 'saleor.payment.gateways.dummy','connection_params': {}},BRAINTREE: {- 'module': 'saleor.payment.providers.braintree',+ 'module': 'saleor.payment.gateways.braintree','connection_params': {'sandbox_mode': get_bool_from_env('BRAINTREE_SANDBOX_MODE', True),'merchant_id': os.environ.get('BRAINTREE_MERCHANT_ID'),@@ -565,15 +565,15 @@ PAYMENT_PROVIDERS = {}}if not DEBUG:- PROVIDER_PATH = '%(module)s/__init__.py'- for provider, data in PAYMENT_PROVIDERS.items():- if provider not in CHECKOUT_PAYMENT_CHOICES:+ GATEWAY_PATH = '%(module)s/__init__.py'+ for gateway, data in PAYMENT_GATEWAYS.items():+ if gateway not in CHECKOUT_PAYMENT_GATEWAYS:continueif 'module' not in data or 'connection_params' not in data:- raise ImproperlyConfigured('Payment provider misconfigured.')+ raise ImproperlyConfigured('Payment gateway misconfigured.')module_path = {'module': data['module'].replace('.', '/')}- payment_provider_file_exists = os.path.isfile(- PROVIDER_PATH % {'module': module_path})- if not payment_provider_file_exists:+ payment_gateway_file_exists = os.path.isfile(+ GATEWAY_PATH % {'module': module_path})+ if not payment_gateway_file_exists:raise ImproperlyConfigured(- 'No configuration files for %s payment provider.' % provider)+ 'No configuration files for %s payment gateway.' % gateway)diff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex 5c9fa28b3a..fde8272a3e 100644--- a/tests/api/test_order.py+++ b/tests/api/test_order.py@@ -1075,7 +1075,7 @@ def test_clean_order_void_payment():def test_clean_order_refund_payment():payment = MagicMock(spec=Payment)- payment.variant = CustomPaymentChoices.MANUAL+ payment.gateway = CustomPaymentChoices.MANUALamount = Mock(spec='string')errors = clean_refund_payment(payment, amount, [])assert errors[0].field == 'payment'diff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex b465e9161c..2e30382bb2 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -46,7 +46,7 @@ def test_payment_charge_gateway_error('Payment', payment_dummy.pk)variables = {'paymentId': payment_id}monkeypatch.setattr(- 'saleor.payment.providers.dummy.dummy_success', lambda: False)+ 'saleor.payment.gateways.dummy.dummy_success', lambda: False)response = staff_api_client.post_graphql(VOID_QUERY, variables, permissions=[permission_manage_orders])content = get_graphql_content(response)@@ -166,7 +166,7 @@ def test_payment_charge_gateway_error('paymentId': payment_id,'amount': str(payment_dummy.total)}monkeypatch.setattr(- 'saleor.payment.providers.dummy.dummy_success', lambda: False)+ 'saleor.payment.gateways.dummy.dummy_success', lambda: False)response = staff_api_client.post_graphql(CHARGE_QUERY, variables, permissions=[permission_manage_orders])content = get_graphql_content(response)@@ -236,7 +236,7 @@ def test_payment_refund_error('paymentId': payment_id,'amount': str(payment.total)}monkeypatch.setattr(- 'saleor.payment.providers.dummy.dummy_success', lambda: False)+ 'saleor.payment.gateways.dummy.dummy_success', lambda: False)response = staff_api_client.post_graphql(REFUND_QUERY, variables, permissions=[permission_manage_orders])content = get_graphql_content(response)@@ -260,7 +260,7 @@ def test_payments_query(edges {node {id- variant+ gateway}}}@@ -270,4 +270,4 @@ def test_payments_query(query, permissions=[permission_manage_orders])content = get_graphql_content(response)data = content['data']['payments']- assert data['edges'][0]['node']['variant'] == payment_dummy.variant+ assert data['edges'][0]['node']['gateway'] == payment_dummy.gatewaydiff --git a/tests/conftest.py b/tests/conftest.pyindex d1a37e4172..d08d3b6dbe 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -728,9 +728,9 @@ def product_translation_fr(product):@pytest.fixture-def payment_dummy(db, order_with_lines):+def payment_dummy(db, settings, order_with_lines):return Payment.objects.create(- variant='dummy',+ gateway=settings.DUMMY,order=order_with_lines,is_active=True,total=order_with_lines.total.gross.amount,diff --git a/tests/test_order.py b/tests/test_order.pyindex b36b85a576..5a1cba5dbe 100644--- a/tests/test_order.py+++ b/tests/test_order.py@@ -369,7 +369,7 @@ def test_order_queryset_to_ship():]for order in orders_to_ship:order.payments.create(- variant=settings.DUMMY, charge_status=ChargeStatus.CHARGED,+ gateway=settings.DUMMY, charge_status=ChargeStatus.CHARGED,total=order.total.gross.amount,captured_amount=order.total.gross.amount,currency=order.total.gross.currency)@@ -449,19 +449,19 @@ def test_order_payment_flow(# Select paymenturl = reverse('order:payment', kwargs={'token': order.token})- data = {'variant': settings.DUMMY}+ data = {'gateway':settings.DUMMY}response = client.post(url, data, follow=True)assert len(response.redirect_chain) == 1assert response.status_code == 200redirect_url = reverse('order:payment',- kwargs={'token': order.token, 'variant': settings.DUMMY})+ kwargs={'token': order.token, 'gateway':settings.DUMMY})assert response.request['PATH_INFO'] == redirect_url# Go to payment details page, enter payment datadata = {- 'variant': settings.DUMMY,+ 'gateway':settings.DUMMY,'is_active': True,'total': order.total.gross.amount,'currency': order.total.gross.currency,diff --git a/tests/test_payment.py b/tests/test_payment.pyindex b7938c163d..1d7c597808 100644--- a/tests/test_payment.py+++ b/tests/test_payment.py@@ -7,7 +7,7 @@ from prices import Moneyfrom saleor.order import OrderEvents, OrderEventsEmailsfrom saleor.payment import (- ChargeStatus, PaymentError, TransactionType, get_provider)+ ChargeStatus, PaymentError, TransactionType, get_payment_gateway)from saleor.payment.utils import (create_payment, create_transaction, gateway_authorize, gateway_capture,gateway_get_transaction_token, gateway_refund, gateway_void,@@ -31,7 +31,7 @@ def transaction_data(payment_dummy, settings):@pytest.fixture-def provider_params():+def gateway_params():return {'secret-key': 'nobodylikesspanishinqusition'}@@ -60,26 +60,26 @@ def test_get_billing_data(order):assert get_billing_data(order) == {}-def test_get_provider_not_allowed_checkout_choice(settings):- provider = 'example-provider'- settings.CHECKOUT_PAYMENT_CHOICES = {}+def test_get_payment_gateway_not_allowed_checkout_choice(settings):+ gateway = 'example-gateway'+ settings.CHECKOUT_PAYMENT_GATEWAYS = {}with pytest.raises(ValueError):- get_provider(provider)+ get_payment_gateway(gateway)-def test_get_provider_non_existing_name(settings):- provider = 'example-provider'- settings.CHECKOUT_PAYMENT_CHOICES = {provider: 'Example provider'}+def test_get_payment_gateway_non_existing_name(settings):+ gateway = 'example-gateway'+ settings.CHECKOUT_PAYMENT_GATEWAYS = {gateway: 'Example gateway'}with pytest.raises(ImproperlyConfigured):- get_provider(provider)+ get_payment_gateway(gateway)-def test_get_provider(settings):- provider_name = list(settings.PAYMENT_PROVIDERS.keys())[0]- provider = settings.PAYMENT_PROVIDERS[provider_name]- provider_module, provider_params = get_provider(provider_name)- assert provider_module.__name__ == provider['module']- assert provider_params == provider['connection_params']+def test_get_payment_gateway(settings):+ gateway_name = list(settings.PAYMENT_GATEWAYS.keys())[0]+ gateway = settings.PAYMENT_GATEWAYS[gateway_name]+ gateway_module, gateway_params = get_payment_gateway(gateway_name)+ assert gateway_module.__name__ == gateway['module']+ assert gateway_params == gateway['connection_params']@patch('saleor.order.emails.send_payment_confirmation.delay')@@ -122,9 +122,9 @@ def test_validate_payment():def test_create_payment(settings):- data = {'variant': settings.DUMMY}+ data = {'gateway': settings.DUMMY}payment = create_payment(**data)- assert payment.variant == settings.DUMMY+ assert payment.gateway == settings.DUMMYsame_payment = create_payment(**data)assert payment == same_payment@@ -151,26 +151,26 @@ def test_create_transaction_no_gateway_response(transaction_data):def test_gateway_get_transaction_token(settings):- provider_name = list(settings.PAYMENT_PROVIDERS.keys())[0]- provider = settings.PAYMENT_PROVIDERS[provider_name]- module = provider['module']+ gateway_name = list(settings.PAYMENT_GATEWAYS.keys())[0]+ gateway = settings.PAYMENT_GATEWAYS[gateway_name]+ module = gateway['module']with patch('%s.get_transaction_token' % module) as transaction_token_mock:- gateway_get_transaction_token(provider_name)+ gateway_get_transaction_token(gateway_name)transaction_token_mock.assert_called_once_with()-def test_gateway_get_transaction_token_not_allowed_provider(settings):- provider = 'example-provider'- settings.CHECKOUT_PAYMENT_CHOICES = {}+def test_gateway_get_transaction_token_not_allowed_gateway(settings):+ gateway = 'example-gateway'+ settings.CHECKOUT_PAYMENT_GATEWAYS = {}with pytest.raises(ValueError):- gateway_get_transaction_token(provider)+ gateway_get_transaction_token(gateway)-def test_gateway_get_transaction_token_not_existing_provider(settings):- provider = 'example-provider'- settings.CHECKOUT_PAYMENT_CHOICES = {provider: 'Example provider'}+def test_gateway_get_transaction_token_not_existing_gateway(settings):+ gateway = 'example-gateway'+ settings.CHECKOUT_PAYMENT_GATEWAYS = {gateway: 'Example gateway'}with pytest.raises(ImproperlyConfigured):- gateway_get_transaction_token(provider)+ gateway_get_transaction_token(gateway)@pytest.mark.parametrize(@@ -190,57 +190,57 @@ def test_gateway_authorize_errors(payment_dummy):'Charged transactions cannot be authorized again.')-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_authorize(- mock_get_provider, payment_txn_preauth, provider_params,+ mock_get_payment_gateway, payment_txn_preauth, gateway_params,transaction_token):txn = payment_txn_preauth.transactions.first()payment = payment_txn_preauthmock_authorize = Mock(return_value=(txn, ''))- mock_get_provider.return_value = (- Mock(authorize=mock_authorize), provider_params)+ mock_get_payment_gateway.return_value = (+ Mock(authorize=mock_authorize), gateway_params)gateway_authorize(payment, transaction_token)- mock_get_provider.assert_called_once_with(payment.variant)+ mock_get_payment_gateway.assert_called_once_with(payment.gateway)mock_authorize.assert_called_once_with(- payment, transaction_token, **provider_params)+ payment, transaction_token, **gateway_params)-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_authorize_failed(- mock_get_provider, payment_txn_preauth, provider_params,+ mock_get_payment_gateway, payment_txn_preauth, gateway_params,transaction_token):txn = payment_txn_preauth.transactions.first()txn.is_success = Falsepayment = payment_txn_preauthmock_authorize = Mock(return_value=(txn, EXAMPLE_ERROR))- mock_get_provider.return_value = (- Mock(authorize=mock_authorize), provider_params)+ mock_get_payment_gateway.return_value = (+ Mock(authorize=mock_authorize), gateway_params)with pytest.raises(PaymentError) as exc:gateway_authorize(payment, transaction_token)assert exc.value.message == EXAMPLE_ERROR@patch('saleor.payment.utils.handle_fully_paid_order')-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_capture(- mock_get_provider, mock_handle_fully_paid_order, payment_txn_preauth,- provider_params):+ mock_get_payment_gateway, mock_handle_fully_paid_order, payment_txn_preauth,+ gateway_params):txn = payment_txn_preauth.transactions.first()payment = payment_txn_preauthassert not payment.captured_amountamount = payment.totalmock_capture = Mock(return_value=(txn, ''))- mock_get_provider.return_value = (- Mock(capture=mock_capture), provider_params)+ mock_get_payment_gateway.return_value = (+ Mock(capture=mock_capture), gateway_params)gateway_capture(payment, amount)- mock_get_provider.assert_called_once_with(payment.variant)+ mock_get_payment_gateway.assert_called_once_with(payment.gateway)mock_capture.assert_called_once_with(- payment, amount=amount, **provider_params)+ payment, amount=amount, **gateway_params)payment.refresh_from_db()assert payment.charge_status == ChargeStatus.CHARGED@@ -249,10 +249,10 @@ def test_gateway_capture(@patch('saleor.payment.utils.handle_fully_paid_order')-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_capture_partial_capture(- mock_get_provider, mock_handle_fully_paid_order, payment_txn_preauth,- provider_params, settings):+ mock_get_payment_gateway, mock_handle_fully_paid_order, payment_txn_preauth,+ gateway_params, settings):payment = payment_txn_preauthamount = payment.total * Decimal('0.5')txn = payment.transactions.first()@@ -260,8 +260,8 @@ def test_gateway_capture_partial_capture(txn.currency = settings.DEFAULT_CURRENCYmock_capture = Mock(return_value=(txn, ''))- mock_get_provider.return_value = (- Mock(capture=mock_capture), provider_params)+ mock_get_payment_gateway.return_value = (+ Mock(capture=mock_capture), gateway_params)gateway_capture(payment, amount)@@ -273,10 +273,10 @@ def test_gateway_capture_partial_capture(@patch('saleor.payment.utils.handle_fully_paid_order')-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_capture_failed(- mock_get_provider, mock_handle_fully_paid_order, payment_txn_preauth,- provider_params):+ mock_get_payment_gateway, mock_handle_fully_paid_order, payment_txn_preauth,+ gateway_params):txn = payment_txn_preauth.transactions.first()txn.is_success = False@@ -284,8 +284,8 @@ def test_gateway_capture_failed(amount = payment.totalmock_capture = Mock(return_value=(txn, EXAMPLE_ERROR))- mock_get_provider.return_value = (- Mock(capture=mock_capture), provider_params)+ mock_get_payment_gateway.return_value = (+ Mock(capture=mock_capture), gateway_params)with pytest.raises(PaymentError) as exc:gateway_capture(payment, amount)assert exc.value.message == EXAMPLE_ERROR@@ -312,32 +312,32 @@ def test_gateway_capture_errors(payment_dummy):'Unable to capture more than authorized amount.')-@patch('saleor.payment.utils.get_provider')-def test_gateway_void(mock_get_provider, payment_txn_preauth, provider_params):+@patch('saleor.payment.utils.get_payment_gateway')+def test_gateway_void(mock_get_payment_gateway, payment_txn_preauth, gateway_params):txn = payment_txn_preauth.transactions.first()payment = payment_txn_preauthassert payment.is_activemock_void = Mock(return_value=(txn, ''))- mock_get_provider.return_value = (Mock(void=mock_void), provider_params)+ mock_get_payment_gateway.return_value = (Mock(void=mock_void), gateway_params)gateway_void(payment)- mock_get_provider.assert_called_once_with(payment.variant)- mock_void.assert_called_once_with(payment, **provider_params)+ mock_get_payment_gateway.assert_called_once_with(payment.gateway)+ mock_void.assert_called_once_with(payment, **gateway_params)payment.refresh_from_db()assert payment.is_active == False-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_void_failed(- mock_get_provider, payment_txn_preauth, provider_params):+ mock_get_payment_gateway, payment_txn_preauth, gateway_params):txn = payment_txn_preauth.transactions.first()txn.is_success = Falsepayment = payment_txn_preauthmock_void = Mock(return_value=(txn, EXAMPLE_ERROR))- mock_get_provider.return_value = (Mock(void=mock_void), provider_params)+ mock_get_payment_gateway.return_value = (Mock(void=mock_void), gateway_params)with pytest.raises(PaymentError) as exc:gateway_void(payment)assert exc.value.message == EXAMPLE_ERROR@@ -353,29 +353,29 @@ def test_gateway_void_errors(payment_dummy):exc.value.message == 'Only pre-authorized transactions can be voided.'-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_refund(- mock_get_provider, payment_txn_captured, provider_params):+ mock_get_payment_gateway, payment_txn_captured, gateway_params):txn = payment_txn_captured.transactions.first()payment = payment_txn_capturedamount = payment.totalmock_refund = Mock(return_value=(txn, ''))- mock_get_provider.return_value = (- Mock(refund=mock_refund), provider_params)+ mock_get_payment_gateway.return_value = (+ Mock(refund=mock_refund), gateway_params)gateway_refund(payment, amount)- mock_get_provider.assert_called_once_with(payment.variant)- mock_refund.assert_called_once_with(payment, amount, **provider_params)+ mock_get_payment_gateway.assert_called_once_with(payment.gateway)+ mock_refund.assert_called_once_with(payment, amount, **gateway_params)payment.refresh_from_db()assert payment.charge_status == ChargeStatus.FULLY_REFUNDEDassert not payment.captured_amount-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_refund_partial_refund(- mock_get_provider, payment_txn_captured, provider_params, settings):+ mock_get_payment_gateway, payment_txn_captured, gateway_params, settings):payment = payment_txn_capturedamount = payment.total * Decimal('0.5')txn = payment_txn_captured.transactions.first()@@ -383,8 +383,8 @@ def test_gateway_refund_partial_refund(txn.currency = settings.DEFAULT_CURRENCYmock_refund = Mock(return_value=(txn, ''))- mock_get_provider.return_value = (- Mock(refund=mock_refund), provider_params)+ mock_get_payment_gateway.return_value = (+ Mock(refund=mock_refund), gateway_params)gateway_refund(payment, amount)@@ -393,17 +393,17 @@ def test_gateway_refund_partial_refund(assert payment.captured_amount == payment.total - amount-@patch('saleor.payment.utils.get_provider')+@patch('saleor.payment.utils.get_payment_gateway')def test_gateway_refund_failed(- mock_get_provider, payment_txn_captured, provider_params, settings):+ mock_get_payment_gateway, payment_txn_captured, gateway_params, settings):txn = payment_txn_captured.transactions.first()payment = payment_txn_capturedcaptured_before = payment.captured_amounttxn.is_success = Falsemock_refund = Mock(return_value=(txn, EXAMPLE_ERROR))- mock_get_provider.return_value = (- Mock(refund=mock_refund), provider_params)+ mock_get_payment_gateway.return_value = (+ Mock(refund=mock_refund), gateway_params)with pytest.raises(PaymentError) as exc:gateway_refund(payment, Decimal('10.00'))diff --git a/tests/test_payment_braintree.py b/tests/test_payment_braintree.pyindex 8e63e33b2a..01eb28eaa6 100644--- a/tests/test_payment_braintree.py+++ b/tests/test_payment_braintree.py@@ -11,10 +11,10 @@ from django.core.exceptions import ImproperlyConfiguredfrom prices import Moneyfrom saleor.payment import TransactionType-from saleor.payment.providers.braintree import (+from saleor.payment.gateways.braintree import (CONFIRM_MANUALLY, THREE_D_SECURE_REQUIRED, authorize, capture,extract_gateway_response, get_transaction_token, get_customer_data,- get_error_for_client, get_gateway, refund,+ get_error_for_client, get_braintree_gateway, refund,transaction_and_incorrect_token_error, void)INCORRECT_TOKEN_ERROR = (@@ -120,16 +120,16 @@ def test_get_error_for_client(braintree_error, monkeypatch):# error not whitelistedmonkeypatch.setattr(- 'saleor.payment.providers.braintree.ERROR_CODES_WHITELIST', {})+ 'saleor.payment.gateways.braintree.ERROR_CODES_WHITELIST', {})assert get_error_for_client([error]) == DEFAULT_ERRORmonkeypatch.setattr(- 'saleor.payment.providers.braintree.ERROR_CODES_WHITELIST',+ 'saleor.payment.gateways.braintree.ERROR_CODES_WHITELIST',{braintree_error.code: ''})assert get_error_for_client([error]) == braintree_error.messagemonkeypatch.setattr(- 'saleor.payment.providers.braintree.ERROR_CODES_WHITELIST',+ 'saleor.payment.gateways.braintree.ERROR_CODES_WHITELIST',{braintree_error.code: 'Error msg override'})assert get_error_for_client([error]) == 'Error msg override'@@ -165,8 +165,8 @@ def test_extract_gateway_response_no_transaction(@pytest.mark.integration-def test_get_gateway(gateway_config):- result = get_gateway(**gateway_config)+def test_get_braintree_gateway(gateway_config):+ result = get_braintree_gateway(**gateway_config)assert gateway_config['sandbox_mode'] == Falseassert result.config.environment == Environment.Productionassert result.config.merchant_id == gateway_config['merchant_id']@@ -175,19 +175,19 @@ def test_get_gateway(gateway_config):@pytest.mark.integration-def test_get_gateway_sandbox(gateway_config):+def test_get_braintree_gateway_sandbox(gateway_config):gateway_config['sandbox_mode'] = True- result = get_gateway(**gateway_config)+ result = get_braintree_gateway(**gateway_config)assert result.config.environment == Environment.Sandbox-def test_get_gateway_inproperly_configured(gateway_config):+def test_get_braintree_gateway_inproperly_configured(gateway_config):with pytest.raises(ImproperlyConfigured):gateway_config['private_key'] = None- get_gateway(**gateway_config)+ get_braintree_gateway(**gateway_config)-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_get_transaction_token(mock_gateway, gateway_config):transaction_token = 'transaction-token'mock_generate = Mock(return_value='transaction-token')@@ -199,7 +199,7 @@ def test_get_transaction_token(mock_gateway, gateway_config):@pytest.mark.integration-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_authorize_error_response(mock_gateway, payment_dummy, braintree_error_response):payment = payment_dummy@@ -218,8 +218,8 @@ def test_authorize_error_response(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.transaction_and_incorrect_token_error')-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.transaction_and_incorrect_token_error')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_authorize_incorrect_token(mock_gateway, mock_transaction, payment_dummy,braintree_not_found_error):@@ -236,7 +236,7 @@ def test_authorize_incorrect_token(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_authorize(mock_gateway, payment_dummy, braintree_success_response):payment = payment_dummy@@ -265,7 +265,7 @@ def test_authorize(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_refund(mock_gateway, payment_txn_captured, braintree_success_response,settings):@@ -292,8 +292,8 @@ def test_refund(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.transaction_and_incorrect_token_error')-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.transaction_and_incorrect_token_error')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_refund_incorrect_token(mock_gateway, mock_transaction, payment_txn_captured,braintree_not_found_error):@@ -313,7 +313,7 @@ def test_refund_incorrect_token(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_refund_error_response(mock_gateway, payment_txn_captured, braintree_error_response):payment = payment_txn_captured@@ -331,7 +331,7 @@ def test_refund_error_response(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_capture(mock_gateway, payment_txn_preauth, braintree_success_response,settings):@@ -360,8 +360,8 @@ def test_capture(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.transaction_and_incorrect_token_error')-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.transaction_and_incorrect_token_error')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_capture_incorrect_token(mock_gateway, mock_transaction, payment_txn_preauth,braintree_not_found_error):@@ -383,7 +383,7 @@ def test_capture_incorrect_token(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_capture_error_response(mock_gateway, payment_txn_preauth, braintree_error_response):payment = payment_txn_preauth@@ -403,7 +403,7 @@ def test_capture_error_response(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_void(mock_gateway, payment_txn_preauth, braintree_success_response):payment = payment_txn_preauth@@ -427,8 +427,8 @@ def test_void(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.transaction_and_incorrect_token_error')-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.transaction_and_incorrect_token_error')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_void_incorrect_token(mock_gateway, mock_transaction, payment_txn_preauth,braintree_not_found_error):@@ -446,7 +446,7 @@ def test_void_incorrect_token(@pytest.mark.integration-@patch('saleor.payment.providers.braintree.get_gateway')+@patch('saleor.payment.gateways.braintree.get_braintree_gateway')def test_void_error_response(mock_gateway, payment_txn_preauth, braintree_error_response):payment = payment_txn_preauthdiff --git a/tests/test_payment_dummy.py b/tests/test_payment_dummy.pyindex ca5ad7120c..9ca4d4b882 100644--- a/tests/test_payment_dummy.py+++ b/tests/test_payment_dummy.py@@ -16,7 +16,7 @@ def test_authorize(payment_dummy):def test_authorize_gateway_error(payment_dummy, monkeypatch):monkeypatch.setattr(- 'saleor.payment.providers.dummy.dummy_success', lambda: False)+ 'saleor.payment.gateways.dummy.dummy_success', lambda: False)with pytest.raises(PaymentError):txn = payment_dummy.authorize(transaction_token='Fake')assert txn.transaction_type == TransactionType.AUTH@@ -54,7 +54,7 @@ def test_void_failed(is_active, charge_status, payment_dummy):def test_void_gateway_error(payment_dummy, monkeypatch):monkeypatch.setattr(- 'saleor.payment.providers.dummy.dummy_success', lambda: False)+ 'saleor.payment.gateways.dummy.dummy_success', lambda: False)with pytest.raises(PaymentError):txn = payment_dummy.void()assert txn.transaction_type == TransactionType.VOID@@ -93,7 +93,7 @@ def test_charge_failed(def test_charge_gateway_error(payment_dummy, monkeypatch):monkeypatch.setattr(- 'saleor.payment.providers.dummy.dummy_success', lambda: False)+ 'saleor.payment.gateways.dummy.dummy_success', lambda: False)with pytest.raises(PaymentError):txn = payment_dummy.capture(80)assert txn.transaction_type == TransactionType.CHARGE@@ -141,7 +141,7 @@ def test_refund_failed(def test_refund_gateway_error(payment_dummy, monkeypatch):monkeypatch.setattr(- 'saleor.payment.providers.dummy.dummy_success', lambda: False)+ 'saleor.payment.gateways.dummy.dummy_success', lambda: False)payment = payment_dummypayment.charge_status = ChargeStatus.CHARGEDpayment.captured_amount = Decimal('80.00')