예제 #1
0
    def test_update_fails_with_invalid_shopper_id(self):
        shopper_id = '1'
        error_msg = 'User: %s is not authorized to update shopper: %s.' % (
            client.default().username, shopper_id)

        responses.add(responses.PUT,
                      '%s/services/2/shoppers/%s' %
                      (client.default().endpoint_url, shopper_id),
                      status=403,
                      content_type='application/xml',
                      body=error_msg)

        shopper = ShopperResource()

        with self.assertRaises(exceptions.APIError) as cm:
            shopper.update(shopper_id, contact_info=self.contact_info)
        self.assertEqual(cm.exception.status_code, 403)
        self.assertEqual(cm.exception.description, error_msg)
예제 #2
0
    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'])))
예제 #3
0
    def test_add_invalid_encrypted_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=EncryptedCreditCard(
                    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'],
                    encrypted_card_number='encrypted_%s' %
                    helper.DUMMY_CARD_VISA__EXPIRED['card_number'],
                    encrypted_security_code=helper.
                    DUMMY_CARD_VISA__EXPIRED['encrypted_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=EncryptedCreditCard(
                    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'],
                    encrypted_card_number='encrypted_%s' %
                    helper.DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['card_number'],
                    encrypted_security_code=helper.
                    DUMMY_CARD_VISA__INSUFFICIENT_FUNDS[
                        'encrypted_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=EncryptedCreditCard(
                    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'],
                    encrypted_card_number='encrypted_%s' %
                    helper.DUMMY_CARD_VISA__INVALID_CARD_NUMBER['card_number'],
                    encrypted_security_code=helper.
                    DUMMY_CARD_VISA__INVALID_CARD_NUMBER[
                        'encrypted_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=EncryptedCreditCard(
                    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'],
                    encrypted_card_number='encrypted_%s' %
                    helper.DUMMY_CARD_AMEX__AUTH_FAIL['card_number'],
                    encrypted_security_code=helper.
                    DUMMY_CARD_AMEX__AUTH_FAIL['encrypted_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')
예제 #4
0
    def test_add_encrypted_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 first credit card
        update_successful = shopper.update(
            shopper_id=shopper_id,
            contact_info=self.contact_info,
            credit_card=self.encrypted_credit_card)
        self.assertTrue(update_successful)

        shopper_obj = shopper.find_by_shopper_id(shopper_id)
        credit_card_info = shopper_obj['shopper-info']['payment-info'][
            'credit-cards-info']['credit-card-info']
        self.assertIsInstance(credit_card_info['credit-card'], dict)
        # Since credit_card and encrypted_credit_card are the same I can get the last 4 digits from the non encrypted
        self.assertEqual(
            credit_card_info['credit-card']['card-last-four-digits'],
            self.credit_card.card_number[-4:])
        self.assertEqual(credit_card_info['credit-card']['card-type'],
                         self.encrypted_credit_card.card_type)

        # Add second credit card
        update_successful = shopper.update(
            shopper_id=shopper_id,
            contact_info=self.contact_info,
            credit_card=self.encrypted_second_credit_card)
        self.assertTrue(update_successful)

        shopper_obj = shopper.find_by_shopper_id(shopper_id)
        credit_cards_info = shopper_obj['shopper-info']['payment-info'][
            'credit-cards-info']['credit-card-info']
        self.assertIsInstance(credit_cards_info, list)
        self.assertEqual(len(credit_cards_info), 2)

        # The order of the credit cards is not known, so we sort the items before comparing.
        cards = [dict(c['credit-card']) for c in credit_cards_info]
        self.assertEqual(
            cards,
            [{
                'card-last-four-digits': self.credit_card.card_number[-4:],
                'card-type': self.encrypted_credit_card.card_type
            }, {
                'card-last-four-digits':
                self.second_credit_card.card_number[-4:],
                'card-type': self.encrypted_second_credit_card.card_type
            }])

        # Add third credit card
        update_successful = shopper.update(
            shopper_id=shopper_id,
            contact_info=self.contact_info,
            credit_card=self.encrypted_third_credit_card)
        self.assertTrue(update_successful)

        shopper_obj = shopper.find_by_shopper_id(shopper_id)
        credit_cards_info = shopper_obj['shopper-info']['payment-info'][
            'credit-cards-info']['credit-card-info']
        self.assertIsInstance(credit_cards_info, list)
        self.assertEqual(len(credit_cards_info), 3)

        # Last added credit card displays first
        cards = [dict(c['credit-card']) for c in credit_cards_info]
        self.assertEqual(
            cards,
            [{
                'card-last-four-digits': self.credit_card.card_number[-4:],
                'card-type': self.encrypted_credit_card.card_type
            }, {
                'card-last-four-digits':
                self.second_credit_card.card_number[-4:],
                'card-type': self.encrypted_second_credit_card.card_type
            }, {
                'card-last-four-digits':
                self.third_credit_card.card_number[-4:],
                'card-type': self.encrypted_third_credit_card.card_type
            }])