Example #1
0
 def store(self, credit_card, options=None):
     if isinstance(credit_card, CreditCard):
         if not self.validate_card(credit_card):
             raise InvalidCard("Invalid Card")
         payment_method = PaymentMethod.create(credit_card.number, 
                                                     credit_card.verification_value, 
                                                     credit_card.month, credit_card.year)
     else:
         # Using the token which has to be retained
         payment_method = PaymentMethod.find(credit_card)
         if payment_method.errors:
             transaction_was_unsuccessful.send(sender=self, 
                                               type="store",
                                               response=payment_method)
             return {'status': 'FAILURE', 'response': payment_method}
     response = payment_method.retain()
     if response.errors:
         transaction_was_unsuccessful.send(sender=self, 
                                           type="store",
                                           response=response)
         return {'status': 'FAILURE', 'response': response}
     transaction_was_successful.send(sender=self, 
                                     type="store",
                                     response=response)
     return {'status': 'SUCCESS', 'response': response}
Example #2
0
 def store(self, credit_card, options=None):
     if isinstance(credit_card, CreditCard):
         if not self.validate_card(credit_card):
             raise InvalidCard("Invalid Card")
         payment_method = PaymentMethod.create(
             credit_card.number, credit_card.verification_value,
             credit_card.month, credit_card.year)
     else:
         # Using the token which has to be retained
         payment_method = PaymentMethod.find(credit_card)
         if payment_method.errors:
             transaction_was_unsuccessful.send(sender=self,
                                               type="store",
                                               response=payment_method)
             return {'status': 'FAILURE', 'response': payment_method}
     response = payment_method.retain()
     if response.errors:
         transaction_was_unsuccessful.send(sender=self,
                                           type="store",
                                           response=response)
         return {'status': 'FAILURE', 'response': response}
     transaction_was_successful.send(sender=self,
                                     type="store",
                                     response=response)
     return {'status': 'SUCCESS', 'response': response}
 def test_find_should_be_successful(self):
     pm = PaymentMethod.create(**params)
     token = pm.payment_method_token
     pm = PaymentMethod.find(token)
     self.assertTrue(self.pm.is_sensitive_data_valid)
     self.assertTrue(self.pm.is_expiration_valid)
     self.assertEqual(self.pm.first_name, params['first_name'])
     self.assertEqual(self.pm.last_name, params['last_name'])
     self.assertEqual(self.pm.address_1, params['address_1'])
     self.assertEqual(self.pm.address_2, params['address_2'])
     self.assertEqual(self.pm.city, params['city'])
     self.assertEqual(self.pm.state, params['state'])
     self.assertEqual(self.pm.zip, params['zip'])
     self.assertEqual(self.pm.last_four_digits, params['card_number'][-4:])
     self.assertEqual(self.pm.expiry_month, int(params['expiry_month']))
     self.assertEqual(self.pm.expiry_year, int(params['expiry_year']))
def default_payment_method(options={}):
  data = {
      'card_number': '4111111111111111',
      'sandbox' : True,
      'redirect_url' : 'http://test.host',
      'merchant_key' : config.merchant_key,
      'custom' : 'custom',
      'first_name' : 'FirstName',
      'last_name' : 'LastName',
      'address_1' : '1000 1st Av',
      'address_2' : '',
      'city' : 'Chicago',
      'state' : 'IL',
      'zip' : '10101',
      'card_number' : '4111111111111111',
      'cvv' : '111',
      'expiry_month' : '05',
      'expiry_year' : '2014',
    }

  data.update(options)
  return PaymentMethod.create(data.pop('card_number'),
                              data.pop('cvv'),
                              data.pop('expiry_month'),
                              data.pop('expiry_year'),
                              **data)
Example #5
0
def default_payment_method(options={}):
  data = {
      'sandbox' : True,
      'redirect_url' : 'http://test.host',
      'merchant_key' : config.merchant_key,
      'custom' : 'custom',
      'first_name' : 'FirstName',
      'last_name' : 'LastName',
      'address_1' : '1000 1st Av',
      'address_2' : '',
      'city' : 'Chicago',
      'state' : 'IL',
      'zip' : '10101',
      'card_number' : '4111111111111111',
      'cvv' : '111',
      'expiry_month' : '05',
      'expiry_year' : '2014',
    }

  data.update(options)
  return PaymentMethod.create(data.pop('card_number'),
                              data.pop('cvv'),
                              data.pop('expiry_month'),
                              data.pop('expiry_year'),
                              **data)
 def test_find_should_be_successful(self):
   pm = PaymentMethod.create(**params)
   token = pm.payment_method_token
   pm = PaymentMethod.find(token)
   self.assertTrue(self.pm.is_sensitive_data_valid)
   self.assertTrue(self.pm.is_expiration_valid)
   self.assertEqual(self.pm.first_name, params['first_name'])
   self.assertEqual(self.pm.last_name, params['last_name'])
   self.assertEqual(self.pm.address_1, params['address_1'])
   self.assertEqual(self.pm.address_2, params['address_2'])
   self.assertEqual(self.pm.city, params['city'])
   self.assertEqual(self.pm.state, params['state'])
   self.assertEqual(self.pm.zip, params['zip'])
   self.assertEqual(self.pm.last_four_digits, params['card_number'][-4:])
   self.assertEqual(self.pm.expiry_month, int(params['expiry_month']))
   self.assertEqual(self.pm.expiry_year, int(params['expiry_year']))
Example #7
0
 def store(self, credit_card, options=None):
     from samurai.payment_method import PaymentMethod
     pm = PaymentMethod.create(credit_card.number,
                               credit_card.verification_value,
                               credit_card.month, credit_card.year)
     response = pm.retain()
     return {'status': 'SUCCESS', 'response': response}
Example #8
0
 def unstore(self, identification, options=None):
     payment_method = PaymentMethod.find(identification)
     if payment_method.errors:
         return {"status": "FAILURE", "response": payment_method}
     payment_method = payment_method.redact()
     if payment_method.errors:
         return {"status": "FAILURE", "response": payment_method}
     return {"status": "SUCCESS", "response": payment_method}
 def test_should_fail_on_blank_card_number(self):
     params_tmp = params
     params_tmp['card_number'] =  ''
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     err = {'context': 'input.card_number', 'key': 'is_blank', 'subclass': 'error'}
     self.assertIn(err, pm.error_messages)
     self.assertIn('The card number was blank.', pm.errors['input.card_number'])
 def test_should_return_failed_checksum_card_number(self):
     params_tmp = params
     params_tmp['card_number'] =  '4111-1111-1111-1234'
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     err = {'context': 'input.card_number', 'key': 'failed_checksum', 'subclass': 'error'}
     self.assertIn(err, pm.error_messages)
     self.assertIn('The card number was invalid.', pm.errors['input.card_number'])
 def test_should_return_too_long_cvv(self):
     params_tmp = params
     params_tmp['cvv'] = '1111111'
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     err = {'context': 'input.cvv', 'key': 'too_long', 'subclass': 'error'}
     self.assertIn(err, pm.error_messages)
     self.assertIn('The CVV was too long.', pm.errors['input.cvv'])
 def test_should_return_too_short_cvv(self):
     params_tmp = params
     params_tmp['cvv'] =  '1'
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     err = {'context': 'input.cvv', 'key': 'too_short', 'subclass': 'error'}
     self.assertIn(err, pm.error_messages)
     self.assertIn('The CVV was too short.', pm.errors['input.cvv'])
 def test_should_return_is_blank_expiry_month(self):
     params_tmp = params
     params_tmp['expiry_month'] =  ''
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     self.assertFalse(pm.is_expiration_valid)
     err = {'context': 'input.expiry_month', 'key': 'is_blank', 'subclass': 'error'}
     self.assertIn(err, pm.error_messages)
     self.assertIn('The expiration month was blank.', pm.errors['input.expiry_month'])
 def test_should_return_is_invalid_expiry_year(self):
     params_tmp = params
     params_tmp['expiry_year'] =  'abcd'
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     self.assertFalse(pm.is_expiration_valid)
     err = {'context': 'input.expiry_year', 'key': 'is_invalid', 'subclass': 'error'}
     self.assertIn(err, pm.error_messages)
     self.assertIn('The expiration year was invalid.', pm.errors['input.expiry_year'])
    def test_create_failure(self):
        pm = PaymentMethod.create('4343434343434343', '133', '07', '12')
        assert not pm.is_sensitive_data_valid

        errors = [{
            'context': 'input.card_number',
            'key': 'failed_checksum',
            'subclass': 'error'
        }]
        assert pm.errors == errors
 def test_find_should_fail_on_an_invalid_token(self):
     pm = PaymentMethod.find('abc123')
     err = "Couldn't find PaymentMethod with token = abc123"
     self.assertIn(
         {
             'context': 'system.general',
             'key': 'default',
             'subclass': 'error',
             'text': err
         }, pm.error_messages)
Example #17
0
 def authorize(self, money, credit_card, options=None):
     if not self.validate_card(credit_card):
         raise InvalidCard("Invalid Card")
     try:
         from samurai.payment_method import PaymentMethod
         from samurai.processor import Processor
         pm = PaymentMethod.create(credit_card.number, credit_card.verification_value, credit_card.month, credit_card.year)
         payment_method_token = pm.payment_method_token
         response = Processor.authorize(payment_method_token, money)
     except Exception, error:
         return {'status': 'FAILURE', 'response': error}
 def test_should_return_not_numeric_cvv(self):
     params_tmp = params
     params_tmp['cvv'] = 'abcd1'
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     err = {
         'context': 'input.cvv',
         'key': 'not_numeric',
         'subclass': 'error'
     }
     self.assertIn(err, pm.error_messages)
     self.assertIn('The CVV was invalid.', pm.errors['input.cvv'])
Example #19
0
 def authorize(self, money, credit_card, options=None):
     payment_method_token = credit_card
     if isinstance(credit_card, CreditCard):
         if not self.validate_card(credit_card):
             raise InvalidCard("Invalid Card")
         pm = PaymentMethod.create(credit_card.number, credit_card.verification_value, 
                                   credit_card.month, credit_card.year)
         payment_method_token = pm.payment_method_token
     response = Processor.authorize(payment_method_token, money)
     if response.errors:
         return {'status': 'FAILURE', 'response': response}
     return {'status': 'SUCCESS', 'response': response}
 def test_should_return_too_short_card_number(self):
     params_tmp = params
     params_tmp['card_number'] = '4111-1'
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     err = {
         'context': 'input.card_number',
         'key': 'too_short',
         'subclass': 'error'
     }
     self.assertIn(err, pm.error_messages)
     self.assertIn('The card number was too short.',
                   pm.errors['input.card_number'])
 def test_should_fail_on_blank_card_number(self):
     params_tmp = params
     params_tmp['card_number'] = ''
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     err = {
         'context': 'input.card_number',
         'key': 'is_blank',
         'subclass': 'error'
     }
     self.assertIn(err, pm.error_messages)
     self.assertIn('The card number was blank.',
                   pm.errors['input.card_number'])
Example #22
0
 def purchase(self, money, credit_card):
     # Cases where token is directly sent for e.g. from Samurai.js
     payment_method_token = credit_card
     if isinstance(credit_card, CreditCard):
         if not self.validate_card(credit_card):
             raise InvalidCard("Invalid Card")
         pm = PaymentMethod.create(credit_card.number, credit_card.verification_value,
                                   credit_card.month, credit_card.year)
         payment_method_token = pm.payment_method_token
     response = Processor.purchase(payment_method_token, money)
     if response.errors:
         return {'status': 'FAILURE', 'response': response}
     return {'status': 'SUCCESS', 'response': response}
Example #23
0
 def authorize(self, money, credit_card, options=None):
     if not self.validate_card(credit_card):
         raise InvalidCard("Invalid Card")
     try:
         from samurai.payment_method import PaymentMethod
         from samurai.processor import Processor
         pm = PaymentMethod.create(credit_card.number,
                                   credit_card.verification_value,
                                   credit_card.month, credit_card.year)
         payment_method_token = pm.payment_method_token
         response = Processor.authorize(payment_method_token, money)
     except Exception, error:
         return {'status': 'FAILURE', 'response': error}
 def test_should_return_is_invalid_expiry_year(self):
     params_tmp = params
     params_tmp['expiry_year'] = 'abcd'
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     self.assertFalse(pm.is_expiration_valid)
     err = {
         'context': 'input.expiry_year',
         'key': 'is_invalid',
         'subclass': 'error'
     }
     self.assertIn(err, pm.error_messages)
     self.assertIn('The expiration year was invalid.',
                   pm.errors['input.expiry_year'])
 def test_should_return_is_blank_expiry_month(self):
     params_tmp = params
     params_tmp['expiry_month'] = ''
     pm = PaymentMethod.create(**params_tmp)
     self.assertFalse(pm.is_sensitive_data_valid)
     self.assertFalse(pm.is_expiration_valid)
     err = {
         'context': 'input.expiry_month',
         'key': 'is_blank',
         'subclass': 'error'
     }
     self.assertIn(err, pm.error_messages)
     self.assertIn('The expiration month was blank.',
                   pm.errors['input.expiry_month'])
Example #26
0
def default_payment_method(options={}):
    data = {
        'card_number': '4111111111111111',
        'cvv': '111',
        'expiry_month': '07',
        'expiry_year': '14',
        'first_name': 'first_name',
        'last_name': 'last_name',
        'sandbox': True
    }
    data.update(options)
    return PaymentMethod.create(data.pop('card_number'), data.pop('cvv'),
                                data.pop('expiry_month'),
                                data.pop('expiry_year'), **data)
def default_payment_method(options={}):
  data = {
      'card_number': '4111111111111111',
      'cvv': '111',
      'expiry_month': '07',
      'expiry_year': '14',
      'first_name': 'first_name',
      'last_name': 'last_name',
      'sandbox': True
  }
  data.update(options)
  return PaymentMethod.create(data.pop('card_number'),
                              data.pop('cvv'),
                              data.pop('expiry_month'),
                              data.pop('expiry_year'),
                              **data)
 def test_update_should_be_successful_preserving_sensitive_data(self):
     params_tmp = paramsx
     params_tmp['card_number'] = '****************'
     params_tmp['cvv'] = '***'
     pm = PaymentMethod.create(**params)
     pm = pm.update(**paramsx)
     self.assertTrue(pm.is_expiration_valid)
     self.assertEqual(pm.first_name, params_tmp['first_name'])
     self.assertEqual(pm.last_name, params_tmp['last_name'])
     self.assertEqual(pm.address_1, params_tmp['address_1'])
     self.assertEqual(pm.address_2, params_tmp['address_2'])
     self.assertEqual(pm.city, params_tmp['city'])
     self.assertEqual(pm.state, params_tmp['state'])
     self.assertEqual(pm.zip, params_tmp['zip'])
     self.assertEqual(pm.last_four_digits, '1111')
     self.assertEqual(pm.expiry_month, int(params_tmp['expiry_month']))
     self.assertEqual(pm.expiry_year, int(params_tmp['expiry_year']))
 def test_update_should_be_successful_preserving_sensitive_data(self):
     params_tmp = paramsx
     params_tmp['card_number'] = '****************'
     params_tmp['cvv'] = '***'
     pm = PaymentMethod.create(**params)
     pm = pm.update(**paramsx)
     self.assertTrue(pm.is_expiration_valid)
     self.assertEqual(pm.first_name, params_tmp['first_name'])
     self.assertEqual(pm.last_name, params_tmp['last_name'])
     self.assertEqual(pm.address_1, params_tmp['address_1'])
     self.assertEqual(pm.address_2, params_tmp['address_2'])
     self.assertEqual(pm.city, params_tmp['city'])
     self.assertEqual(pm.state, params_tmp['state'])
     self.assertEqual(pm.zip, params_tmp['zip'])
     self.assertEqual(pm.last_four_digits, '1111')
     self.assertEqual(pm.expiry_month, int(params_tmp['expiry_month']))
     self.assertEqual(pm.expiry_year, int(params_tmp['expiry_year']))
def purchase(request):
    if request.method == "POST":
        data = request.POST
        token = PaymentMethod.create(data.get('card_number'), data.get('cvv'), data.get('expiry_month'),
                                     data.get('expiry_year'), first_name=data.get('first_name'),
                                     last_name=data.get('last_name'))
        trans = Processor.purchase(token.payment_method_token, 10)
        if trans.errors:
            errors = parse_error(trans.errors)
            for err in errors:
                messages.error(request, err, fail_silently=True)
            return redirect('/server_to_server/payment_form')
        else:
            messages.success(request, 'Purchase Successful.', fail_silently=True)
            return render_to_response('/server_to_server/receipt.html')
    else:
        return redirect('/server_to_server/payment_form')
Example #31
0
 def unstore(self, identification, options=None):
     payment_method = PaymentMethod.find(identification)
     if payment_method.errors:
         transaction_was_unsuccessful.send(sender=self, 
                                           type="unstore",
                                           response=payment_method)
         return {"status": "FAILURE", "response": payment_method}
     payment_method = payment_method.redact()
     if payment_method.errors:
         transaction_was_unsuccessful.send(sender=self, 
                                           type="unstore",
                                           response=payment_method)
         return {"status": "FAILURE", "response": payment_method}
     transaction_was_successful.send(sender=self, 
                                     type="unstore",
                                     response=payment_method)
     return {"status": "SUCCESS", "response": payment_method}
Example #32
0
 def unstore(self, identification, options=None):
     payment_method = PaymentMethod.find(identification)
     if payment_method.errors:
         transaction_was_unsuccessful.send(sender=self,
                                           type="unstore",
                                           response=payment_method)
         return {"status": "FAILURE", "response": payment_method}
     payment_method = payment_method.redact()
     if payment_method.errors:
         transaction_was_unsuccessful.send(sender=self,
                                           type="unstore",
                                           response=payment_method)
         return {"status": "FAILURE", "response": payment_method}
     transaction_was_successful.send(sender=self,
                                     type="unstore",
                                     response=payment_method)
     return {"status": "SUCCESS", "response": payment_method}
Example #33
0
    def charge_setup(self, card, billing_info):
        """
        standard setup, used for charges
        """
        billing_info = self.translate(billing_info)

        # use the card + extra data- send it to samurai for storage and tokenization
        card._exp_yr_style = True
        super(Samurai, self).use_credit_card(card)
        pm = PaymentMethod.create(
                    card.number,
                    card.verification_value,
                    card.exp_month, card.exp_year, **billing_info)

        debug_string = " paython.gateways.samurai_ff.charge_setup() -- response on setting pm"
        logger.debug(debug_string.center(80, '='))
        logger.debug(dir(pm))

        if pm.errors:
            raise DataValidationError('Invalid Card Data: %s' % pm.errors[pm.error_messages[0]['context']][0])

        return pm.payment_method_token
Example #34
0
    def charge_setup(self, card, billing_info):
        """
        standard setup, used for charges
        """
        billing_info = self.translate(billing_info)

        # use the card + extra data- send it to samurai for storage and tokenization
        card._exp_yr_style = True
        super(Samurai, self).use_credit_card(card)
        pm = PaymentMethod.create(
                    card.number,
                    card.verification_value,
                    card.exp_month, card.exp_year, **billing_info)

        debug_string = " paython.gateways.samurai_ff.charge_setup() -- response on setting pm"
        logger.debug(debug_string.center(80, '='))
        logger.debug(dir(pm))

        if pm.errors:
            raise DataValidationError('Invalid Card Data: %s' % pm.errors[pm.error_messages[0]['context']][0])

        return pm.payment_method_token
 def setUp(self):
     self.pm = PaymentMethod.create(**params)
Example #36
0
 def unstore(self, identification, options=None):
     from samurai.payment_method import PaymentMethod
     payment_method = PaymentMethod.find(identification)
     payment_method = payment_method.redact()
     return {"status": "SUCCESS", "response": payment_method}
    def test_create_failure(self):
        pm = PaymentMethod.create("4343434343434343", "133", "07", "12")
        assert not pm.is_sensitive_data_valid

        errors = [{"context": "input.card_number", "key": "failed_checksum", "subclass": "error"}]
        assert pm.errors == errors
Example #38
0
 def unstore(self, identification, options=None):
     from samurai.payment_method import PaymentMethod
     payment_method = PaymentMethod.find(identification)
     payment_method = payment_method.redact()
     return {"status": "SUCCESS", "response": payment_method}
Example #39
0
 def store(self, credit_card, options=None):
     from samurai.payment_method import PaymentMethod
     pm = PaymentMethod.create(credit_card.number, credit_card.verification_value, credit_card.month, credit_card.year)
     response = pm.retain()
     return {'status': 'SUCCESS', 'response': response}
 def setUp(self):
     self.pm = PaymentMethod.create(**params)
Example #41
0
 def __init__(self, pmt):
     """Given a payment method token, loads data from Samurai.
     """
     if pmt is not None:
        self._payment_method = SamuraiPaymentMethod.find(pmt)
 def test_find_should_fail_on_an_invalid_token(self):
     pm = PaymentMethod.find('abc123')
     err = "Couldn't find PaymentMethod with token = abc123"
     self.assertIn(err, pm.error_messages)
 def test_find_should_fail_on_an_invalid_token(self):
     pm = PaymentMethod.find('abc123')
     err = "Couldn't find PaymentMethod with token = abc123"
     self.assertIn({'context': 'system.general', 'key': 'default', 'subclass':'error', 'text':err}, pm.error_messages)
 def setUp(self):
     self.pm = PaymentMethod.create("4242424242424242", "133", "07", "12")
Example #45
0
 def testPurchaseWithToken(self):
     resp = PaymentMethod.create('4111111111111111', '111', '07', '14')
     resp = self.merchant.purchase(500, resp.payment_method_token)
     self.assertEquals(resp["status"], "SUCCESS")
Example #46
0
 def __init__(self, pmt):
     """Given a payment method token, loads data from Samurai.
     """
     if pmt is not None:
         self._payment_method = SamuraiPaymentMethod.find(pmt)
 def setUp(self):
     self.pm = PaymentMethod.create('4242424242424242', '133', '07', '12')