示例#1
0
    def test_create_payment_profile(self, PaymentProfile, CreateRequest):
        payment_profile = Mock()
        PaymentProfile.return_value = payment_profile
        _request = Mock()
        _request.make_request.return_value = self.payment_profile_id
        CreateRequest.return_value = _request

        # Scenario: call is successful, no validationMode is passed
        return_value = create_payment_profile(self.customer_id, 'address',
                                              'credit_card')
        PaymentProfile.assert_called_once_with(billTo='address',
                                               card='credit_card')
        CreateRequest.assert_called_once_with(customerProfileId=self.customer_id,
                                              paymentProfile=payment_profile,
                                              validationMode=None)
        self.assertTrue(_request.make_request.called)
        self.assertEqual(return_value, self.payment_profile_id)

        # Scenario: call is successful, validationMode is passed
        create_payment_profile(self.customer_id, 'address', 'credit_card',
                               'liveMode')
        CreateRequest.assert_called_with(customerProfileId=self.customer_id,
                                         paymentProfile=payment_profile,
                                         validationMode='liveMode')

        # Scenario: call raises AuthorizeNetException
        _request.make_request.side_effect = AuthorizeNetException('')
        self.assertRaises(AuthorizeNetException, create_payment_profile,
                          self.customer_id, 'address', 'credit_card')
示例#2
0
    def test_create_payment_profile(self, PaymentProfile, CreateRequest):
        payment_profile = Mock()
        PaymentProfile.return_value = payment_profile
        _request = Mock()
        _request.make_request.return_value = self.payment_profile_id
        CreateRequest.return_value = _request

        # Scenario: call is successful, no validationMode is passed
        return_value = create_payment_profile(self.customer_id, 'address',
                                              'credit_card')
        PaymentProfile.assert_called_once_with(billTo='address',
                                               card='credit_card')
        CreateRequest.assert_called_once_with(
            customerProfileId=self.customer_id,
            paymentProfile=payment_profile,
            validationMode=None)
        self.assertTrue(_request.make_request.called)
        self.assertEqual(return_value, self.payment_profile_id)

        # Scenario: call is successful, validationMode is passed
        create_payment_profile(self.customer_id, 'address', 'credit_card',
                               'liveMode')
        CreateRequest.assert_called_with(customerProfileId=self.customer_id,
                                         paymentProfile=payment_profile,
                                         validationMode='liveMode')

        # Scenario: call raises AuthorizeNetException
        _request.make_request.side_effect = AuthorizeNetException('')
        self.assertRaises(AuthorizeNetException, create_payment_profile,
                          self.customer_id, 'address', 'credit_card')
示例#3
0
def add_payment_method(user, address, credit_card, validate=False):
    profile_id = CustomerID.get_id(user._id)
    payment_method_id = api.create_payment_profile(profile_id, address, credit_card, validate)

    if payment_method_id:
        PayID.add(user, payment_method_id)
        return payment_method_id
示例#4
0
def add_payment_method(user, address, credit_card, validate=False):
    profile_id = CustomerID.get_id(user._id)
    payment_method_id = api.create_payment_profile(profile_id, address,
                                                   credit_card, validate)

    if payment_method_id:
        PayID.add(user, payment_method_id)
        return payment_method_id