def setUp(self): self.api = TransactionAPI('123', '456') self.success = lambda *args, **kwargs: SUCCESS.reset() or SUCCESS self.error = lambda *args, **kwargs: ERROR.reset() or ERROR self.year = date.today().year + 10 self.credit_card = CreditCard('4111111111111111', self.year, 1, '911') self.address = Address('45 Rose Ave', 'Venice', 'CA', '90291')
def retrieve_saved_payment(self, profile_id, payment_id): payment_id = int(payment_id) profile = self._make_call( 'GetCustomerProfile', profile_id).profile payment_info = {} email = None if hasattr(profile, 'email'): email = str(profile.email) payment_info['email'] = email saved_payment = None for payment in profile.paymentProfiles[0]: if payment.customerPaymentProfileId == payment_id: saved_payment = payment break if not saved_payment: raise AuthorizeError("Payment ID does not exist for this profile.") payment_info['number'] = str( saved_payment.payment.creditCard.cardNumber) data = saved_payment.billTo payment_info['first_name'] = str(getattr(data, 'firstName', '')) payment_info['last_name'] = str(getattr(data, 'lastName', '')) kwargs = { 'street': getattr(data, 'address', None), 'city': getattr(data, 'city', None), 'state': getattr(data, 'state', None), 'zip_code': getattr(data, 'zip', None), 'country': getattr(data, 'country', None)} kwargs = {key: str(value) for key, value in kwargs.items() if value} payment_info['address'] = Address(**kwargs) return payment_info
def test_update_saved_payment(self): service_payment = self.api.client.service.UpdateCustomerPaymentProfile service_payment.return_value = SUCCESS service_customer = self.api.client.service.UpdateCustomerProfile service_customer.return_value = SUCCESS address = Address(street='45 Rose Ave', city='Venice', state='CA', zip_code='90291', country='US') kwargs = { 'first_name': 'Jeff', 'last_name': 'Schenck', 'address': address, 'email': '*****@*****.**', 'exp_month': '10', 'exp_year': int(date.today().year + 10), 'number': 'XXXX1111'} self.api.update_saved_payment( '123456', '123458', **kwargs) self.assertEqual(service_payment.call_args[0][1], '123456') profile_request = service_payment.call_args[0][2] self.assertEqual(profile_request.customerPaymentProfileId, '123458') self.assertEqual( profile_request.billTo.firstName, kwargs['first_name']) self.assertEqual( profile_request.billTo.lastName, kwargs['last_name']) self.assertEqual(profile_request.billTo.address, address.street) self.assertEqual(profile_request.billTo.state, address.state) self.assertEqual(profile_request.billTo.zip, address.zip_code) self.assertEqual( profile_request.payment.creditCard.cardNumber, 'XXXX1111') exp_date = '{0}-{1:0>2}'.format( kwargs['exp_year'], kwargs['exp_month']) self.assertEqual( profile_request.payment.creditCard.expirationDate, exp_date) customer_profile = service_customer.call_args[0][1] self.assertEqual(customer_profile.customerProfileId, '123456') self.assertEqual(customer_profile.email, kwargs['email'])
def test_create_saved_payment(self): service = self.api.client.service.CreateCustomerPaymentProfile service.return_value = SUCCESS year = date.today().year + 10 credit_card = CreditCard('4111111111111111', year, 1, '911', 'Jeff', 'Schenck') address = Address('45 Rose Ave', 'Venice', 'CA', '90291') # Without profile id should return object payment_profile = self.api.create_saved_payment(credit_card, address) self.assertEqual(service.call_args, None) self.assertEqual(payment_profile.__class__.__name__, 'customerPaymentProfileType') self.assertEqual(payment_profile.payment.__class__.__name__, 'paymentType') self.assertEqual(payment_profile.payment.creditCard.__class__.__name__, 'creditCardType') self.assertEqual(payment_profile.payment.creditCard.cardNumber, '4111111111111111') self.assertEqual(payment_profile.payment.creditCard.expirationDate, '{0}-01'.format(year)) self.assertEqual(payment_profile.payment.creditCard.cardCode, '911') self.assertEqual(payment_profile.billTo.firstName, 'Jeff') self.assertEqual(payment_profile.billTo.lastName, 'Schenck') self.assertEqual(payment_profile.billTo.address, '45 Rose Ave') self.assertEqual(payment_profile.billTo.city, 'Venice') self.assertEqual(payment_profile.billTo.state, 'CA') self.assertEqual(payment_profile.billTo.zip, '90291') self.assertEqual(payment_profile.billTo.country, 'US') # With profile id should make call to API payment_profile_id = self.api.create_saved_payment(credit_card, profile_id='1') self.assertEqual(payment_profile_id, '123458') self.assertEqual(service.call_args[0][1], '1') payment_profile = service.call_args[0][2] self.assertEqual(payment_profile._kind, 'CustomerPaymentProfileType') self.assertEqual(payment_profile.payment._kind, 'PaymentType') self.assertEqual(payment_profile.payment.creditCard._kind, 'CreditCardType') self.assertEqual(payment_profile.payment.creditCard.cardNumber, '4111111111111111') self.assertEqual(payment_profile.payment.creditCard.expirationDate, '{0}-01'.format(year)) self.assertEqual(payment_profile.payment.creditCard.cardCode, '911') self.assertEqual(payment_profile.billTo.firstName, 'Jeff') self.assertEqual(payment_profile.billTo.lastName, 'Schenck') self.assertNotEqual(payment_profile.billTo.address, '45 Rose Ave') self.assertNotEqual(payment_profile.billTo.city, 'Venice') self.assertNotEqual(payment_profile.billTo.state, 'CA') self.assertNotEqual(payment_profile.billTo.zip, '90291') self.assertNotEqual(payment_profile.billTo.country, 'US')
def test_retrieve_saved_payment(self): service = self.api.client.service.GetCustomerProfile service.return_value = PROFILE_RESPONSE address = Address(street='45 Rose Ave', city='Venice', state='CA', zip_code='90291', country='USA') payment = self.api.retrieve_saved_payment('123456', '123458') self.assertEqual(payment['first_name'], 'Jeff') self.assertEqual(payment['last_name'], 'Schenck') self.assertEqual(payment['address'].street, address.street) self.assertEqual(payment['address'].city, address.city) self.assertEqual(payment['address'].state, address.state) self.assertEqual(payment['address'].zip_code, address.zip_code) self.assertEqual(payment['number'], 'XXXX1111') self.assertEqual(payment['email'], '*****@*****.**')
def get_card(card_num, cvn, exp_month, exp_year, fname, lname, street, city, state, zipcode, authorize_id, authorize_key, country='USA'): client = get_client(authorize_id, authorize_key) address = Address(street, city, state, zipcode, country) card = CreditCard(card_num, exp_year, exp_month, cvn, fname, lname) return AuthorizeCreditCard(client, card, address=address)
def test_basic_address(self): address = Address('45 Rose Ave', 'Venice', 'CA', '90291') repr(address)