def test_shopper_with_two_encrypted_credit_cards_with_valid_selection_succeeds( self): amount_in_pence = 150 amount = amount_in_pence / 100.0 description = 'order description' order = OrderResource() order_obj = order.create( shopper_id=self.shopper_id_with_two_encrypted_credit_cards, sku_id=helper.TEST_PRODUCT_SKU_ID, amount_in_pence=amount_in_pence, credit_card=self.credit_card_selection, description=description) self.assertIsInstance(order_obj, dict) self.assertEqual(order_obj['ordering-shopper']['shopper-id'], self.shopper_id_with_two_encrypted_credit_cards) self.assertEqual(order_obj['cart']['charged-currency'], order.client.currency) self.assertEqual(order_obj['cart']['cart-item']['sku']['sku-id'], helper.TEST_PRODUCT_SKU_ID) self.assertEqual(int(order_obj['cart']['cart-item']['quantity']), 1) self.assertEqual( float(order_obj['cart']['cart-item']['item-sub-total']), amount) self.assertEqual(float(order_obj['cart']['tax']), 0.0) self.assertEqual(int(order_obj['cart']['tax-rate']), 0) self.assertEqual(float(order_obj['cart']['total-cart-cost']), amount) self.assertIsNotNone( order_obj['post-sale-info']['invoices']['invoice']['invoice-id']) self.assertIsNotNone( order_obj['post-sale-info']['invoices']['invoice']['url']) self.assertIsNotNone( order_obj['post-sale-info']['invoices']['invoice'] ['financial-transactions']['financial-transaction'] ['soft-descriptor'], description) self.assertEqual( float( order_obj['post-sale-info']['invoices']['invoice'] ['financial-transactions']['financial-transaction']['amount']), amount) self.assertEqual( order_obj['post-sale-info']['invoices']['invoice'] ['financial-transactions']['financial-transaction']['currency'], order.client.currency) self.assertEqual( order_obj['post-sale-info']['invoices']['invoice'] ['financial-transactions']['financial-transaction']['credit-card'] ['card-last-four-digits'], self.credit_card_selection.card_last_four_digits)
def test_shopper_with_two_credit_cards_with_invalid_selection_fails(self): order = OrderResource() with self.assertRaises(exceptions.APIError) as e: order.create( shopper_id=self.shopper_id_with_two_credit_cards, sku_id=helper.TEST_PRODUCT_SKU_ID, amount_in_pence=100, credit_card=CreditCardSelection( card_type=helper.DUMMY_CARD_AMEX['card_type'], card_last_four_digits=helper.DUMMY_CARD_AMEX['card_number'] [-4:])) self.assertEqual( e.exception.description, 'The order failed because shopper payment details were incorrect or insufficient.' )
def test_shopper_without_credit_card_creating_order_fails(self): order = OrderResource() # Without credit card selection with self.assertRaises(exceptions.APIError) as e: order.create(shopper_id=self.shopper_id_without_credit_card, sku_id=helper.TEST_PRODUCT_SKU_ID, amount_in_pence=100) self.assertEqual(e.exception.code, '15009') self.assertEqual( e.exception.description, 'Order creation failure, since no payment information was provided.' ) # With bogus credit card selection with self.assertRaises(exceptions.APIError) as e: order.create(shopper_id=self.shopper_id_without_credit_card, sku_id=helper.TEST_PRODUCT_SKU_ID, amount_in_pence=100, credit_card=self.credit_card_selection) self.assertEqual(e.exception.code, '10000') self.assertEqual( e.exception.description, 'The order failed because shopper payment details were incorrect or insufficient.' )