Пример #1
0
    def self_save_billing(self):
        cust = self.request.ctx.customer
        self.forbid_if(cust.campaign.company.enterprise_id != self.enterprise_id)
        bill = cust.billing
        if not bill:
            bill = Billing.create(cust, True)

        bill.set_cc_info(self.request.POST.get('bill_cc_num'), self.request.POST.get('bill_cc_cvv'))
        bill.cc_exp = self.request.POST.get('bill_cc_exp')
        bill.cc_token = self.request.POST.get('bill_cc_token')
        if 'bill_exp_month' in self.request.POST and 'bill_exp_year' in self.request.POST:
            bill.cc_exp = self.request.POST.get('bill_exp_month') + '/' + self.request.POST.get('bill_exp_year')

        bill.bind(self.request.POST, False, 'bill')
        bill.save()
        cust.save()
        self.db_flush()
        api = BaseBillingApi.create_api(cust.campaign.company.enterprise)
        if api.update_billing(cust, bill):
            Status.add(cust, cust, Status.find_event(self.enterprise_id, cust, 'NOTE'),
                       'Billing Updated at gateway')
            self.flash('Successfully saved billing information.')
            cust.invalidate_caches()
            return self.find_redirect()
        else:
            (_, last_note) = api.get_last_status()
            self.flash('Unable to save credit card information: %s' % last_note)
            log.error('CC CHANGE DECLINED %s %s %s' % (cust.customer_id, cust.email, last_note))
            self.raise_redirect(self.request.referrer)
Пример #2
0
 def _create_billing(self, cust):
     bill = Billing.create(cust)
     bill.set_cc_info(self.request.POST.get('bill_cc_num'), self.request.POST.get('bill_cc_cvv'))
     bill.cc_exp = self.request.POST.get('bill_cc_exp')
     bill.cc_token = self.request.POST.get('bill_cc_token')
     if 'bill_exp_month' in self.request.POST and 'bill_exp_year' in self.request.POST:
         bill.cc_exp = self.request.POST.get('bill_exp_month') + '/' + self.request.POST.get('bill_exp_year')
     bill.bind(self.request.POST, False, 'bill')
     cust.billing = bill
     cust.save()
     bill.save()
     return bill