/** * @param Mage_Payment_Model_Method_Abstract $payment * @param Mage_Sales_Model_Order $order * @param int $customerId * * @return bool * @throws \Mage_Core_Exception */ protected function processSinglePayment($payment, $order, $customerId) { $uniquePaymentProduct = $this->api()->findOrCreateUniquePaymentProduct(); $this->log(sprintf('Produto para pagamento único: %d.', $uniquePaymentProduct)); $body = ['customer_id' => $customerId, 'payment_method_code' => $this->getPaymentMethodCode(), 'bill_items' => [['product_id' => $uniquePaymentProduct, 'amount' => $order->getGrandTotal()]]]; if ($installments = $payment->getAdditionalInformation('installments')) { $body['installments'] = (int) $installments; } $billId = $this->api()->createBill($body); if (!$billId) { $this->log(sprintf('Erro no pagamento do pedido %d.', $order->getId())); $message = sprintf('Pagamento Falhou. (%s)', $this->api()->lastError); $payment->setStatus(Mage_Sales_Model_Order::STATE_CANCELED, Mage_Sales_Model_Order::STATE_CANCELED, $message, true); Mage::throwException($message); return false; } $order->setVindiBillId($billId); $order->save(); return $billId; }