コード例 #1
0
def test_stripe_checkout_phase_with_saved_card_exception(
        rf, stripe_payment_processor):
    shop = factories.get_default_shop()
    user = factories.create_random_user()
    contact = get_person_contact(user)
    request = apply_request_middleware(rf.post("/"),
                                       shop=shop,
                                       customer=contact)

    def raise_stripe_exc(*args, **kwargs):
        raise stripe.StripeError("DUMMY")

    with mock.patch("stripe.Customer.retrieve", new=raise_stripe_exc):
        service = stripe_payment_processor.create_service(
            "stripe",
            shop=request.shop,
            tax_class=factories.get_default_tax_class(),
            enabled=True)

        StripeCustomer.objects.create(contact=contact, customer_token="123")
        checkout_phase = StripeCheckoutPhase(request=request, service=service)
        assert not checkout_phase.is_valid()
        context = checkout_phase.get_context_data()
        assert context["stripe"]
        assert not context.get("stripe_customer_data")

        request.method = "POST"
        request.POST = {}
        checkout_phase.get_success_url = lambda: reverse("shuup_admin:home")
        checkout_phase.post(request)
        assert not checkout_phase.is_valid()
コード例 #2
0
def test_stripe_checkout_phase_with_saved_card(rf, stripe_payment_processor):
    shop = factories.get_default_shop()
    user = factories.create_random_user()
    contact = get_person_contact(user)
    request = apply_request_middleware(rf.post("/"),
                                       shop=shop,
                                       customer=contact)

    def return_stripe_mock_data(*args, **kwargs):
        return StripedData(**CUSTOMER_MOCK_DATA)

    with mock.patch("stripe.Customer.retrieve", new=return_stripe_mock_data):
        service = stripe_payment_processor.create_service(
            "stripe",
            shop=request.shop,
            tax_class=factories.get_default_tax_class(),
            enabled=True)

        StripeCustomer.objects.create(contact=contact, customer_token="123")
        checkout_phase = StripeCheckoutPhase(request=request, service=service)
        assert not checkout_phase.is_valid()
        context = checkout_phase.get_context_data()
        assert context["stripe"]
        request.method = "POST"
        request.POST = {"stripeCustomer": "1234"}
        checkout_phase.get_success_url = lambda: reverse("shuup_admin:home")
        checkout_phase.post(request)
        assert checkout_phase.is_valid()  # We should be valid now
        assert request.session  # And things should've been saved into the session
        checkout_phase.process()  # And this should do things to the basket
        assert request.basket.payment_data["stripe"]["customer"]
コード例 #3
0
def test_stripe_checkout_phase(rf):
    request = apply_request_middleware(rf.post("/"), shop=get_default_shop())
    request.session = {}
    request.basket = get_basket(request)

    payment_processor = StripeCheckoutPaymentProcessor.objects.create(
        secret_key="secret", publishable_key="12", name="Stripe")
    service = payment_processor.create_service(
        "stripe",
        shop=request.shop,
        tax_class=get_default_tax_class(),
        enabled=True)
    checkout_phase = StripeCheckoutPhase(request=request, service=service)
    assert not checkout_phase.is_valid()  # We can't be valid just yet
    context = checkout_phase.get_context_data()
    assert context["stripe"]
    request.method = "POST"
    request.POST = {
        "stripeToken": "1234",
        "stripeTokenType": "12442",
        "stripeTokenEmail": "4212342",
    }
    checkout_phase.get_success_url = lambda: reverse("shuup_admin:home")
    checkout_phase.post(request)
    assert checkout_phase.is_valid()  # We should be valid now
    assert request.session  # And things should've been saved into the session
    checkout_phase.process()  # And this should do things to the basket
    assert request.basket.payment_data.get("stripe")
コード例 #4
0
ファイル: test_stripe.py プロジェクト: nathan3d/shuup-stripe
def test_stripe_checkout_phase(rf, stripe_payment_processor):
    request = rf.get("/")
    request.shop = get_default_shop()
    request.session = {}
    request.basket = get_basket(request)
    service = stripe_payment_processor.create_service(
        None,
        shop=request.shop,
        tax_class=get_default_tax_class(),
        enabled=True)
    checkout_phase = StripeCheckoutPhase(request=request, service=service)
    assert not checkout_phase.is_valid()  # We can't be valid just yet
    context = checkout_phase.get_context_data()
    assert context["stripe"]
    request.method = "POST"
    token = get_stripe_token(stripe_payment_processor)
    request.POST = {
        "stripeToken": token["id"],
        "stripeTokenType": token["type"],
        "stripeTokenEmail": token.get("email"),
    }
    checkout_phase.post(request)
    assert checkout_phase.is_valid()  # We should be valid now
    assert request.session  # And things should've been saved into the session
    checkout_phase.process()  # And this should do things to the basket
    assert request.basket.payment_data.get("stripe")
コード例 #5
0
def test_stripe_checkout_phase_with_saved_card(rf, stripe_payment_processor):
    shop = factories.get_default_shop()
    user = factories.create_random_user()
    contact = get_person_contact(user)
    request = apply_request_middleware(rf.post("/"), shop=shop, customer=contact)

    def return_stripe_mock_data(*args, **kwargs):
        return StripedData(**CUSTOMER_MOCK_DATA)

    with mock.patch("stripe.Customer.retrieve", new=return_stripe_mock_data):
        service = stripe_payment_processor.create_service(
            "stripe", shop=request.shop, tax_class=factories.get_default_tax_class(), enabled=True)

        StripeCustomer.objects.create(contact=contact, customer_token="123")
        checkout_phase = StripeCheckoutPhase(request=request, service=service)
        assert not checkout_phase.is_valid()
        context = checkout_phase.get_context_data()
        assert context["stripe"]
        request.method = "POST"
        request.POST = {
            "stripeCustomer": "1234"
        }
        checkout_phase.get_success_url = lambda: reverse("shuup_admin:home")
        checkout_phase.post(request)
        assert checkout_phase.is_valid()  # We should be valid now
        assert request.session  # And things should've been saved into the session
        checkout_phase.process()  # And this should do things to the basket
        assert request.basket.payment_data["stripe"]["customer"]
コード例 #6
0
def test_stripe_checkout_phase_with_saved_card_exception(rf, stripe_payment_processor):
    shop = factories.get_default_shop()
    user = factories.create_random_user()
    contact = get_person_contact(user)
    request = apply_request_middleware(rf.post("/"), shop=shop, customer=contact)

    def raise_stripe_exc(*args, **kwargs):
        raise stripe.StripeError("DUMMY")

    with mock.patch("stripe.Customer.retrieve", new=raise_stripe_exc):
        service = stripe_payment_processor.create_service(
            "stripe", shop=request.shop, tax_class=factories.get_default_tax_class(), enabled=True)

        StripeCustomer.objects.create(contact=contact, customer_token="123")
        checkout_phase = StripeCheckoutPhase(request=request, service=service)
        assert not checkout_phase.is_valid()
        context = checkout_phase.get_context_data()
        assert context["stripe"]
        assert not context.get("stripe_customer_data")

        request.method = "POST"
        request.POST = {}
        checkout_phase.get_success_url = lambda: reverse("shuup_admin:home")
        checkout_phase.post(request)
        assert not checkout_phase.is_valid()
コード例 #7
0
ファイル: test_stripe.py プロジェクト: farzeni/shuup-stripe
def test_stripe_checkout_phase(rf, stripe_payment_processor):
    request = rf.get("/")
    request.shop = get_default_shop()
    request.session = {}
    request.basket = get_basket(request)
    service = stripe_payment_processor.create_service(
        None, shop=request.shop, tax_class=get_default_tax_class(),
        enabled=True)
    checkout_phase = StripeCheckoutPhase(
        request=request, service=service)
    assert not checkout_phase.is_valid()  # We can't be valid just yet
    context = checkout_phase.get_context_data()
    assert context["stripe"]
    request.method = "POST"
    token = get_stripe_token(stripe_payment_processor)
    request.POST = {
        "stripeToken": token["id"],
        "stripeTokenType": token["type"],
        "stripeTokenEmail": token.get("email"),
    }
    checkout_phase.post(request)
    assert checkout_phase.is_valid()  # We should be valid now
    assert request.session  # And things should've been saved into the session
    checkout_phase.process()  # And this should do things to the basket
    assert request.basket.payment_data.get("stripe")