Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add documentation on adding new payment gateway, fix style and inconsistencies in naming
Pacu252047fc8ac5d
diff --git a/docs/architecture/payments.rst b/docs/architecture/payments.rstindex 91aa3c587c..94a7effa17 100644--- a/docs/architecture/payments.rst+++ b/docs/architecture/payments.rst@@ -1,6 +1,48 @@Payments========+Supported Gateways+------------------++The default configuration uses the *dummy* backend.+It's meant to allow developers to easily simulate different payment results.++Here is a list of supported payment providers:++* Braintree++For how-to guide on adding new payments into your Saleor project please check :ref:`adding-payments`++.. note::++ All payment backends default to using sandbox mode.+ This is very useful for development but make sure you use production mode when deploying to a production server.+++Authorization and Capture+-------------------------++Some of the payment backends support pre-authorizing payments.++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 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.+It is also useful if your business prefers to manually screen orders for fraud attempts.++When viewing orders with pre-authorized payments Saleor will offer options to either capture or release the funds.+++Refunds+-------++You can issue partial or full refunds for all captured payments.+When you edit an order and remove items Saleor will also offer to automatically issue a partial refund.++Saleor uses the concept of Payments and Transactions to fulfill the payment process.Payment Methods@@ -48,43 +90,3 @@ There are 5 possible transaction types:+---------+-------------------+----------------------------------------------------------------------------------------------------------------------------+| refund | REFUND | Full or partial return of captured funds to the customer. |+---------+-------------------+----------------------------------------------------------------------------------------------------------------------------+---Supported Gateways---------------------The default configuration uses the *dummy* backend.-It's meant to allow developers to easily simulate different payment results.--Here is a list of supported payment providers:--* Braintree--.. note::-- All payment backends default to using sandbox mode.- This is very useful for development but make sure you use production mode when deploying to a production server.---Authorization and Capture----------------------------Some of the payment backends support pre-authorizing payments.--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 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.-It is also useful if your business prefers to manually screen orders for fraud attempts.--When viewing orders with pre-authorized payments Saleor will offer options to either capture or release the funds.---Refunds----------You can issue partial or full refunds for all captured payments.-When you edit an order and remove items Saleor will also offer to automatically issue a partial refund.diff --git a/docs/guides.rst b/docs/guides.rstindex 3339b36e0f..3a345073e7 100644--- a/docs/guides.rst+++ b/docs/guides.rst@@ -5,6 +5,7 @@ Guides:maxdepth: 2guides/orders+ guides/paymentsguides/navigationguides/taxesguides/recaptchadiff --git a/docs/guides/payments.rst b/docs/guides/payments.rstnew file mode 100644index 0000000000..108355833a--- /dev/null+++ b/docs/guides/payments.rst@@ -0,0 +1,226 @@+.. _adding-payments:++Payments+========++Integrating new Payment Gateway into Saleor+-------------------------------------------++We are using a universal flow, that each provider should fulfill, there are+several methods that should be implemented.++Your changes should live under the+``saleor.payment.providers.<provider name>``.++.. note::++ After completing those changes your new payment gateway will be available+ only from the API level. You also need to integrate it into your+ Frontend's workflow.++get_transaction_token(**connection_params)+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^++A transaction token is a signed data blob that includes configuration and+authorization information required by the payment provider.++These should not be reused; a new transaction token should be generated for+each payment request.++Example+"""""""++.. code-block:: python++ def get_transaction_token(**connection_params: Dict) -> str:+ gateway - get_gateway(**connection_params)+ transaction_token - gateway.transaction_token.generate()+ return transaction_token++authorize(payment, transaction_token, **connection_params)+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^++A process of reserving the amount of money against the customer's funding+source. Money does not change hands until the authorization is captured.++Example+"""""""++.. code-block:: python++ def authorize(+ payment: Payment,+ transaction_token: str,+ **connection_params: Dict) -> Tuple[Transaction, str]:++ # Handle connecting to the gateway and sending the auth request here+ response - gateway.auth(token-transaction_token)++ txn - Transaction.objects.create(+ payment-payment,+ transaction_type-TransactionType.AUTH,+ amount-payment.total.amount,+ gateway_response-get_gateway_response(response),+ token-response.transaction.id,+ is_success-response.is_success)+ return txn, response['error']+++refund(payment, amount, **connection_params)+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^++Full or partial return of captured funds to the customer.++Example+"""""""++.. code-block:: python++ def refund(+ payment: Payment,+ amount: Decimal,+ **connection_params: Dict) -> Tuple[Transaction, str]:++ # Please note that token from the last AUTH transaction should be used+ capture_txn - payment.transactions.filter(+ transaction_type-TransactionType.CAPTURE).first()+ transaction_token - capture_txn.token++ # Handle connecting to the gateway and sending the refund request here+ response - gateway.refund(token-transaction_token)++ txn - create_transaction(+ payment-payment,+ transaction_type-TransactionType.REFUND,+ amount-amount,+ token-response.transaction.id,+ is_success-response.is_success,+ gateway_response-get_gateway_response(response))+ return txn, response['error']++capture(payment, amount, **connection_params)+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^++A transfer of the money that was reserved during the authorization stage.++Example+"""""""++.. code-block:: python++ def capture(+ payment: Payment,+ amount: Decimal,+ **connection_params: Dict) -> Tuple[Transaction, str]:++ # Please note that token from the last AUTH transaction should be used+ auth_transaction - payment.transactions.filter(+ transaction_type-TransactionType.AUTH).first()+ transaction_token - auth_transaction.token++ # Handle connecting to the gateway and sending the capture request here+ response - gateway.capture(token-transaction_token)++ txn - create_transaction(+ payment-payment,+ transaction_type-TransactionType.CAPTURE,+ amount-amount,+ token-response.transaction.id,+ is_success-response.is_success,+ gateway_response-get_gateway_response(response))+ return txn, response['error']++void(payment, **connection_params)+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^++A cancellation of a pending authorization or capture.++Example+"""""""++.. code-block:: python++ def void(+ payment: Payment,+ **connection_params: Dict) -> Tuple[Transaction, str]:++ # Please note that token from the last AUTH transaction should be used+ auth_transaction - payment.transactions.filter(+ transaction_type-TransactionType.AUTH).first()+ transaction_token - auth_transaction.token++ # Handle connecting to the gateway and sending the void request here+ response - gateway.void(token-transaction_token)++ txn - create_transaction(+ payment-payment,+ transaction_type-TransactionType.VOID,+ amount-payment.total.amount,+ gateway_response-get_gateway_response(response),+ token-response.transaction.id,+ is_success-response.is_success)+ return txn, response['error']++Parameters+^^^^^^^^^^++-----------------------+-----------+------------------------------------------------------------------------------------------------++| name | type | description |++-----------------------+-----------+------------------------------------------------------------------------------------------------++| ``payment`` | `Payment` | Payment instance, for which the transaction will be created. |++-----------------------+-----------+------------------------------------------------------------------------------------------------++| ``transaction_token`` | `str` | Unique transaction's token that will be used on the purpose of completing the payment process. |++-----------------------+-----------+------------------------------------------------------------------------------------------------++| ``connection_params`` | `dict` | List of parameters used for connecting to the payment's gateway. |++-----------------------+-----------+------------------------------------------------------------------------------------------------++| ``amount`` | `Decimal` | Amount of Money to be refunded/captured. |++-----------------------+-----------+------------------------------------------------------------------------------------------------+++Returns+^^^^^^^++-----------------------+---------------+-----------------------------------------------------------------------------------------------------------++| name | type | description |++-----------------------+---------------+-----------------------------------------------------------------------------------------------------------++| ``txn`` | `Transaction` | Transaction created during the payment process, with ``is_success`` set to ``True`` if no error occurred. |++-----------------------+---------------+-----------------------------------------------------------------------------------------------------------++| ``error`` | `str` | Error message to be displayed in the UI, empty if no error occurred. |++-----------------------+---------------+-----------------------------------------------------------------------------------------------------------++| ``transaction_token`` | `str` | Unique transaction's token that will be used on the purpose of completing the payment process. |++-----------------------+---------------+-----------------------------------------------------------------------------------------------------------+++Enabling new payment provider in the settings+---------------------------------------------++.. code-block:: python++ PAYMENT_PROVIDERS - {+ 'braintree': {+ 'module': 'saleor.payment.providers.braintree',+ 'connection_params': {+ 'sandbox_mode': get_bool_from_env('BRAINTREE_SANDBOX_MODE', True),+ 'merchant_id': os.environ.get('BRAINTREE_MERCHANT_ID'),+ 'public_key': os.environ.get('BRAINTREE_PUBLIC_KEY'),+ 'private_key': os.environ.get('BRAINTREE_PRIVATE_KEY')+ }+ }+ }++Please take a moment to consider the example settings above.++- ``braintree``+ Provider's name, which will be used to identify the gateway+ during the payment process.+ It's stored in the ``Payment`` model under the ``variant`` value.++- ``module``+ The path to the integration module+ (assuming that your changes live within the+ ``saleor.payment.providers.braintree.__init__.py`` file)++- ``connection_params``+ List of parameters used for connecting to the payment's gateway.++.. note::++ All payment backends default to using sandbox mode.+ This is very useful for development but make sure you use+ production mode when deploying to a production server.diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex 30c20ce5d1..4e961ae08c 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -29,11 +29,16 @@ from ...order.utils import update_order_statusfrom ...page.models import Pagefrom ...payment import ChargeStatus, TransactionType<<<<<<< HEAD+<<<<<<< HEADfrom ...payment.models import PaymentMethod=======from ...payment.utils import get_billing_datafrom ...payment.models import Payment>>>>>>> Rename PaymentMethod to Payment+=======+from ...payment.models import Payment+from ...payment.utils import get_billing_data+>>>>>>> Add documentation on adding new payment gateway, fix style and inconsistencies in namingfrom ...product.models import (Attribute, AttributeValue, Category, Collection, Product, ProductImage,ProductType, ProductVariant)diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.pyindex 572df14187..7dbc570f41 100644--- a/saleor/graphql/account/mutations.py+++ b/saleor/graphql/account/mutations.py@@ -102,7 +102,7 @@ class CustomerCreate(ModelMutation, I18nMixin):@classmethoddef clean_input(cls, info, instance, input, errors):shipping_address_data = input.pop(SHIPPING_ADDRESS_FIELD, None)- billing_address_data= input.pop(BILLING_ADDRESS_FIELD, None)+ billing_address_data = input.pop(BILLING_ADDRESS_FIELD, None)cleaned_input = super().clean_input(info, instance, input, errors)if shipping_address_data:diff --git a/saleor/graphql/api.py b/saleor/graphql/api.pyindex 26ebccd77c..53f846311c 100644--- a/saleor/graphql/api.py+++ b/saleor/graphql/api.py@@ -44,7 +44,7 @@ from .page.resolvers import resolve_page, resolve_pagesfrom .page.types import Pagefrom .product.schema import ProductMutations, ProductQueriesfrom .payment.types import Payment, PaymentGatewayEnum-from .payment.resolvers import resolve_payments, resolve_payment_client_token+from .payment.resolvers import resolve_payments, resolve_payment_transaction_tokenfrom .payment.mutations import (CheckoutPaymentCreate, PaymentCapture, PaymentRefund,PaymentVoid)@@ -123,7 +123,7 @@ class Query(ProductQueries):description=DESCRIPTIONS['page']),description='List of the shop\'s pages.')payment = graphene.Field(Payment, id=graphene.Argument(graphene.ID))- payment_client_token = graphene.Field(+ payment_transaction_token = graphene.Field(graphene.String, args={'gateway': PaymentGatewayEnum()})payments = DjangoFilterConnectionField(Payment,@@ -217,8 +217,8 @@ class Query(ProductQueries):def resolve_payment(self, info, id):return graphene.Node.get_node_from_global_id(info, id, Payment)- def resolve_payment_client_token(self, info, gateway=None):- return resolve_payment_client_token(gateway)+ def resolve_payment_transaction_token(self, info, gateway=None):+ return resolve_payment_transaction_token(gateway)@permission_required('order.manage_orders')def resolve_payments(self, info, query=None, **kwargs):diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.pyindex ae7bba4a12..11694b9352 100644--- a/saleor/graphql/core/mutations.py+++ b/saleor/graphql/core/mutations.py@@ -30,7 +30,8 @@ def get_output_fields(model, return_field_name):model_type = registry.get_type_for_model(model)if not model_type:raise ImproperlyConfigured(- 'Unable to find type for model %s in graphene registry' % model.__name__)+ 'Unable to find type for model %s in graphene registry' %+ model.__name__)fields = {return_field_name: graphene.Field(model_type)}return fields@@ -106,7 +107,7 @@ class BaseMutation(graphene.Mutation):Once a instance is created, this method runs `full_clean()` to performmodel fields' validation. Returns errors ready to be returned by- the GraphQL response (if any occured).+ the GraphQL response (if any occurred)."""try:instance.full_clean()diff --git a/saleor/graphql/payment/resolvers.py b/saleor/graphql/payment/resolvers.pyindex 9b233eca9a..8fb400b2e7 100644--- a/saleor/graphql/payment/resolvers.py+++ b/saleor/graphql/payment/resolvers.py@@ -1,5 +1,5 @@from ...payment import models-from ...payment.utils import gateway_get_client_token+from ...payment.utils import gateway_get_transaction_tokenfrom ..utils import filter_by_query_paramPAYMENT_SEARCH_FIELDS = ['id']@@ -12,6 +12,6 @@ def resolve_payments(info, query):return queryset-def resolve_payment_client_token(gateway=None):+def resolve_payment_transaction_token(gateway=None):# FIXME Add tests- return gateway_get_client_token(gateway)+ return gateway_get_transaction_token(gateway)diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.pyindex eab80cda42..aa9a2b51ad 100644--- a/saleor/graphql/payment/types.py+++ b/saleor/graphql/payment/types.py@@ -12,7 +12,7 @@ PaymentChargeStatusEnum = graphene.Enum(class Payment(CountableDjangoObjectType):- #FIXME gateway_response field should be resolved into query-readable format+ # FIXME gateway_response field should be resolved into query-readable format# if we want to use it on the frontend# otherwise it should be removed from this typecharge_status = PaymentChargeStatusEnum(diff --git a/saleor/payment/models.py b/saleor/payment/models.pyindex f38117edbf..6175c2f419 100644--- a/saleor/payment/models.py+++ b/saleor/payment/models.py@@ -78,12 +78,12 @@ class Payment(models.Model):transaction_type=TransactionType.AUTH, is_success=True)return txn- def authorize(self, client_token):+ def authorize(self, transaction_token):# FIXME Used for backwards compatibility, remove after moving to# dashboard 2.0from . import utilsreturn utils.gateway_authorize(- payment=self, transaction_token=client_token)+ payment=self, transaction_token=transaction_token)def void(self):# FIXME Used for backwards compatibility, remove after moving to@@ -95,12 +95,16 @@ class Payment(models.Model):# FIXME Used for backwards compatibility, remove after moving to# dashboard 2.0from . import utils+ if amount is None:+ amount = self.total.amountreturn utils.gateway_capture(payment=self, amount=amount)def refund(self, amount=None):# FIXME Used for backwards compatibility, remove after moving to# dashboard 2.0from . import utils+ if amount is None:+ amount = self.total.amountreturn utils.gateway_refund(payment=self, amount=amount)diff --git a/saleor/payment/providers/braintree/__init__.py b/saleor/payment/providers/braintree/__init__.pyindex 0a106fc2ff..f637697004 100644--- a/saleor/payment/providers/braintree/__init__.py+++ b/saleor/payment/providers/braintree/__init__.py@@ -1,5 +1,6 @@import logging-from typing import Dict+from decimal import Decimal+from typing import Dict, List, Tupleimport braintree as braintree_sdkfrom django.conf import settings@@ -7,10 +8,10 @@ from django.core.exceptions import ImproperlyConfiguredfrom django.utils.translation import pgettext_lazyfrom ... import TransactionType+from ...models import Payment, Transactionfrom ...utils import create_transactionlogger = logging.getLogger(__name__)-# FIXME: Move to SiteSettings# If this option is checked, then one needs to authorize the amount paid@@ -24,7 +25,7 @@ THREE_D_SECURE_REQUIRED = FalseERROR_CODES_WHITELIST = []-def get_customer_data(payment):+def get_customer_data(payment: Payment) -> Dict:return {'billing': {'first_name': payment.billing_first_name,@@ -42,7 +43,7 @@ def get_customer_data(payment):'email': payment.billing_email}}-def get_error_for_client(errors):+def get_error_for_client(errors: List) -> str:"""Filters all error messages and decides which one is visible for theclient side."""@@ -58,7 +59,11 @@ def get_error_for_client(errors):return default_msg-def transaction_and_incorrect_token_error(payment, token, type, amount=None):+def transaction_and_incorrect_token_error(+ payment: Payment,+ token: str,+ type: TransactionType,+ amount: Decimal = None) -> Tuple[Transaction, str]:amount = payment.total.amount if amount is None else amounttxn = create_transaction(payment=payment,@@ -121,14 +126,17 @@ def get_gateway(sandbox_mode, merchant_id, public_key, private_key):return gateway-def get_client_token(**client_kwargs):- gateway = get_gateway(**client_kwargs)- client_token = gateway.client_token.generate()- return client_token+def get_transaction_token(**connection_params: Dict) -> str:+ gateway = get_gateway(**connection_params)+ transaction_token = gateway.client_token.generate()+ return transaction_token-def authorize(payment, transaction_token, **client_kwargs):- gateway = get_gateway(**client_kwargs)+def authorize(+ payment: Payment,+ transaction_token: str,+ **connection_params: Dict) -> Tuple[Transaction, str]:+ gateway = get_gateway(**connection_params)try:result = gateway.transaction.sale({'amount': str(payment.total.amount),@@ -154,16 +162,16 @@ def authorize(payment, transaction_token, **client_kwargs):return txn, error-def capture(payment, amount=None, **client_kwargs):- gateway = get_gateway(**client_kwargs)+def capture(+ payment: Payment,+ amount: Decimal,+ **connection_params: Dict) -> Tuple[Transaction, str]:+ gateway = get_gateway(**connection_params)auth_transaction = payment.transactions.filter(transaction_type=TransactionType.AUTH).first()- if not amount:- amount = payment.total.amount-try:result = gateway.transaction.submit_for_settlement(- transaction_id=auth_transaction.token, amount=str(amount))+ transaction_token=auth_transaction.token, amount=str(amount))except braintree_sdk.exceptions.NotFoundError:return transaction_and_incorrect_token_error(payment,@@ -184,13 +192,15 @@ def capture(payment, amount=None, **client_kwargs):return txn, error-def void(payment, **client_kwargs):- gateway = get_gateway(**client_kwargs)+def void(+ payment: Payment,+ **connection_params: Dict) -> Tuple[Transaction, str]:+ gateway = get_gateway(**connection_params)auth_transaction = payment.transactions.filter(transaction_type=TransactionType.AUTH).first()try:result = gateway.transaction.void(- transaction_id=auth_transaction.token)+ transaction_token=auth_transaction.token)except braintree_sdk.exceptions.NotFoundError:return transaction_and_incorrect_token_error(payment, type=TransactionType.VOID, token=auth_transaction.token)@@ -207,20 +217,20 @@ def void(payment, **client_kwargs):return txn, error-def refund(payment, amount=None, **client_kwargs):- gateway = get_gateway(**client_kwargs)- auth_transaction = payment.transactions.filter(+def refund(+ payment: Payment,+ amount: Decimal,+ **connection_params: Dict) -> Tuple[Transaction, str]:+ gateway = get_gateway(**connection_params)+ capture_txn = payment.transactions.filter(transaction_type=TransactionType.CAPTURE).first()- if not amount:- amount = payment.total.amount-try:result = gateway.transaction.refund(- transaction_id=auth_transaction.token,+ transaction_token=capture_txn.token,amount_or_options=str(amount))except braintree_sdk.exceptions.NotFoundError:return transaction_and_incorrect_token_error(- payment, type=TransactionType.REFUND, token=auth_transaction.token,+ payment, type=TransactionType.REFUND, token=capture_txn.token,amount=amount)gateway_response = extract_gateway_response(result)diff --git a/saleor/payment/providers/dummy/__init__.py b/saleor/payment/providers/dummy/__init__.pyindex 3e9102fead..75bf985e06 100644--- a/saleor/payment/providers/dummy/__init__.py+++ b/saleor/payment/providers/dummy/__init__.py@@ -8,11 +8,11 @@ def dummy_success():return True-def get_client_token(**client_kwargs):+def get_transaction_token(**connection_params):return str(uuid.uuid4())-def authorize(payment, transaction_token, **client_kwargs):+def authorize(payment, transaction_token, **connection_params):success = dummy_success()error = Noneif not success:@@ -27,7 +27,7 @@ def authorize(payment, transaction_token, **client_kwargs):return txn, error-def void(payment, **client_kwargs):+def void(payment, **connection_params):error = Nonesuccess = dummy_success()if not success:@@ -42,7 +42,7 @@ def void(payment, **client_kwargs):return txn, error-def capture(payment, amount=None):+def capture(payment, amount):error = Nonesuccess = dummy_success()if not success:@@ -56,7 +56,7 @@ def capture(payment, amount=None):return txn, error-def refund(payment, amount=None):+def refund(payment, amount):error = Nonesuccess = dummy_success()if not success:diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 6b743e2ee2..126d2cfe0a 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -88,11 +88,10 @@ def create_transaction(return txn-def gateway_get_client_token(provider_name: str):+def gateway_get_transaction_token(provider_name: str):# FIXME Add tests-provider, provider_params = get_provider(provider_name)- return provider.get_client_token(**provider_params)+ return provider.get_transaction_token(**provider_params)@validate_paymentdiff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex 9651af8e50..d58bb16e81 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -104,9 +104,9 @@ def test_checkout_add_payment(content = get_graphql_content(response)data = content['data']['checkoutPaymentCreate']assert not data['errors']- transaction_id = data['payment']['transactions']['edges'][0]['node'][+ transaction_token = data['payment']['transactions']['edges'][0]['node']['token']- txn = Transaction.objects.filter(token=transaction_id).first()+ txn = Transaction.objects.filter(token=transaction_token).first()assert txn.transaction_type == TransactionType.AUTHassert txn is not Nonepayment = txn.paymentdiff --git a/tests/test_payment.py b/tests/test_payment.pyindex 30d7801c77..a912175a3f 100644--- a/tests/test_payment.py+++ b/tests/test_payment.py@@ -6,7 +6,7 @@ from .utils import moneydef test_authorize(payment_dummy):- txn = payment_dummy.authorize(client_token='Fake')+ txn = payment_dummy.authorize(transaction_token='Fake')assert txn.is_successassert txn.transaction_type == TransactionType.AUTHassert txn.payment == payment_dummy@@ -18,7 +18,7 @@ def test_authorize_gateway_error(payment_dummy, monkeypatch):monkeypatch.setattr('saleor.payment.providers.dummy.dummy_success', lambda: False)with pytest.raises(PaymentError):- txn = payment_dummy.authorize(client_token='Fake')+ txn = payment_dummy.authorize(transaction_token='Fake')assert txn.transaction_type == TransactionType.AUTHassert not txn.is_successassert txn.payment == payment_dummydiff --git a/tests/test_payment_braintree.py b/tests/test_payment_braintree.pyindex b0f121f895..1842ee78f9 100644--- a/tests/test_payment_braintree.py+++ b/tests/test_payment_braintree.py@@ -9,11 +9,10 @@ from braintree.exceptions import NotFoundErrorfrom braintree.validation_error import ValidationErrorfrom django.core.exceptions import ImproperlyConfigured-import saleor.payment.providers.braintree as payment_modulefrom saleor.payment import TransactionTypefrom saleor.payment.providers.braintree import (CONFIRM_MANUALLY, THREE_D_SECURE_REQUIRED, authorize, capture,- extract_gateway_response, get_client_token, get_customer_data,+ extract_gateway_response, get_transaction_token, get_customer_data,get_error_for_client, get_gateway, refund,transaction_and_incorrect_token_error, void)@@ -106,16 +105,21 @@ def test_get_customer_data(payment_dummy):assert result == expected_result-def test_get_error_for_client(braintree_error):++def test_get_error_for_client(braintree_error, monkeypatch):# no errorassert get_error_for_client([]) == ''- # error not whitelisted- payment_module.ERROR_CODES_WHITELIST = []error = {'code': braintree_error.code, 'message': braintree_error.message}++ # error not whitelisted+ monkeypatch.setattr(+ 'saleor.payment.providers.braintree.ERROR_CODES_WHITELIST', [])assert get_error_for_client([error]) == DEFAULT_ERROR- payment_module.ERROR_CODES_WHITELIST = [braintree_error.code]+ monkeypatch.setattr(+ 'saleor.payment.providers.braintree.ERROR_CODES_WHITELIST',+ [braintree_error.code])assert get_error_for_client([error]) == braintree_error.message@@ -173,14 +177,14 @@ def test_get_gateway_inproperly_configured(gateway_config):@patch('saleor.payment.providers.braintree.get_gateway')-def test_get_client_token(mock_gateway, gateway_config):- client_token = 'client-token'- mock_generate = Mock(return_value='client-token')+def test_get_transaction_token(mock_gateway, gateway_config):+ transaction_token = 'transaction-token'+ mock_generate = Mock(return_value='transaction-token')mock_gateway.return_value = Mock(client_token=Mock(generate=mock_generate))- result = get_client_token(**gateway_config)+ result = get_transaction_token(**gateway_config)mock_gateway.assert_called_once_with(**gateway_config)mock_generate.assert_called_once()- assert result == client_token+ assert result == transaction_token@pytest.mark.integration@@ -268,7 +272,7 @@ def test_refund(capture_txn = payment.transactions.filter(transaction_type=TransactionType.CAPTURE).first()mock_response.assert_called_once_with(- amount_or_options=str(amount), transaction_id=capture_txn.token)+ amount_or_options=str(amount), transaction_token=capture_txn.token)@pytest.mark.integration@@ -332,7 +336,7 @@ def test_capture(auth_txn = payment.transactions.filter(transaction_type=TransactionType.AUTH).first()mock_response.assert_called_once_with(- amount=str(amount), transaction_id=auth_txn.token)+ amount=str(amount), transaction_token=auth_txn.token)@pytest.mark.integration@@ -396,7 +400,7 @@ def test_void(auth_txn = payment.transactions.filter(transaction_type=TransactionType.AUTH).first()- mock_response.assert_called_once_with(transaction_id=auth_txn.token)+ mock_response.assert_called_once_with(transaction_token=auth_txn.token)@pytest.mark.integration