Beispiel #1
0
    def test_create_customer_profile(self, Profile, CreateRequest):
        merchant_customer_id = 99
        description = 'some description'

        # Set up profile mock
        profile = Mock()
        Profile.return_value = profile
        # Set up request mock
        _request = MagicMock()
        _request.make_request.return_value = self.customer_id
        CreateRequest.return_value = _request

        # Scenario: successful call
        return_value = create_customer_profile(merchant_customer_id,
                                               description)
        Profile.assert_called_once_with(description=description,
                                        merchantCustomerId=merchant_customer_id,
                                        paymentProfiles=None,
                                        customerProfileId=None)
        CreateRequest.assert_called_once_with(profile=profile)
        self.assertTrue(_request.make_request.called)
        self.assertEqual(return_value, self.customer_id)

        # Scenario: call raises AuthorizeNetException
        _request.make_request.side_effect = AuthorizeNetException('')
        return_value = create_customer_profile(merchant_customer_id,
                                               description)
        self.assertEqual(return_value, None)
Beispiel #2
0
    def test_create_customer_profile(self, Profile, CreateRequest):
        merchant_customer_id = 99
        description = 'some description'

        # Set up profile mock
        profile = Mock()
        Profile.return_value = profile
        # Set up request mock
        _request = MagicMock()
        _request.make_request.return_value = self.customer_id
        CreateRequest.return_value = _request

        # Scenario: successful call
        return_value = create_customer_profile(merchant_customer_id,
                                               description)
        Profile.assert_called_once_with(
            description=description,
            merchantCustomerId=merchant_customer_id,
            paymentProfiles=None,
            customerProfileId=None)
        CreateRequest.assert_called_once_with(profile=profile)
        self.assertTrue(_request.make_request.called)
        self.assertEqual(return_value, self.customer_id)

        # Scenario: call raises AuthorizeNetException
        _request.make_request.side_effect = AuthorizeNetException('')
        return_value = create_customer_profile(merchant_customer_id,
                                               description)
        self.assertEqual(return_value, None)
Beispiel #3
0
def get_or_create_customer_profile(user):
    profile_id = CustomerID.get_id(user._id)
    if not profile_id:
        profile_id = api.create_customer_profile(merchant_customer_id=user._fullname, description=user.name)
        CustomerID.set(user, profile_id)

    profile = api.get_customer_profile(profile_id)

    if not profile or profile.merchantCustomerId != user._fullname:
        raise ValueError("error getting customer profile")

    for payment_profile in profile.paymentProfiles:
        PayID.add(user, payment_profile.customerPaymentProfileId)

    return profile
Beispiel #4
0
def get_or_create_customer_profile(user):
    profile_id = CustomerID.get_id(user._id)
    if not profile_id:
        profile_id = api.create_customer_profile(
            merchant_customer_id=user._fullname, description=user.name)
        CustomerID.set(user, profile_id)

    profile = api.get_customer_profile(profile_id)

    if not profile or profile.merchantCustomerId != user._fullname:
        raise ValueError("error getting customer profile")

    for payment_profile in profile.paymentProfiles:
        PayID.add(user, payment_profile.customerPaymentProfileId)

    return profile