Exemplo n.º 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}
Exemplo n.º 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}
Exemplo n.º 3
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}
Exemplo n.º 4
0
 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 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']))
Exemplo n.º 6
0
 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']))
Exemplo n.º 7
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}
Exemplo n.º 8
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}
 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)
Exemplo n.º 10
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_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)
Exemplo n.º 12
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)
Exemplo n.º 13
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}
Exemplo n.º 14
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)