Пример #1
0
    def test_request_apple_pay_authorization_rejected(self):
        """ The method should raise GatewayError if CyberSource rejects the payment. """
        self.mock_cybersource_wsdl()
        self.mock_authorization_response(accepted=False)

        basket = create_basket(site=self.site, owner=self.create_user())

        billing_address = factories.BillingAddressFactory()
        payment_token = {
            'paymentData': {
                'version': 'EC_v1',
                'data': 'fake-data',
                'signature': 'fake-signature',
                'header': {
                    'ephemeralPublicKey': 'fake-key',
                    'publicKeyHash': 'fake-hash',
                    'transactionId': 'abc123'
                }
            },
            'paymentMethod': {
                'displayName': 'AmEx 1086',
                'network': 'AmEx',
                'type': 'credit'
            },
            'transactionIdentifier': 'DEADBEEF'
        }

        with self.assertRaises(GatewayError):
            self.processor.request_apple_pay_authorization(
                basket, billing_address, payment_token)
Пример #2
0
    def test_multiple_payment_events(self):
        basket = factories.create_basket(empty=True)
        user = factories.UserFactory()
        add_product(basket, D('100.00'))
        order_placement = OrderPlacementMixin()
        order_placement.add_payment_event('Gift Card Payment', D('10'))
        order_placement.add_payment_event('Credit Card Payment', D('90'))
        shipping_method = Free()
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        billing_address = factories.BillingAddressFactory()
        shipping_address = factories.ShippingAddressFactory()
        order_submission_data = {
            'user': user,
            'order_number': '12345',
            'basket': basket,
            'shipping_method': shipping_method,
            'shipping_charge': shipping_charge,
            'order_total': order_total,
            'billing_address': billing_address,
            'shipping_address': shipping_address
        }
        order_placement.place_order(**order_submission_data)
        order1 = Order.objects.get(number='12345')
        self.assertEqual(order1.payment_events.count(), 2)
        event1 = order1.payment_events.all()[0]
        event2 = order1.payment_events.all()[1]
        self.assertEqual(event1.event_type.name, 'Credit Card Payment')
        self.assertEqual(event1.amount, D('90'))
        self.assertEqual(event1.lines.count(), 1)
        self.assertEqual(event2.event_type.name, 'Gift Card Payment')
        self.assertEqual(event2.amount, D('10'))
        self.assertEqual(event2.lines.count(), 1)
Пример #3
0
    def test_request_apple_pay_authorization(self):
        """ The method should authorize and settle an Apple Pay payment with CyberSource. """
        basket = create_basket(owner=self.create_user(), site=self.site)

        billing_address = factories.BillingAddressFactory()
        payment_token = {
            'paymentData': {
                'version': 'EC_v1',
                'data': 'fake-data',
                'signature': 'fake-signature',
                'header': {
                    'ephemeralPublicKey': 'fake-key',
                    'publicKeyHash': 'fake-hash',
                    'transactionId': 'abc123'
                }
            },
            'paymentMethod': {
                'displayName': 'AmEx 1086',
                'network': 'AmEx',
                'type': 'credit'
            },
            'transactionIdentifier': 'DEADBEEF'
        }

        self.mock_cybersource_wsdl()
        self.mock_authorization_response(accepted=True)

        actual = self.processor.request_apple_pay_authorization(
            basket, billing_address, payment_token)
        self.assertEqual(actual.total, basket.total_incl_tax)
        self.assertEqual(actual.currency, basket.currency)
        self.assertEqual(actual.card_number, 'Apple Pay')
        self.assertEqual(actual.card_type, 'american_express')
Пример #4
0
    def create_order_with_billing_address(self):
        """ Creates an order object with a bit of extra information for HubSpot unit tests"""
        enrollment_code = Product.objects.get(
            product_class__name=ENROLLMENT_CODE_PRODUCT_CLASS_NAME)
        user = UserFactory()
        basket = factories.BasketFactory(owner=user, site=self.site)
        basket.add_product(enrollment_code, self.QUANTITY)

        # add organization and purchaser attributes manually to the basket for testing purposes
        basket_data = {
            'organization': 'Dummy Business Client',
            PURCHASER_BEHALF_ATTRIBUTE: 'True'
        }
        basket_add_organization_attribute(basket, basket_data)

        # add some additional data the billing address to exercise some of the code paths in the unit we are testing
        billing_address = factories.BillingAddressFactory()
        billing_address.line2 = 'Suite 321'
        billing_address.line4 = "City"
        billing_address.state = "State"
        billing_address.country.name = "United States of America"

        # create new order adding in the additional billing address info
        return create_order(number=2,
                            basket=basket,
                            user=user,
                            billing_address=billing_address)
Пример #5
0
    def test_multi_site(self):
        basket = factories.create_basket(empty=True)
        site1 = factories.SiteFactory()
        site2 = factories.SiteFactory()
        request = HttpRequest()
        request.META['SERVER_PORT'] = 80
        request.META['SERVER_NAME'] = site1.domain
        user = factories.UserFactory()
        add_product(basket, D('12.00'))
        shipping_method = Free()
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        billing_address = factories.BillingAddressFactory()
        shipping_address = factories.ShippingAddressFactory()
        order_submission_data = {'user': user,
                                 'order_number': '12345',
                                 'basket': basket,
                                 'shipping_method': shipping_method,
                                 'shipping_charge': shipping_charge,
                                 'order_total': order_total,
                                 'billing_address': billing_address,
                                 'shipping_address': shipping_address,
                                 'request': request}
        OrderPlacementMixin().place_order(**order_submission_data)
        order1 = Order.objects.get(number='12345')
        self.assertEqual(order1.site, site1)

        add_product(basket, D('12.00'))
        request.META['SERVER_NAME'] = site2.domain
        order_submission_data['order_number'] = '12346'
        order_submission_data['request'] = request
        OrderPlacementMixin().place_order(**order_submission_data)
        order2 = Order.objects.get(number='12346')
        self.assertEqual(order2.site, site2)
Пример #6
0
 def make_billing_address(self, overrides=None):
     """
     Create a billing address for Cybersource tests with minimal required
     fields defined.
     """
     kwargs = {
         'first_name': 'TestForename',
         'last_name': 'TestSurname',
         'line1': 'TestLine1',
         'line2': '',  # this is not required by Cybersource, so make it empty unless the caller overrides it.
         'line4': 'TestLine4',
         'postcode': 'TestPostCode',
         'country': factories.CountryFactory(),
     }
     kwargs.update(overrides or {})
     return factories.BillingAddressFactory(**kwargs)
Пример #7
0
    def generate_post_data(self):
        address = factories.BillingAddressFactory()

        return {
            'billingContact': {
                'addressLines': [
                    address.line1,
                    address.line1
                ],
                'administrativeArea': address.state,
                'country': address.country.printable_name,
                'countryCode': address.country.iso_3166_1_a2,
                'familyName': self.user.last_name,
                'givenName': self.user.first_name,
                'locality': address.line4,
                'postalCode': address.postcode,
            },
            'shippingContact': {
                'emailAddress': self.user.email,
                'familyName': self.user.last_name,
                'givenName': self.user.first_name,
            },
            'token': {
                'paymentData': {
                    'version': 'EC_v1',
                    'data': 'fake-data',
                    'signature': 'fake-signature',
                    'header': {
                        'ephemeralPublicKey': 'fake-key',
                        'publicKeyHash': 'fake-hash',
                        'transactionId': 'abc123'
                    }
                },
                'paymentMethod': {
                    'displayName': 'AmEx 1086',
                    'network': 'AmEx',
                    'type': 'credit'
                },
                'transactionIdentifier': 'DEADBEEF'
            }
        }
Пример #8
0
    def test_update_address_book(self):
        basket = factories.create_basket(empty=True)
        user = factories.UserFactory()
        add_product(basket, D('12.00'))
        shipping_method = FixedPrice(D('5.00'), D('5.00'))

        billing_address = factories.BillingAddressFactory(
            line1='1 Boardwalk Place',
            line2='Trafalgar Way',
            line3='Tower Hamlets',
            line4='London')
        shipping_address = factories.ShippingAddressFactory(
            line1='Knightsbridge', line2='159', line4='London')
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        order_submission_data = {
            'user': user,
            'order_number': '12345',
            'basket': basket,
            'shipping_address': shipping_address,
            'shipping_method': shipping_method,
            'shipping_charge': shipping_charge,
            'billing_address': billing_address,
            'order_total': order_total
        }
        OrderPlacementMixin().place_order(**order_submission_data)

        self.assertEqual(
            user.addresses.filter(
                hash=billing_address.generate_hash()).count(), 1)
        self.assertEqual(
            user.addresses.filter(
                hash=shipping_address.generate_hash()).count(), 1)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 1)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         1)

        order_submission_data['order_number'] = '12346'

        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 2)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         2)

        order_submission_data.pop('billing_address', None)
        order_submission_data['order_number'] = '123457'
        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 2)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         3)

        shipping_address.line2 = '160'
        order_submission_data['billing_address'] = billing_address
        order_submission_data['order_number'] = '123458'
        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 3)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         1)