def _bill_credit_card(self, cust, order, bill): api = BaseBillingApi.create_api(cust.campaign.company.enterprise) api.set_coupon(self.request.POST.get('coupon_code')) if api.purchase(order, bill, util.request_ip(self.request)): # accept terms if they sent accept_terms as positive across (checkbox) if ('accept_terms' in self.request.POST and self.request.POST['accept_terms'] == '1'): accept = OrderItemTermsAcceptance() accept.order_id = order.order_id accept.signature = cust.email accept.save() accept.flush() self._apply_payment(cust.customer_id, order.order_id, order.total_price(), api.payment_method) try: order.campaign.send_post_purchase_comm(order) except Exception as exc: #pragma: no cover log.exception(exc) try: order.campaign.send_admin_post_sale_comm(order) except Exception as exc: #pragma: no cover log.exception(exc) return order else: (_, last_note) = api.get_last_status() self.flash('Unable to bill credit card: %s' % last_note) log.error('CC DECLINED %s %s %s' % (cust.customer_id, cust.email, last_note)) self.raise_redirect(self.request.referrer)
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)
def _cancel_order_impl(self, order_id, reason, by_customer=False): codr = CustomerOrder.load(order_id) self.forbid_if(not codr) cust = codr.customer api = BaseBillingApi.create_api(cust.campaign.company.enterprise) if api.cancel_order(codr, cust.billing): Status.add(cust, cust, Status.find_event(self.enterprise_id, cust, 'NOTE'), 'Billing Cancelled at gateway') codr.cancel(reason, by_customer) cust.invalidate_caches()
def test_null_api(self): """ KB: [2012-10-11]: Contrived to get coverage up. """ api = BaseBillingApi.create_api(None) api.purchase(None, None, None) api.get_last_status() api.set_coupon(None) api.is_declined() api.create_token(None, None, None, None, None) api.cancel_order(None, None) api.is_declined() api.get_last_status()