def test_invalid_cvc(self):
		card_info = {'number': '5555555555554444', 'exp_month': 12, 'exp_year': 2020, 'cvc': 54,}
		with self.assertRaises( CardError ) as cm:
			gateway.charge( 4000, card_info=card_info )

		obj = cm.exception
		self.assertEqual( obj.http_status, 402 )

		body = obj.json_body
		err  = body['error']

		self.assertEqual( err['code'], u'invalid_cvc' )
	def test_expired_card_charge(self):
		card_info = {'number': '4000000000000119', 'exp_month': 12, 'exp_year': 2017, 'cvc': 544,}
		
		with self.assertRaises( CardError ) as cm:
			gateway.charge( 4000, card_info=card_info )

		obj = cm.exception
		self.assertEqual( obj.http_status, 402 )

		body = obj.json_body
		err  = body['error']

		self.assertEqual( err['code'], u'processing_error' )
Beispiel #3
0
def charge(order_number, total, bankcard, currency='CAD'):
    try:
        metadata = {
            'order_number': order_number,
        }
        card_info = {
            'number': bankcard.number, 
            'exp_month': bankcard.expiry_date.month, 
            'exp_year': bankcard.expiry_date.year, 
            'cvc': bankcard.ccv,
        }
        total_in_cents = int(total.incl_tax * 100)

        charge = gateway.charge( total_in_cents, currency=currency.lower(), card_info=card_info, metadata=metadata )


    except gateway.CardInfoError, e:
        raise UnableToTakePayment( e )
	def test_invalid_cardinfo(self):
		#missing card info
		card_info = {'exp_month': 12, 'exp_year': 2020, 'cvc': 54,}

		with self.assertRaises( gateway.CardInfoError ) as cm:
			gateway.charge( 4000, card_info=card_info )
	def test_successful_charge(self):
		card_info = {'number': '5555555555554444', 'exp_month': 12, 'exp_year': 2017, 'cvc': 544,}
		obj = gateway.charge(4000, card_info=card_info)

		self.assertEqual( obj['amount'], 4000)
		self.assertEqual( obj['captured'], True)
	def setUp(self):
		card_info = {'number': '5555555555554444', 'exp_month': 12, 'exp_year': 2017, 'cvc': 544,}
		self.charge = gateway.charge(4000, card_info=card_info)