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}
Example #2
0
 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}
Example #3
0
def process_direct_payment(request, order_form, order):
    """
        Eway Direct Payment API Url : http://www.eway.com.au/developers/api/direct-payments#tab-1
            Input and Output format: https://gist.github.com/2552fcaa2799045a7884
    """
    #direct_payment_details is dict
    direct_payment_details = {}
    # create a md5 value to be the 
    direct_payment_details['ewayCustomerID'] = testid
    direct_payment_details['ewayCustomerFirstName'] = order_form.cleaned_data['card_name']
    direct_payment_details['ewayCustomerLastName'] = None
    direct_payment_details['ewayCustomerAddress'] = None
    direct_payment_details['ewayCustomerEmail'] = None
    direct_payment_details['ewayCustomerPostcode'] = None
    direct_payment_details['ewayCardNumber'] = order_form.cleaned_data['card_number']
    direct_payment_details['ewayCardHoldersName'] = order_form.cleaned_data['card_name']
    direct_payment_details['ewayCardExpiryMonth'] = order_form.cleaned_data['card_expiry_month']
    direct_payment_details['ewayCardExpiryYear'] = order_form.cleaned_data['card_expiry_year']
    direct_payment_details['ewayCVN'] = order_form.cleaned_data['card_ccv']
    direct_payment_details['ewayOption1'] = None
    direct_payment_details['ewayOption2'] = None
    direct_payment_details['ewayOption3'] = None
    direct_payment_details['ewayTrxnNumber'] = None
    #direct_payment_details['ewayTotalAmount'] = int((order.total).to_integral())
    #test sandbox
    #direct_payment_details['ewayTotalAmount'] = int(str(int((order.total).to_integral()))+'00')
    #test live environment 
    direct_payment_details['ewayTotalAmount'] =int(str("%.2f" % order.total ).replace('.',''))
    #direct_payment_details['ewayTotalAmount']=1
    direct_payment_details['ewayCustomerInvoiceRef'] = None
    direct_payment_details['ewayCustomerInvoiceDescription'] = None


    if direct_payment_details:
        # Create XML to send
        payment_xml_root = Element("ewaygateway")
        for each_field in direct_payment_details:
            field = Element(each_field)
            field.text = str(direct_payment_details.get(each_field))
            payment_xml_root.append(field)
        # pretty string
        payment_xml_string = tostring(payment_xml_root)
        print payment_xml_string
        #response = requests.post(DIRECT_PAYMENT_TEST_URL, data=payment_xml_string)
        response = requests.post(DIRECT_PAYMENT_LIVE_URL, data=payment_xml_string)
        response_xml = parseString(response.text)
        response_dict = nodeToDic(response_xml)

        return response_dict
    else:
         pass
Example #4
0
    def process_direct_payment(self, direct_payment_details=None, **kwargs):
        """
            Eway Direct Payment API Url : http://www.eway.com.au/developers/api/direct-payments#tab-1
            Input and Output format: https://gist.github.com/2552fcaa2799045a7884
        """
        if direct_payment_details:
            # Create XML to send
            payment_xml_root = Element("ewaygateway")
            for each_field in direct_payment_details:
                field = Element(each_field)
                field.text = str(direct_payment_details.get(each_field))
                payment_xml_root.append(field)
            # pretty string
            payment_xml_string = tostring(payment_xml_root)
            response = requests.post(self.gateway_url, data=payment_xml_string)
            response_xml = parseString(response.text)
            response_dict = nodeToDic(response_xml)

            return response_dict
        else:
            return self.process_direct_payment(**kwargs)
Example #5
0
    def process_direct_payment(self, direct_payment_details=None, **kwargs):
        """
            Eway Direct Payment API Url : http://www.eway.com.au/developers/api/direct-payments#tab-1
            Input and Output format: https://gist.github.com/2552fcaa2799045a7884
        """
        if direct_payment_details:
            # Create XML to send
            payment_xml_root = Element("ewaygateway")
            for each_field in direct_payment_details:
                field = Element(each_field)
                field.text = str(direct_payment_details.get(each_field))
                payment_xml_root.append(field)
            # pretty string
            payment_xml_string = tostring(payment_xml_root)
            response = requests.post(self.gateway_url, data=payment_xml_string)
            response_xml = parseString(response.text)
            response_dict = nodeToDic(response_xml)

            return response_dict
        else:
            return self.process_direct_payment(**kwargs)