def test_perform_success_zero_decimal_currency(env, factory, monkeypatch): event, order = env event.currency = 'JPY' event.save() def charge_create(**kwargs): assert kwargs['amount'] == 13 assert kwargs['currency'] == 'jpy' assert kwargs['source'] == 'tok_189fTT2eZvKYlo2CvJKzEzeu' c = MockedCharge() c.status = 'succeeded' c.paid = True return c monkeypatch.setattr("stripe.Charge.create", charge_create) prov = StripeCC(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
def test_perform_failed(env, factory, monkeypatch): event, order = env def paymentintent_create(**kwargs): assert kwargs['amount'] == 1337 assert kwargs['currency'] == 'eur' assert kwargs['payment_method'] == 'pm_189fTT2eZvKYlo2CvJKzEzeu' c = MockedPaymentintent() c.status = 'failed' c.failure_message = 'Foo' c.charges.data[0].paid = True c.last_payment_error = Object() c.last_payment_error.message = "Foo" return c monkeypatch.setattr("stripe.PaymentIntent.create", paymentintent_create) prov = StripeCC(event) req = factory.post( '/', { 'stripe_payment_method_id': 'pm_189fTT2eZvKYlo2CvJKzEzeu', 'stripe_last4': '4242', 'stripe_brand': 'Visa' }) req.session = {} prov.checkout_prepare(req, {}) assert 'payment_stripe_payment_method_id' in req.session with pytest.raises(PaymentException): payment = order.payments.create(provider='stripe_cc', amount=order.total) prov.execute_payment(req, payment) order.refresh_from_db() assert order.status == Order.STATUS_PENDING
def test_perform_success_zero_decimal_currency(env, factory, monkeypatch): event, order = env event.currency = 'JPY' event.save() def paymentintent_create(**kwargs): assert kwargs['amount'] == 13 assert kwargs['currency'] == 'jpy' assert kwargs['payment_method'] == 'pm_189fTT2eZvKYlo2CvJKzEzeu' c = MockedPaymentintent() c.status = 'succeeded' c.charges.data[0].paid = True return c monkeypatch.setattr("stripe.PaymentIntent.create", paymentintent_create) prov = StripeCC(event) req = factory.post( '/', { 'stripe_payment_method_id': 'pm_189fTT2eZvKYlo2CvJKzEzeu', 'stripe_last4': '4242', 'stripe_brand': 'Visa' }) req.session = {} prov.checkout_prepare(req, {}) assert 'payment_stripe_payment_method_id' in req.session payment = order.payments.create(provider='stripe_cc', amount=order.total) prov.execute_payment(req, payment) order.refresh_from_db() assert order.status == Order.STATUS_PAID
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 = StripeCC(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
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 = StripeCC(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 payment = order.payments.create( provider='stripe_cc', amount=order.total ) prov.execute_payment(req, payment) order.refresh_from_db() assert order.status == Order.STATUS_PAID
def test_perform_success_zero_decimal_currency(env, factory, monkeypatch): event, order = env event.currency = 'JPY' event.save() def charge_create(**kwargs): assert kwargs['amount'] == 13 assert kwargs['currency'] == 'jpy' assert kwargs['source'] == 'tok_189fTT2eZvKYlo2CvJKzEzeu' c = MockedCharge() c.status = 'succeeded' c.paid = True return c monkeypatch.setattr("stripe.Charge.create", charge_create) prov = StripeCC(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 payment = order.payments.create( provider='stripe_cc', amount=order.total ) prov.execute_payment(req, payment) order.refresh_from_db() assert order.status == Order.STATUS_PAID
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 = StripeCC(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): payment = order.payments.create( provider='stripe_cc', amount=order.total ) prov.execute_payment(req, payment) order.refresh_from_db() assert order.status == Order.STATUS_PENDING
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 = StripeCC(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
def test_perform_stripe_error(env, factory, monkeypatch): event, order = env def paymentintent_create(**kwargs): raise CardError(message='Foo', param='foo', code=100) monkeypatch.setattr("stripe.PaymentIntent.create", paymentintent_create) prov = StripeCC(event) req = factory.post( '/', { 'stripe_payment_method_id': 'pm_189fTT2eZvKYlo2CvJKzEzeu', 'stripe_last4': '4242', 'stripe_brand': 'Visa' }) req.session = {} prov.checkout_prepare(req, {}) assert 'payment_stripe_payment_method_id' in req.session with pytest.raises(PaymentException): payment = order.payments.create(provider='stripe_cc', amount=order.total) prov.execute_payment(req, payment) order.refresh_from_db() assert order.status == Order.STATUS_PENDING