private function getInstallments() { $email = Configuration::get(self::prefix . 'EMAIL'); $token = Configuration::get(self::prefix . 'TOKEN'); $amount = $this->context->cart->getOrderTotal(true, Cart::BOTH); $installments = new Installments($email, $token); $installments->enableSandBox(Configuration::get(self::prefix . 'SANDBOX')); $response = null; try { $response = $installments->calculate($amount); } catch (ValidationException $e) { return $this->retryInstallments(); } catch (ConnectionException $e) { return $this->retryInstallments(); } return $response; }
/** * Retorna os parcelamentos possíveis via cartão de crédito. * @return array */ public function getInstallments() { $installments = new Installments($this->email, $this->token); try { $sessionCheckout = Mage::getSingleton('checkout/session'); $quoteId = $sessionCheckout->getQuoteId(); $this->quote = Mage::getModel("sales/quote")->load($quoteId); $grandTotal = floatval(number_format($this->quote->getData('grand_total'), 2, '.', '')); $ignoreScheduledDiscount = false; if ($this->sandbox) { $installments->enableSandBox(true); } $response = $installments->calculate($grandTotal, $this->max_installments, $ignoreScheduledDiscount); return array("ok" => true, "installments" => array(0 => $this->prepareInstallmentsCards($response))); } catch (ValidationException $e) { Mage::helper("bcash")->saveLog("ValidationException - Helper_Data->getInstallments:" . $e->getMessage(), $e->getErrors()); return array("ok" => false, "installments" => array("1" => $grandTotal)); } catch (ConnectionException $e) { Mage::helper("bcash")->saveLog("ConnectionException - Helper_Data->getInstallments:" . $e->getMessage(), $e->getErrors()); return array("ok" => false, "installments" => array("1" => $grandTotal)); } }
/** * Método para buscar métodos de pagamentos permitidos pela API * * @return array */ private function getAllowedPaymentMethods() { $methods = array(); $installments = new Installments($this->email, $this->token); try { $installments->enableSandBox($this->sandbox); // Any param value just for check $response = $installments->calculate(100.0, 1, false); // list methods foreach ($response->paymentTypes as $types) { if ($types->name == 'boleto') { foreach ($types->paymentMethods as $method) { $methods[] = $method->id; } } } } catch (ValidationException $e) { Mage::helper("bcash")->saveLog("Form_Bankslip::getAllowedPaymentMethods ValidationException: " . $e->getMessage(), $e->getErrors()); } catch (ConnectionException $e) { Mage::helper("bcash")->saveLog("Form_Bankslip::getAllowedPaymentMethods ConnectionException:" . $e->getMessage(), $e->getErrors()); } return $methods; }