def recurring(self, money, credit_card, options): if not options: options = {} if not self.validate_card(credit_card): raise InvalidCard("Invalid Card") template_vars = {} template_vars['auth_login'] = self.login template_vars['auth_key'] = self.password template_vars['amount'] = money template_vars['card_number'] = credit_card.number template_vars['exp_date'] = credit_card.expire_date template_vars['start_date'] = options.get( 'start_date') or datetime.date.today().strftime("%Y-%m-%d") template_vars['total_occurrences'] = options.get( 'total_occurences', 9999) template_vars['interval_length'] = options.get('interval_length', 1) template_vars['interval_unit'] = options.get('interval_unit', 'months') template_vars['sub_name'] = options.get('sub_name', '') template_vars['first_name'] = credit_card.first_name template_vars['last_name'] = credit_card.last_name xml = render_to_string('billing/arb/arb_create_subscription.xml', template_vars) if self.test_mode: url = self.arb_test_url else: url = self.arb_live_url headers = {'content-type': 'text/xml'} conn = urllib2.Request(url=url, data=xml, headers=headers) try: open_conn = urllib2.urlopen(conn) xml_response = open_conn.read() except urllib2.URLError: return (5, '1', 'Could not talk to payment gateway.') response = nodeToDic( parseString(xml_response))['ARBCreateSubscriptionResponse'] # successful response # {u'ARBCreateSubscriptionResponse': {u'messages': {u'message': {u'code': u'I00001', # u'text': u'Successful.'}, # u'resultCode': u'Ok'}, # u'subscriptionId': u'933728'}} status = "SUCCESS" if response['messages']['resultCode'].lower() != 'ok': status = "FAILURE" transaction_was_unsuccessful.send(sender=self, type="recurring", response=response) else: transaction_was_successful.send(sender=self, type="recurring", response=response) return {"status": status, "response": response}
def recurring(self, money, credit_card, options): if not options: options = {} if not self.validate_card(credit_card): raise InvalidCard("Invalid Card") template_vars = {} template_vars['auth_login'] = self.login template_vars['auth_key'] = self.password template_vars['amount'] = money template_vars['card_number'] = credit_card.number template_vars['exp_date'] = credit_card.expire_date template_vars['start_date'] = options.get('start_date') or datetime.date.today().strftime("%Y-%m-%d") template_vars['total_occurrences'] = options.get('total_occurences', 9999) template_vars['interval_length'] = options.get('interval_length', 1) template_vars['interval_unit'] = options.get('interval_unit', 'months') template_vars['sub_name'] = options.get('sub_name', '') template_vars['first_name'] = credit_card.first_name template_vars['last_name'] = credit_card.last_name xml = render_to_string('billing/arb/arb_create_subscription.xml', template_vars) if self.test_mode: url = self.arb_test_url else: url = self.arb_live_url headers = {'content-type':'text/xml'} conn = urllib2.Request(url=url, data=xml, headers=headers) try: open_conn = urllib2.urlopen(conn) xml_response = open_conn.read() except urllib2.URLError: return (5, '1', 'Could not talk to payment gateway.') response = nodeToDic(parseString(xml_response))['ARBCreateSubscriptionResponse'] # successful response # {u'ARBCreateSubscriptionResponse': {u'messages': {u'message': {u'code': u'I00001', # u'text': u'Successful.'}, # u'resultCode': u'Ok'}, # u'subscriptionId': u'933728'}} status = "SUCCESS" subscription_id = None if response['messages']['resultCode'].lower() != 'ok': status = "FAILURE" transaction_was_unsuccessful.send(sender=self, type="recurring", response=response) else: transaction_was_successful.send(sender=self, type="recurring", response=response) if 'subscriptionId' in response: subscription_id = response['subscriptionId'] return {"status": status, 'subscription_id': subscription_id, "response": response}