def test_add_with_token(self):
        token_service = HpsTokenService(
            TestServicesConfig.valid_pay_plan_config.public_key)

        card = HpsCreditCard()
        card.number = 4111111111111111
        card.exp_month = '12'
        card.exp_year = '2020'
        card.cvv = '123'

        token = token_service.get_token(card)
        if token.token_value is None:
            self.fail("cannot generate token")

        payment_method = HpsPayPlanPaymentMethod()
        payment_method.customer_key = self.customer.customer_key
        payment_method.payment_method_type = HpsPayPlanPaymentMethodType.CREDIT_CARD
        payment_method.name_on_account = 'Bill Johnson'
        payment_method.payment_token = token.token_value
        payment_method.expiration_date = '0120'
        payment_method.country = 'USA'

        response = self.service.add_payment_method(payment_method)
        self.assertIsNotNone(response)
        self.assertIsNotNone(response.payment_method_key)
    def _charge_valid_amex_token(self, amt):
        token_service = HpsTokenService(TestServicesConfig.valid_services_config.credential_token)
        token_response = token_service.get_token(TestCreditCard.valid_amex)

        response = self.charge_service.charge(
            amt, 'usd',
            token_response.token_value,
            TestCardHolder.valid_card_holder)
        if response is None:
            self.fail('Response is null.')

        return response
    def _get_token(self, card, key=None):
        if key is not None and key != '':
            self.public_key = key
        else:
            self.public_key = TestServicesConfig.valid_services_config.credential_token

        self.token_service = HpsTokenService(self.public_key)
        token_response = self.token_service.get_token(card)
        if token_response.token_value is not None:
            token = HpsTokenData()
            token.token_value = token_response.token_value
            return token
        else:
            return token_response
Exemple #4
0
    def test_recurring_with_token(self):
        if self.schedule is None:
            self.skipTest('Schedule was none')

        token_service = HpsTokenService(TestServicesConfig.valid_services_config.credential_token)
        token_response = token_service.get_token(TestCreditCard.valid_visa)
        self.assertIsNotNone(token_response)
        self.assertIsNotNone(token_response.token_value)

        recurring = self.service.recurring(10)\
            .with_schedule(self.schedule)\
            .with_token(token_response.token_value)\
            .with_card_holder(TestCardHolder.valid_card_holder)\
            .with_allow_duplicates(True)\
            .execute()

        self.assertIsNotNone(recurring)
        self.assertEqual('00', recurring.response_code)
 def test_bad_public_key(self):
     token = HpsTokenService('pkapi_foo_foo').get_token(TestCreditCard.valid_visa)
     self.assertIsNotNone(token)
 def test_malformed_public_key(self):
     with self.assertRaises(HpsArgumentException):
         HpsTokenService('pkapi_bad')
 def test_empty_public_key(self):
     with self.assertRaises(HpsArgumentException):
         HpsTokenService('')
 def test_null_public_key(self):
     with self.assertRaises(HpsArgumentException):
         HpsTokenService(None)
class TokenServiceTests(unittest.TestCase):
    token_service = HpsTokenService(TestServicesConfig.valid_services_config.credential_token)

    def test_null_public_key(self):
        with self.assertRaises(HpsArgumentException):
            HpsTokenService(None)

    def test_empty_public_key(self):
        with self.assertRaises(HpsArgumentException):
            HpsTokenService('')

    def test_malformed_public_key(self):
        with self.assertRaises(HpsArgumentException):
            HpsTokenService('pkapi_bad')

    def test_bad_public_key(self):
        token = HpsTokenService('pkapi_foo_foo').get_token(TestCreditCard.valid_visa)
        self.assertIsNotNone(token)

    def test_validation_invalid_card_number(self):
        card = HpsCreditCard()
        card.number = '1'

        response = self.token_service.get_token(card)
        error = response.error

        self.assertIsNotNone(error)
        self.assertEqual('2', error.code)
        self.assertEqual('card.number', error.param)
        self.assertEqual('Card number is invalid.', error.message)

    def test_validation_long_card_number(self):
        card = HpsCreditCard()
        card.number = '11111111111111111111111111111111111'

        response = self.token_service.get_token(card)
        error = response.error

        self.assertIsNotNone(error)
        self.assertEqual('2', error.code)
        self.assertEqual('card.number', error.param)
        self.assertEqual('Card number is invalid.', error.message)

    def test_validation_high_exp_month(self):
        card = copy.deepcopy(TestCreditCard.valid_visa)
        card.exp_month = 13

        response = self.token_service.get_token(card)
        error = response.error

        self.assertIsNotNone(error)
        self.assertEqual('2', error.code)
        self.assertEqual('card.exp_month', error.param)
        self.assertEqual('Card expiration month is invalid.', error.message)

    def test_validation_low_exp_year(self):
        card = copy.deepcopy(TestCreditCard.valid_visa)
        card.exp_year = 12

        response = self.token_service.get_token(card)
        error = response.error

        self.assertIsNotNone(error)
        self.assertEqual('2', error.code)
        self.assertEqual('card.exp_year', error.param)
        self.assertEqual('Card expiration year is invalid.', error.message)

    def test_validation_year_under_2000(self):
        card = copy.deepcopy(TestCreditCard.valid_visa)
        card.exp_year = 1999

        response = self.token_service.get_token(card)
        error = response.error

        self.assertIsNotNone(error)
        self.assertEqual('2', error.code)
        self.assertEqual('card.exp_year', error.param)
        self.assertEqual('Card expiration year is invalid.', error.message)

    def test_token_result(self):
        response = self.token_service.get_token(TestCreditCard.valid_visa)
        self.assertIsNone(response.error)

    def test_token_data_result(self):
        response = self.token_service.get_token(TestCreditCard.valid_visa)
        self.assertIsNotNone(response.token_value)
        self.assertIsNotNone(response.token_type)
        self.assertIsNotNone(response.token_expire)

    def test_token_charge(self):
        token = self.token_service.get_token(TestCreditCard.valid_visa)
        charge_service = HpsCreditService(TestServicesConfig.valid_services_config)
        charge = charge_service.charge(4, 'USD', token.token_value, TestCardHolder.valid_card_holder)

        self.assertIsNotNone(charge)
        self.assertEqual('00', charge.response_code)

    def test_swipe_token(self):
        swipe_data = '.11%B4012001000000016^VI TEST CREDIT^251210100000000000000000?|mc7vPHGGYh79DuD2Ys0ELhubZcP7dIsNaxQlRF243dIX5kfXEnQKaciND|+++++++JnvkN4mBa11;4012001000000016=25121010000000000000?|kON4LjKZ+tcDZcIef/W2H7oRDw|+++++++JnvkN4mBa00||/wECAQECAoFGAgEH3wEeShV78RZwb3NAc2VjdXJlZXhjaGFuZ2UubmV0TBtEt4SQvyC03zgmcS/4rnZdMpF+4mJT6EYuyDKC+WJAMG4+cSiWOGHtqwaK6edyzqosTPLavpdRat7z2dVX/SM3//TXLGGrSIayLW6Zmatbw4MT0KtBuyYaKX74E4v2L2PhItHv7m6rm2xGu2yTPmCvm9yFTouljvhF3Klx8rUAn0o0zCVAE9sl/iix+qqnTLEvgd/XXpaiYwyQoKSkkZGVX7QP'
        token = self.token_service.get_swipe_token(swipe_data)
        self.assertIsNotNone(token)

        charge_service = HpsCreditService(TestServicesConfig.valid_services_config)
        charge = charge_service.charge(3, 'USD', token.token_value, TestCardHolder.valid_card_holder)

        self.assertIsNotNone(charge)
        self.assertEqual('00', charge.response_code)

    def test_encrypted_card_token(self):
        track = '4012007060016=2512101hX3JZdqcwEOaoUry'
        ktb = '/wECAQEEAoFGAgEH3ggDTDT6jRZwb3NAc2VjdXJlZXhjaGFuZ2UubmV0MCtomwyCdnN+qr1I/SvhXbgOurdPKxkAyrmBQkzS/0UB6HWpdN1nc4IXcgB7tuVAs4fRjIlYOTIWNjf10bwciwD3m1JNoDMtvoXggaN7dLI7uuA+jYzt0gAmzgB3QqUFY0k7awOm923RJhnVaWUBJv9jL3+gvFNzZ+CiYbJH3BoArnCvWJbn/ohfnlJ6bA+GPC2fJlQkizQXbrRoF+pbcezCaY9W'
        token = self.token_service.get_track_token(track, '02', ktb)
        self.assertIsNotNone(token)

        charge_service = HpsCreditService(TestServicesConfig.valid_services_config)
        charge = charge_service.charge(2, 'USD', token.token_value, TestCardHolder.valid_card_holder)

        self.assertIsNotNone(charge)
        self.assertEqual('00', charge.response_code)