def placeOrder(self, data, cart): # disable ZPublisher retries for this request self.request.retry_max_count = 0 conn = self.context._p_jar order_manager = getUtility(IOrderManager) order = Order() conn.add(order) order.shopping_cart = loads(dumps(cart)) # make sure the cart is not in session storage conn.add(order.shopping_cart) order.order_id = order_manager.newOrderId() order.contact_information = self.getContactInformation() conn.add(order.contact_information) order.billing_address = BillingAddressInfo(**data) conn.add(order.billing_address) order.user_id = self.getBuyerUsername() order.processor_id, processor = IPaymentProcessor(getSite()) order.finance_workflow.fireTransition("create") order.bill_phone_number = '' if self.total_is_zero: order.user_payment_info_last4 = None order.name_on_card = None order_manager.store(order) order.finance_workflow.fireTransition("authorize") order.finance_workflow.fireTransition('charge-charging') else: order.user_payment_info_last4 = data['credit_card'][-4:] order.name_on_card = data['name_on_card'] payment_info = PaymentInfo(**data) # XXX Should rewrite to do a single auth_capture if possible result = processor.authorize(order, payment_info) if result is gp_interfaces.keys.results_success: order_manager.store(order) order.finance_workflow.fireTransition("authorize") elif result is gp_interfaces.keys.results_async: # Asynchronous handling of authorization; we don't know status return order else: order.finance_workflow.fireTransition('reviewing-declined') return False return order