コード例 #1
0
 def test_capture_should_return_processor_transaction_declined(self):
     auth = Processor.authorize(self.pm.payment_method_token, 100.00)
     capture = auth.capture(100.02)
     self.assertFalse(capture.success)
     err = {'context': 'processor.transaction', 'key': 'declined', 'subclass': 'error'}
     self.assertIn(err, capture.error_messages)
     self.assertIn('The card was declined.', capture.errors['processor.transaction'])
コード例 #2
0
 def test_capture_should_return_input_amount_invalid(self):
     auth = Processor.authorize(self.pm.payment_method_token, 100.00)
     capture = auth.capture(100.10)
     self.assertFalse(capture.success)
     err = {'context': 'input.amount', 'key': 'invalid', 'subclass': 'error'}
     self.assertIn(err, capture.error_messages)
     self.assertIn('The transaction amount was invalid.', capture.errors['input.amount'])
コード例 #3
0
 def test_authorize_should_return_processor_cvv_result_code_N(self):
     token = test_helper.default_payment_method({'cvv':'222'}).payment_method_token
     purchase = Processor.authorize(token,
                                   1.00,
                                   billing_reference=self.rand)
     self.assertTrue(purchase.success)
     self.assertEqual(purchase.processor_response['cvv_result_code'], 'N')
コード例 #4
0
ファイル: billing.py プロジェクト: bglusman/www.gittip.com
def authorize(participant_id, pmt):
    """Given two unicodes, return a dict.

    This function attempts to authorize the credit card details referenced by
    pmt. If the attempt succeeds we cancel the transaction. If it fails we log
    the failure. Even for failure we keep the payment_method_token, we don't
    reset it to None/NULL. It's useful for loading the previous (bad) credit
    card info from Samurai in order to prepopulate the form.

    """
    typecheck(pmt, unicode, participant_id, unicode)
    transaction = Processor.authorize(pmt, '1.00', custom=participant_id)
    if transaction.errors:
        last_bill_result = json.dumps(transaction.errors)
        out = dict(transaction.errors)
    else:
        transaction.reverse()
        last_bill_result = ''
        out = {}
        
    STANDING = """\

    UPDATE participants
       SET payment_method_token=%s
         , last_bill_result=%s 
     WHERE id=%s

    """
    db.execute(STANDING, (pmt, last_bill_result, participant_id))
    return out
コード例 #5
0
def authorize(participant_id, pmt):
    """Given two unicodes, return a dict.

    This function attempts to authorize the credit card details referenced by
    pmt. If the attempt succeeds we cancel the transaction. If it fails we log
    the failure. Even for failure we keep the payment_method_token, we don't
    reset it to None/NULL. It's useful for loading the previous (bad) credit
    card info from Samurai in order to prepopulate the form.

    """
    typecheck(pmt, unicode, participant_id, unicode)
    transaction = Processor.authorize(pmt, '1.00', custom=participant_id)
    if transaction.errors:
        last_bill_result = json.dumps(transaction.errors)
        out = dict(transaction.errors)
    else:
        transaction.reverse()
        last_bill_result = ''
        out = {}

    STANDING = """\

    UPDATE participants
       SET payment_method_token=%s
         , last_bill_result=%s 
     WHERE id=%s

    """
    db.execute(STANDING, (pmt, last_bill_result, participant_id))
    return out
コード例 #6
0
 def test_authorize_should_return_processor_transaction_declined(self):
     token = self.pm.payment_method_token
     purchase = Processor.authorize(token,
                                   1.02,
                                   billing_reference=self.rand)
     self.assertFalse(purchase.success)
     err = {'context': 'processor.transaction', 'key': 'declined', 'subclass': 'error'}
     self.assertIn(err, purchase.error_messages)
     self.assertIn('The card was declined.' , purchase.errors['processor.transaction'])
コード例 #7
0
 def test_authorize_should_return_input_amount_invalid(self):
     token = self.pm.payment_method_token
     purchase = Processor.authorize(token,
                                   1.10,
                                   billing_reference=self.rand)
     self.assertFalse(purchase.success)
     err = {'context': 'input.amount', 'key': 'invalid', 'subclass': 'error'}
     self.assertIn(err, purchase.error_messages)
     self.assertIn('The transaction amount was invalid.', purchase.errors['input.amount'])
コード例 #8
0
 def test_authorize_should_return_processor_avs_result_code_N(self):
     token = test_helper.default_payment_method({'address_1':'123 Main St',
                                                'address_2':'',
                                                'zip':'60610'}).payment_method_token
     purchase = Processor.authorize(token,
                                   1.00,
                                   billing_reference=self.rand)
     self.assertTrue(purchase.success)
     self.assertEqual(purchase.processor_response['avs_result_code'], 'N')
コード例 #9
0
 def test_authorize_should_return_processor_cvv_result_code_N(self):
     token = test_helper.default_payment_method({
         'cvv': '222'
     }).payment_method_token
     purchase = Processor.authorize(token,
                                    1.00,
                                    billing_reference=self.rand)
     self.assertTrue(purchase.success)
     self.assertEqual(purchase.processor_response['cvv_result_code'], 'N')
コード例 #10
0
 def test_authorize_capture_failed(self):
     auth = Processor.authorize(self.pm.payment_method_token, 10.0)
     trans = auth.capture(10.02)
     self.assertFalse(trans.success)
     errors = [{
         'context': 'processor.transaction',
         'key': 'declined',
         'subclass': 'error'
     }]
     self.assertEquals(trans.errors, errors)
コード例 #11
0
 def test_authorize_should_return_processor_avs_result_code_N(self):
     token = test_helper.default_payment_method({
         'address_1': '123 Main St',
         'address_2': '',
         'zip': '60610'
     }).payment_method_token
     purchase = Processor.authorize(token,
                                    1.00,
                                    billing_reference=self.rand)
     self.assertTrue(purchase.success)
     self.assertEqual(purchase.processor_response['avs_result_code'], 'N')
コード例 #12
0
ファイル: samurai_gateway.py プロジェクト: hayyat/merchant
 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}
コード例 #13
0
 def test_capture_should_return_input_amount_invalid(self):
     auth = Processor.authorize(self.pm.payment_method_token, 100.00)
     capture = auth.capture(100.10)
     self.assertFalse(capture.success)
     err = {
         'context': 'input.amount',
         'key': 'invalid',
         'subclass': 'error'
     }
     self.assertIn(err, capture.error_messages)
     self.assertIn('The transaction amount was invalid.',
                   capture.errors['input.amount'])
コード例 #14
0
ファイル: samurai_ff.py プロジェクト: AdamJacobMuller/Paython
 def auth(self, amount, credit_card=None, billing_info=None, shipping_info=None):
     # set up the card for charging, obviously
     card_token = self.charge_setup(credit_card, billing_info)
     # start the timer
     start = time.time()
     # send it over for processing
     response = Processor.authorize(card_token, amount)
     # measure time
     end = time.time() # done timing it
     response_time = '%0.2f' % (end-start)
     # return parsed response
     return self.parse(response, response_time)
コード例 #15
0
ファイル: samurai_ff.py プロジェクト: Python3pkg/Paython
 def auth(self, amount, credit_card=None, billing_info=None, shipping_info=None):
     # set up the card for charging, obviously
     card_token = self.charge_setup(credit_card, billing_info)
     # start the timer
     start = time.time()
     # send it over for processing
     response = Processor.authorize(card_token, amount)
     # measure time
     end = time.time() # done timing it
     response_time = '%0.2f' % (end-start)
     # return parsed response
     return self.parse(response, response_time)
コード例 #16
0
ファイル: samurai_gateway.py プロジェクト: pydonny/merchant
 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}
コード例 #17
0
 def test_capture_should_return_processor_transaction_declined(self):
     auth = Processor.authorize(self.pm.payment_method_token, 100.00)
     capture = auth.capture(100.02)
     self.assertFalse(capture.success)
     err = {
         'context': 'processor.transaction',
         'key': 'declined',
         'subclass': 'error'
     }
     self.assertIn(err, capture.error_messages)
     self.assertIn('The card was declined.',
                   capture.errors['processor.transaction'])
コード例 #18
0
 def test_capture_should_return_processor_transaction_invalid_with_declined_auth(
         self):
     auth = Processor.authorize(self.pm.payment_method_token,
                                100.02)  # declined auth
     capture = auth.capture()
     self.assertFalse(capture.success)
     err = {
         'context': 'processor.transaction',
         'key': 'not_allowed',
         'subclass': 'error'
     }
     self.assertIn(err, capture.error_messages)
コード例 #19
0
ファイル: samurai_gateway.py プロジェクト: hayyat/merchant
 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}
コード例 #20
0
 def test_authorize_should_return_input_amount_invalid(self):
     token = self.pm.payment_method_token
     purchase = Processor.authorize(token,
                                    1.10,
                                    billing_reference=self.rand)
     self.assertFalse(purchase.success)
     err = {
         'context': 'input.amount',
         'key': 'invalid',
         'subclass': 'error'
     }
     self.assertIn(err, purchase.error_messages)
     self.assertIn('The transaction amount was invalid.',
                   purchase.errors['input.amount'])
コード例 #21
0
 def test_authorize_should_return_processor_transaction_declined(self):
     token = self.pm.payment_method_token
     purchase = Processor.authorize(token,
                                    1.02,
                                    billing_reference=self.rand)
     self.assertFalse(purchase.success)
     err = {
         'context': 'processor.transaction',
         'key': 'declined',
         'subclass': 'error'
     }
     self.assertIn(err, purchase.error_messages)
     self.assertIn('The card was declined.',
                   purchase.errors['processor.transaction'])
コード例 #22
0
 def test_authorize_should_be_successful(self):
     options = {'description':'description',
                'descriptor_name':'descriptor_name',
                'descriptor_phone':'descriptor_phone',
                'custom':'custom',
                'billing_reference':'ABC123%s' % self.rand,
                'customer_reference':'Customer (123)'}
     token = self.pm.payment_method_token
     purchase = Processor.authorize(token, 100.0, None, **options)
     self.assertTrue(purchase.success)
     self.assertEquals(purchase.error_messages, [])
     self.assertEqual(purchase.description, 'description')
     self.assertEqual(purchase.descriptor_name, 'descriptor_name')
     self.assertEqual(purchase.descriptor_phone, 'descriptor_phone')
     self.assertEqual(purchase.custom, 'custom')
     self.assertEqual(purchase.billing_reference, 'ABC123%s' % self.rand)
     self.assertEqual(purchase.customer_reference, 'Customer (123)')
コード例 #23
0
 def test_authorize_should_be_successful(self):
     options = {
         'description': 'description',
         'descriptor_name': 'descriptor_name',
         'descriptor_phone': 'descriptor_phone',
         'custom': 'custom',
         'billing_reference': 'ABC123%s' % self.rand,
         'customer_reference': 'Customer (123)'
     }
     token = self.pm.payment_method_token
     purchase = Processor.authorize(token, 100.0, None, **options)
     self.assertTrue(purchase.success)
     self.assertEquals(purchase.error_messages, [])
     self.assertEqual(purchase.description, 'description')
     self.assertEqual(purchase.descriptor_name, 'descriptor_name')
     self.assertEqual(purchase.descriptor_phone, 'descriptor_phone')
     self.assertEqual(purchase.custom, 'custom')
     self.assertEqual(purchase.billing_reference, 'ABC123%s' % self.rand)
     self.assertEqual(purchase.customer_reference, 'Customer (123)')
コード例 #24
0
 def setUp(self):
     self.pm = test_helper.default_payment_method()
     self.rand = randint(100, 999)
     self.auth = Processor.authorize(self.pm.payment_method_token, 100.0)
     self.purchase = Processor.purchase(self.pm.payment_method_token, 100.0)
コード例 #25
0
 def test_authorize_partial_capture(self):
     auth = Processor.authorize(self.pm.payment_method_token, 10.0)
     trans = auth.capture(8.0)
     self.assertTrue(trans.success)
     self.assertEquals(trans.amount, '8.0')
     self.assertEquals(trans.errors, [])
コード例 #26
0
 def test_authorize_void(self):
     auth = Processor.authorize(self.pm.payment_method_token, 10.0)
     trans = auth.void()
     self.assertTrue(trans.success)
     self.assertEquals(trans.errors, [])
コード例 #27
0
 def test_authorize_capture_reverse(self):
     auth = Processor.authorize(self.pm.payment_method_token, 10.0)
     capture = auth.capture(10.0)
     trans = capture.reverse()
     self.assertTrue(trans.success)
     self.assertEquals(trans.errors, [])
コード例 #28
0
 def test_authorize(self):
     token = self.pm.payment_method_token
     trans = Processor.authorize(token, 10.0)
     self.assertTrue(trans.success)
     self.assertEquals(trans.errors, [])
コード例 #29
0
 def test_authorize_failure(self):
     token = self.pm.payment_method_token
     trans = Processor.authorize(token, 10.02)
     errors = [{'context': 'processor.transaction', 'key': 'declined', 'subclass': 'error'}]
     self.assertEquals(trans.errors, errors)
コード例 #30
0
 def test_capture_should_return_processor_transaction_invalid_with_declined_auth(self):
     auth = Processor.authorize(self.pm.payment_method_token, 100.02)  # declined auth
     capture = auth.capture()
     self.assertFalse(capture.success)
     err = {'context': 'processor.transaction', 'key': 'not_allowed', 'subclass': 'error'}
     self.assertIn(err, capture.error_messages)
コード例 #31
0
 def test_authorize_capture(self):
     auth = Processor.authorize(self.pm.payment_method_token, 10.0)      
     trans = auth.capture(10.0)
     self.assertTrue(trans.success)
     self.assertEquals(trans.errors, [])
コード例 #32
0
 def setUp(self):
     self.pm = test_helper.default_payment_method()
     self.rand = randint(100, 999)
     self.auth = Processor.authorize(self.pm.payment_method_token, 100.0)
     self.purchase = Processor.purchase(self.pm.payment_method_token, 100.0)
コード例 #33
0
 def test_authorize_capture_failed(self):
     auth = Processor.authorize(self.pm.payment_method_token, 10.0)      
     trans = auth.capture(10.02)
     self.assertFalse(trans.success)
     errors = [{'context': 'processor.transaction', 'key': 'declined', 'subclass': 'error'}]
     self.assertEquals(trans.errors, errors)