Exemple #1
0
    def _cancel_subscription(self, customer, order, order_item):
        try:
            xml = render('/crm/billing/authnet_arb_cancel_subscription.xml.mako',
                         {'auth_login' : self.authnet_login_id,
                          'auth_key' : self.authnet_transaction_key,
                          'subscription_id' : order_item.third_party_id
                          })

            headers = {'content-type': 'text/xml'}

            conn = urllib2.Request(url=self._arb_url, data=xml, headers=headers)
            try:
                open_conn = urllib2.urlopen(conn)
                xml_response = open_conn.read()
            except urllib2.URLError: #pragma: no cover
                return (5, '1', 'Could not talk to payment gateway.')

            response = util.xml_str_to_dict(xml_response)['ARBCancelSubscriptionResponse']

            if response['messages']['resultCode'].lower() != 'ok':
                message = response['messages']['message']
                message = message[0] if type(message) == list else message
                self.last_status = message['code']
                self.last_note = message['text']
                return False
            return True
        except Exception as exc2: #pragma: no cover
            self.last_status = -1
            self.last_note = exc2.message
        return False  #pragma: no cover
Exemple #2
0
    def _create_subscription(self, prod, order_item, customer, billing):
        try:
            xml = render('/crm/billing/authnet_arb_create_subscription.xml.mako',
                         {'auth_login' : self.authnet_login_id,
                          'auth_key' : self.authnet_transaction_key,
                          'amount' : order_item.total(),
                          'card_number' : billing.get_cc_num(),
                          'exp_date' : billing.cc_exp,
                          'start_date' : util.format_date(order_item.start_dt) if order_item.start_dt else util.str_today(),
                          'total_occurrences' : 9999,
                          'interval_length' : 1,
                          'interval_unit' : 'months',
                          'sub_name' : '',
                          'first_name' : customer.fname,
                          'last_name' : customer.lname
                          })

            headers = {'content-type': 'text/xml'}

            conn = urllib2.Request(url=self._arb_url, data=xml, headers=headers)
            try:
                open_conn = urllib2.urlopen(conn)
                xml_response = open_conn.read()
            except urllib2.URLError: #pragma: no cover
                return (5, '1', 'Could not talk to payment gateway.')

            response = util.xml_str_to_dict(xml_response)['ARBCreateSubscriptionResponse']
            if response['messages']['resultCode'].lower() != 'ok':
                message = response['messages']['message']
                message = message[0] if type(message) == list else message
                self.last_status = message['code']
                self.last_note = message['text']
                return False
            order_item.third_party_id = response['subscriptionId']
            order_item.save()
            return True
        except Exception as exc2: #pragma: no cover
            self.last_status = -1
            self.last_note = exc2.message
        return False  #pragma: no cover