예제 #1
0
def test_perform_failed(env, factory, monkeypatch):
    event, order = env

    def charge_create(**kwargs):
        c = MockedCharge()
        c.status = 'failed'
        c.paid = True
        c.failure_message = 'Foo'
        return c

    monkeypatch.setattr("stripe.Charge.create", charge_create)
    prov = Stripe(event)
    req = factory.post(
        '/', {
            'stripe_token': 'tok_189fTT2eZvKYlo2CvJKzEzeu',
            'stripe_last4': '4242',
            'stripe_brand': 'Visa'
        })
    req.session = {}
    prov.checkout_prepare(req, {})
    assert 'payment_stripe_token' in req.session
    with pytest.raises(PaymentException):
        prov.payment_perform(req, order)
    order.refresh_from_db()
    assert order.status == Order.STATUS_PENDING
예제 #2
0
def test_perform_success(env, factory, monkeypatch):
    event, order = env

    def charge_create(**kwargs):
        assert kwargs['amount'] == 1337
        assert kwargs['currency'] == 'eur'
        assert kwargs['source'] == 'tok_189fTT2eZvKYlo2CvJKzEzeu'
        c = MockedCharge()
        c.status = 'succeeded'
        c.paid = True
        return c

    monkeypatch.setattr("stripe.Charge.create", charge_create)
    prov = Stripe(event)
    req = factory.post(
        '/', {
            'stripe_token': 'tok_189fTT2eZvKYlo2CvJKzEzeu',
            'stripe_last4': '4242',
            'stripe_brand': 'Visa'
        })
    req.session = {}
    prov.checkout_prepare(req, {})
    assert 'payment_stripe_token' in req.session
    prov.payment_perform(req, order)
    order.refresh_from_db()
    assert order.status == Order.STATUS_PAID
예제 #3
0
def test_perform_card_error(env, factory, monkeypatch):
    event, order = env

    def charge_create(**kwargs):
        raise CardError(message='Foo', param='foo', code=100)

    monkeypatch.setattr("stripe.Charge.create", charge_create)
    prov = Stripe(event)
    req = factory.post(
        '/', {
            'stripe_token': 'tok_189fTT2eZvKYlo2CvJKzEzeu',
            'stripe_last4': '4242',
            'stripe_brand': 'Visa'
        })
    req.session = {}
    prov.checkout_prepare(req, {})
    assert 'payment_stripe_token' in req.session
    prov.payment_perform(req, order)
    order.refresh_from_db()
    assert order.status == Order.STATUS_PENDING