def setUp(self): self.contact_info = ContactInfo(first_name='John', last_name='Doe', email='*****@*****.**', zip_='SW5', country='gb', phone='07777777777') self.credit_card = PlainCreditCard( card_type=helper.DUMMY_CARD_VISA['card_type'], expiration_month=helper.DUMMY_CARD_VISA['expiration_month'], expiration_year=helper.DUMMY_CARD_VISA['expiration_year'], card_number=helper.DUMMY_CARD_VISA['card_number'], security_code=helper.DUMMY_CARD_VISA['security_code']) self.second_credit_card = PlainCreditCard( card_type=helper.DUMMY_CARD_MASTERCARD['card_type'], expiration_month=helper.DUMMY_CARD_MASTERCARD['expiration_month'], expiration_year=helper.DUMMY_CARD_MASTERCARD['expiration_year'], card_number=helper.DUMMY_CARD_MASTERCARD['card_number'], security_code=helper.DUMMY_CARD_MASTERCARD['security_code']) self.third_credit_card = PlainCreditCard( card_type=helper.DUMMY_CARD_AMEX['card_type'], expiration_month=helper.DUMMY_CARD_AMEX['expiration_month'], expiration_year=helper.DUMMY_CARD_AMEX['expiration_year'], card_number=helper.DUMMY_CARD_AMEX['card_number'], security_code=helper.DUMMY_CARD_AMEX['security_code'])
def setUp(self): self.contact_info = ContactInfo(first_name='John', last_name='Doe', email='*****@*****.**', zip_='SW5', country='gb', phone='07777777777') self.credit_card = PlainCreditCard( card_type=helper.DUMMY_CARD_VISA['card_type'], expiration_month=helper.DUMMY_CARD_VISA['expiration_month'], expiration_year=helper.DUMMY_CARD_VISA['expiration_year'], card_number=helper.DUMMY_CARD_VISA['card_number'], security_code=helper.DUMMY_CARD_VISA['security_code']) self.encrypted_credit_card = EncryptedCreditCard( card_type=helper.DUMMY_CARD_VISA['card_type'], expiration_month=helper.DUMMY_CARD_VISA['expiration_month'], expiration_year=helper.DUMMY_CARD_VISA['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_VISA['card_number'], encrypted_security_code=helper. DUMMY_CARD_VISA['encrypted_security_code']) self.credit_card_selection = CreditCardSelection( card_type=helper.DUMMY_CARD_VISA['card_type'], card_last_four_digits=helper.DUMMY_CARD_VISA['card_number'][-4:]) shopper = ShopperResource() self.shopper_id_with_one_credit_card = shopper.create( contact_info=self.contact_info, credit_card=self.credit_card) self.shopper_id_with_one_encrypted_credit_card = shopper.create( contact_info=self.contact_info, credit_card=self.encrypted_credit_card) self.shopper_id_without_credit_card = shopper.create( contact_info=self.contact_info) self.shopper_id_with_two_credit_cards = shopper.create( contact_info=self.contact_info, credit_card=self.credit_card) self.assertTrue( shopper.update( shopper_id=self.shopper_id_with_two_credit_cards, contact_info=self.contact_info, credit_card=PlainCreditCard( card_type=helper.DUMMY_CARD_MASTERCARD['card_type'], expiration_month=helper. DUMMY_CARD_MASTERCARD['expiration_month'], expiration_year=helper. DUMMY_CARD_MASTERCARD['expiration_year'], card_number=helper.DUMMY_CARD_MASTERCARD['card_number'], security_code=helper.DUMMY_CARD_MASTERCARD['security_code'] ))) self.shopper_id_with_two_encrypted_credit_cards = shopper.create( contact_info=self.contact_info, credit_card=self.encrypted_credit_card) self.assertTrue( shopper.update( shopper_id=self.shopper_id_with_two_encrypted_credit_cards, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper.DUMMY_CARD_MASTERCARD['card_type'], expiration_month=helper. DUMMY_CARD_MASTERCARD['expiration_month'], expiration_year=helper. DUMMY_CARD_MASTERCARD['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_MASTERCARD['card_number'], encrypted_security_code=helper. DUMMY_CARD_MASTERCARD['encrypted_security_code'])))
def test_add_invalid_credit_card(self): # Create a shopper, ensuring no credit card info was added shopper = ShopperResource() shopper_id = shopper.create(contact_info=self.contact_info) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsNone( shopper_obj['shopper-info']['payment-info']['credit-cards-info']) # Add expired card with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=PlainCreditCard( card_type=helper.DUMMY_CARD_VISA__EXPIRED['card_type'], expiration_month=helper. DUMMY_CARD_VISA__EXPIRED['expiration_month'], expiration_year=helper. DUMMY_CARD_VISA__EXPIRED['expiration_year'], card_number=helper.DUMMY_CARD_VISA__EXPIRED['card_number'], security_code=helper. DUMMY_CARD_VISA__EXPIRED['security_code'])) self.assertEqual(e.exception.code, '430306-14002') self.assertEqual( e.exception.description, 'The expiration date entered is invalid. Enter valid expiration date or try another card' ) self.assertEqual( e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430306 ' '- The expiration date entered is invalid. Enter valid expiration date or try another card' ) # Add card with insufficient funds with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=PlainCreditCard( card_type=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['card_type'], expiration_month=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['expiration_month'], expiration_year=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['expiration_year'], card_number=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['card_number'], security_code=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['security_code'])) self.assertEqual(e.exception.code, '430360-14002') self.assertEqual( e.exception.description, 'Insufficient funds. Please use another card or contact your bank for assistance' ) self.assertEqual( e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430360 ' '- Insufficient funds. Please use another card or contact your bank for assistance' ) # Add card with invalid number with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=PlainCreditCard( card_type=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER['card_type'], expiration_month=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER['expiration_month'], expiration_year=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER['expiration_year'], card_number=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER['card_number'], security_code=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER['security_code'])) self.assertEqual(e.exception.code, '430330-14002') self.assertEqual( e.exception.description, 'Invalid card number. Please check the number and try again, or use a different card' ) self.assertEqual( e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430330 ' '- Invalid card number. Please check the number and try again, or use a different card' ) # Add card with invalid number with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=PlainCreditCard( card_type=helper.DUMMY_CARD_AMEX__AUTH_FAIL['card_type'], expiration_month=helper. DUMMY_CARD_AMEX__AUTH_FAIL['expiration_month'], expiration_year=helper. DUMMY_CARD_AMEX__AUTH_FAIL['expiration_year'], card_number=helper. DUMMY_CARD_AMEX__AUTH_FAIL['card_number'], security_code=helper. DUMMY_CARD_AMEX__AUTH_FAIL['security_code'])) self.assertEqual(e.exception.code, '430285-14002') self.assertEqual( e.exception.description, 'Authorization has failed for this transaction. ' 'Please try again or contact your bank for assistance')