Example #1
0
def test_stored_payment_sources_restriction(
    mocker, staff_api_client, customer_user, permission_manage_users
):
    # Only owner of storedPaymentSources can fetch it.
    card = CreditCardInfo(
        last_4="5678", exp_year=2020, exp_month=12, name_on_card="JohnDoe"
    )
    source = CustomerSource(id="test1", gateway="dummy", credit_card_info=card)
    mocker.patch(
        "saleor.graphql.account.resolvers.gateway.list_payment_sources",
        return_value=[source],
        autospec=True,
    )

    customer_user_id = graphene.Node.to_global_id("User", customer_user.pk)
    query = """
        query PaymentSources($id: ID!) {
            user(id: $id) {
                storedPaymentSources {
                    creditCardInfo {
                        firstDigits
                    }
                }
            }
        }
    """
    variables = {"id": customer_user_id}
    response = staff_api_client.post_graphql(
        query, variables, permissions=[permission_manage_users]
    )
    assert_no_permission(response)
Example #2
0
def test_list_payment_sources(
    mocker, dummy_customer_id, set_dummy_customer_id, user_api_client
):
    gateway = "mirumee.payments.dummy"
    query = """
    {
        me {
            storedPaymentSources {
                gateway
                creditCardInfo {
                    lastDigits
                }
            }
        }
    }
    """
    card = CreditCardInfo(
        last_4="5678", exp_year=2020, exp_month=12, name_on_card="JohnDoe"
    )
    source = CustomerSource(id="test1", gateway=gateway, credit_card_info=card)
    mock_get_source_list = mocker.patch(
        "saleor.graphql.account.resolvers.gateway.list_payment_sources",
        return_value=[source],
        autospec=True,
    )
    response = user_api_client.post_graphql(query)

    mock_get_source_list.assert_called_once_with(gateway, dummy_customer_id)
    content = get_graphql_content(response)["data"]["me"]["storedPaymentSources"]
    assert content is not None and len(content) == 1
    assert content[0] == {"gateway": gateway, "creditCardInfo": {"lastDigits": "5678"}}
Example #3
0
def test_list_customer_sources(sandbox_braintree_gateway_config):
    CUSTOMER_ID = "595109854"  # retrieved from sandbox
    expected_credit_card = CreditCardInfo(
        last_4="1881", exp_year=2020, exp_month=12, name_on_card=None
    )
    expected_customer_source = CustomerSource(
        id="d0b52c80b648ae8e5a14eddcaf24d254",
        gateway="braintree",
        credit_card_info=expected_credit_card,
    )
    sources = list_client_sources(sandbox_braintree_gateway_config, CUSTOMER_ID)
    assert sources == [expected_customer_source]
Example #4
0
def test_list_customer_sources(sandbox_gateway_config):
    CUSTOMER_ID = "cus_FbquUfgBnLdlsY"  # retrieved from sandbox
    expected_credit_card = CreditCardInfo(
        last_4="0005", exp_year=2020, exp_month=8, name_on_card=None
    )
    expected_customer_source = CustomerSource(
        id="pm_1F6dCWIUmJaD6OqvCtcAnPSq",
        gateway="stripe",
        credit_card_info=expected_credit_card,
    )
    sources = list_client_sources(sandbox_gateway_config, CUSTOMER_ID)
    assert sources == [expected_customer_source]