Exemplo n.º 1
0
def test_refund_unavailable(env, factory, monkeypatch):
    event, order = env

    def charge_retr(*args, **kwargs):
        def refund_create(amount):
            raise APIConnectionError(message='Foo')

        c = MockedCharge()
        c.refunds.create = refund_create
        return c

    monkeypatch.setattr("stripe.Charge.retrieve", charge_retr)
    order.status = Order.STATUS_PAID
    p = order.payments.create(provider='stripe_cc',
                              amount=order.total,
                              info=json.dumps({'id': 'ch_123345345'}))
    order.save()
    prov = StripeCC(event)
    refund = order.refunds.create(provider='stripe_cc',
                                  amount=order.total,
                                  payment=p)
    with pytest.raises(PaymentException):
        prov.execute_refund(refund)
    refund.refresh_from_db()
    assert refund.state != OrderRefund.REFUND_STATE_DONE
Exemplo n.º 2
0
def test_refund_unavailable(env, factory, monkeypatch):
    event, order = env

    def charge_retr(*args, **kwargs):
        def refund_create(amount):
            raise APIConnectionError(message='Foo')

        c = MockedCharge()
        c.refunds.create = refund_create
        return c

    monkeypatch.setattr("stripe.Charge.retrieve", charge_retr)
    order.status = Order.STATUS_PAID
    p = order.payments.create(provider='stripe_cc', amount=order.total, info=json.dumps({
        'id': 'ch_123345345'
    }))
    order.save()
    prov = StripeCC(event)
    refund = order.refunds.create(
        provider='stripe_cc', amount=order.total, payment=p
    )
    with pytest.raises(PaymentException):
        prov.execute_refund(refund)
    refund.refresh_from_db()
    assert refund.state != OrderRefund.REFUND_STATE_DONE
Exemplo n.º 3
0
def test_refund_success(env, factory, monkeypatch):
    event, order = env

    def charge_retr(*args, **kwargs):
        def refund_create(amount):
            r = MockedCharge()
            r.id = 'foo'
            r.status = 'succeeded'
            return r

        c = MockedCharge()
        c.refunds.create = refund_create
        return c

    monkeypatch.setattr("stripe.Charge.retrieve", charge_retr)
    order.status = Order.STATUS_PAID
    p = order.payments.create(provider='stripe_cc',
                              amount=order.total,
                              info=json.dumps({'id': 'ch_123345345'}))
    order.save()
    prov = StripeCC(event)
    refund = order.refunds.create(
        provider='stripe_cc',
        amount=order.total,
        payment=p,
    )
    prov.execute_refund(refund)
    refund.refresh_from_db()
    assert refund.state == OrderRefund.REFUND_STATE_DONE
Exemplo n.º 4
0
def test_refund_success(env, factory, monkeypatch):
    event, order = env

    def charge_retr(*args, **kwargs):
        def refund_create(amount):
            r = MockedCharge()
            r.id = 'foo'
            r.status = 'succeeded'
            return r

        c = MockedCharge()
        c.refunds.create = refund_create
        return c

    monkeypatch.setattr("stripe.Charge.retrieve", charge_retr)
    order.status = Order.STATUS_PAID
    p = order.payments.create(provider='stripe_cc', amount=order.total, info=json.dumps({
        'id': 'ch_123345345'
    }))
    order.save()
    prov = StripeCC(event)
    refund = order.refunds.create(
        provider='stripe_cc', amount=order.total, payment=p,
    )
    prov.execute_refund(refund)
    refund.refresh_from_db()
    assert refund.state == OrderRefund.REFUND_STATE_DONE