Example #1
0
    def clean(self):
        cleaned_data = super(PaylaneForm,self).clean()
        
        if not self._errors:
            name = cleaned_data.get('name_on_card','').split(' ',1)
            first_name = name[0]
            last_name = ' '.join(name[1:])

            cc = Visa(first_name=first_name,
                    last_name=last_name,
                    month = cleaned_data.get('expiration_month'),
                    year = cleaned_data.get('expiration_year'),
                    number = cleaned_data.get('card_number'),
                    verification_value = cleaned_data.get('card_code'))

            if cc.is_expired():
                raise forms.ValidationError(_('This credit card has expired.'))
            
            if not cc.is_luhn_valid():
                raise forms.ValidationError(_('This credit card number isn\'t valid'))
            
            if not cc.is_valid():
                #this should never occur
                raise forms.ValidationError(_('Invalid credit card'))

            options = {
                    'customer':cleaned_data.get('name_on_card'),
                    'email':'',
                    'order_id':'',
                    'ip':'',
                    'description':'',
                    'merchant':'',
                    'billing_address':{
                            'name':cleaned_data.get('name_on_card'),
                            'company':'',
                            'address1':cleaned_data.get('street_house'),
                            'address2':'',
                            'city':cleaned_data.get('city'),
                            'state':'',
                            'country':cleaned_data.get('country_code'),
                            'zip':cleaned_data.get('zip_code'),
                            'phone':'',
                        },
                    'shipping_address':{}
                }
        
            cleaned_data['paylane'] = {
                    'credit_card':cc,
                    'options':options
                }

        return cleaned_data
Example #2
0
    def clean(self):
        cleaned_data = super(PaylaneForm, self).clean()

        if not self._errors:
            name = cleaned_data.get('name_on_card', '').split(' ', 1)
            first_name = name[0]
            last_name = ' '.join(name[1:])

            cc = Visa(first_name=first_name,
                      last_name=last_name,
                      month=cleaned_data.get('expiration_month'),
                      year=cleaned_data.get('expiration_year'),
                      number=cleaned_data.get('card_number'),
                      verification_value=cleaned_data.get('card_code'))

            if cc.is_expired():
                raise forms.ValidationError(_('This credit card has expired.'))

            if not cc.is_luhn_valid():
                raise forms.ValidationError(
                    _('This credit card number isn\'t valid'))

            if not cc.is_valid():
                #this should never occur
                raise forms.ValidationError(_('Invalid credit card'))

            options = {
                'customer': cleaned_data.get('name_on_card'),
                'email': '',
                'order_id': '',
                'ip': '',
                'description': '',
                'merchant': '',
                'billing_address': {
                    'name': cleaned_data.get('name_on_card'),
                    'company': '',
                    'address1': cleaned_data.get('street_house'),
                    'address2': '',
                    'city': cleaned_data.get('city'),
                    'state': '',
                    'country': cleaned_data.get('country_code'),
                    'zip': cleaned_data.get('zip_code'),
                    'phone': '',
                },
                'shipping_address': {}
            }

            cleaned_data['paylane'] = {'credit_card': cc, 'options': options}

        return cleaned_data
Example #3
0
    def testCaptureError(self):
        credit_card = Visa(first_name='Celso',
                           last_name='Pinto',
                           month=10,
                           year=2020,
                           number='4556096020428973',
                           verification_value=435)
        options = {}
        options['customer'] = self.customer
        options['product'] = self.product
        res = self.merchant.authorize(1.0, credit_card, options=options)
        self.assertEqual(res['status'], 'SUCCESS', unicode(res['response']))
        self.assertTrue('transaction' in res['response'])
        self.assertTrue('authorization' in res['response'])
        self.assertTrue(
            res['response']['authorization'].sale_authorization_id > 0)

        bill2 = self.merchant.capture(
            float(PaylaneError.ERR_RESALE_WITH_CHARGEBACK),
            res['response']['authorization'], options)
        self.assertEqual(bill2['status'], 'FAILURE',
                         unicode(bill2['response']))
        self.assertTrue('transaction' in bill2['response'])
        self.assertTrue('error' in bill2['response'])
        self.assertEqual(bill2['response']['error'].error_code, 443)
Example #4
0
    def testRecurringBillingFailWithChargeback(self):
        credit_card = Visa(first_name='Celso',
                           last_name='Pinto',
                           month=10,
                           year=2020,
                           number='4111111111111111',
                           verification_value=435)
        options = {}
        options['customer'] = self.customer
        options['product'] = self.product
        res = self.merchant.recurring(1.0, credit_card, options=options)
        self.assertEqual(res['status'], 'SUCCESS', unicode(res['response']))
        self.assertTrue('transaction' in res['response'])
        self.assertTrue('authorization' in res['response'])
        self.assertTrue(
            res['response']['authorization'].sale_authorization_id > 0)

        bill1 = self.merchant.bill_recurring(12.0,
                                             res['response']['authorization'],
                                             'OK recurring')
        self.assertEqual(bill1['status'], 'SUCCESS',
                         unicode(bill1['response']))
        self.assertTrue('transaction' in bill1['response'])
        self.assertTrue('authorization' in bill1['response'])

        bill2 = self.merchant.bill_recurring(
            float(PaylaneError.ERR_RESALE_WITH_CHARGEBACK),
            bill1['response']['authorization'], 'Fail recurring')
        self.assertEqual(bill2['status'], 'FAILURE',
                         unicode(bill2['response']))
        self.assertTrue('transaction' in bill2['response'])
        self.assertTrue('error' in bill2['response'])
        self.assertEqual(bill2['response']['error'].error_code,
                         PaylaneError.ERR_RESALE_WITH_CHARGEBACK)
Example #5
0
    def testRecurringBillingOK(self):
        credit_card = Visa(first_name='Celso',
                           last_name='Pinto',
                           month=10,
                           year=2012,
                           number='4000111111111115',
                           verification_value="100")
        options = {}
        options['customer'] = self.customer
        options['product'] = self.product
        res = self.merchant.recurring(1.0, credit_card, options=options)
        self.assertEqual(res['status'], 'SUCCESS', unicode(res['response']))
        self.assertTrue('transaction' in res['response'])
        self.assertTrue('authorization' in res['response'])
        self.assertTrue(
            res['response']['authorization'].sale_authorization_id > 0)

        bill1 = self.merchant.bill_recurring(12.0,
                                             res['response']['authorization'],
                                             'OK recurring')
        self.assertEqual(bill1['status'], 'SUCCESS',
                         unicode(bill1['response']))
        self.assertTrue('transaction' in bill1['response'])
        self.assertTrue('authorization' in bill1['response'])

        bill2 = self.merchant.bill_recurring(
            12.0, bill1['response']['authorization'], 'OK recurring')
        self.assertEqual(bill2['status'], 'SUCCESS',
                         unicode(bill2['response']))
        self.assertTrue('transaction' in bill2['response'])
        self.assertTrue('authorization' in bill2['response'])
Example #6
0
 def testOneShotPurchaseOK(self):
     credit_card = Visa(first_name='Celso', last_name='Pinto', month=10, year=2020, number='4012888888881881', verification_value=435)
     options = {}
     options['customer'] = self.customer
     options['product'] = {}
     res = self.merchant.purchase(1.0, credit_card, options=options)
     self.assertEqual(res['status'], 'SUCCESS', unicode(res['response']))
     self.assertTrue('transaction' in res['response'])
     self.assertFalse('authorization' in res['response'])
Example #7
0
 def testRecurringSetupOK(self):
     credit_card = Visa(first_name='Celso', last_name='Pinto', month=10, year=2020, number='4242424242424242', verification_value=435)
     options = {}
     options['customer'] = self.customer
     options['product'] = self.product
     res = self.merchant.recurring(1.0, credit_card, options=options)
     self.assertEqual(res['status'], 'SUCCESS', unicode(res['response']))
     self.assertTrue('transaction' in res['response'])
     self.assertTrue('authorization' in res['response'])
     self.assertTrue(res['response']['authorization'].sale_authorization_id > 0)
Example #8
0
 def testRecurringSetupError(self):
     credit_card = Visa(first_name='Celso', last_name='Pinto', month=10, year=2020, number='4916437826836305', verification_value=435)
     options = {}
     options['customer'] = self.customer
     options['product'] = self.product
     res = self.merchant.recurring(float(PaylaneError.ERR_CARD_EXPIRED), credit_card, options=options)
     self.assertEqual(res['status'], 'FAILURE', unicode(res['response']))
     self.assertTrue('transaction' in res['response'])
     self.assertFalse('authorization' in res['response'])
     self.assertTrue('error' in res['response'])
     self.assertEqual(res['response']['error'].error_code, PaylaneError.ERR_CARD_EXPIRED)
Example #9
0
    def testCaptureOK(self):
        credit_card = Visa(first_name='Celso', last_name='Pinto', month=10, year=2020, number='4278255665174428', verification_value="100")
        options = {}
        options['customer'] = self.customer
        options['product'] = self.product
        res = self.merchant.authorize(36.0, credit_card, options=options)
        self.assertEqual(res['status'], 'SUCCESS', unicode(res['response']))
        self.assertTrue('transaction' in res['response'])
        self.assertTrue('authorization' in res['response'])
        self.assertTrue(res['response']['authorization'].sale_authorization_id > 0)

        bill1 = self.merchant.capture(36.0, res['response']['authorization'], options)
        self.assertEqual(bill1['status'], 'SUCCESS', unicode(bill1['response']))
        self.assertTrue('transaction' in bill1['response'])
        self.assertTrue('authorization' in bill1['response'])
Example #10
0
 def testOneShotPurchaseError(self):
     credit_card = Visa(first_name='Celso',
                        last_name='Pinto',
                        month=10,
                        year=2012,
                        number='4929966723331981',
                        verification_value=435)
     options = {}
     options['customer'] = self.customer
     options['product'] = {}
     res = self.merchant.purchase(float(PaylaneError.ERR_CARD_EXPIRED),
                                  credit_card,
                                  options=options)
     self.assertEqual(res['status'], 'FAILURE', unicode(res['response']))
     self.assertTrue('transaction' in res['response'])
     self.assertFalse('authorization' in res['response'])
     self.assertTrue('error' in res['response'])
     self.assertEqual(res['response']['error'].error_code,
                      PaylaneError.ERR_CARD_EXPIRED)