def process_stripe_charge(order, token): logger.info('children:process_stripe_charge', order=order.order_id, token=token) assert order.payment_required() try: charge = create_charge_for_order(order, token) confirm_order(order, charge.id, charge.created) except stripe.error.CardError as e: mark_order_as_failed(order, e._message)
def process_stripe_charge(order, token): logger.info('process_stripe_charge', order=order.order_id, token=token) assert order.payment_required() try: charge = create_charge_for_order(order, token) confirm_order(order, charge.id, charge.created) except stripe.error.CardError as e: mark_order_as_failed(order, e._message) except IntegrityError: refund_charge(charge.id) mark_order_as_errored_after_charge(order, charge.id)
def test_create_charge_for_order_with_unsuccessful_charge(self): token = 'tok_abcdefghijklmnopqurstuvwx' with self.assertRaises(stripe.error.CardError): with utils.patched_charge_creation_failure(): stripe_integration.create_charge_for_order(self.order, token)
def test_create_charge_for_order_with_successful_charge(self): token = 'tok_abcdefghijklmnopqurstuvwx' with utils.patched_charge_creation_success(): charge = stripe_integration.create_charge_for_order( self.order, token) self.assertEqual(charge.id, 'ch_abcdefghijklmnopqurstuvw')