Example #1
0
 public function _place(Mage_Sales_Model_Order_Payment $payment, $amount)
 {
     try {
         $order = $payment->getOrder();
         $azpay = new AZPay($this->_merchantId, $this->_merchantKey);
         $azpay->curl_timeout = 60;
         $azpay->config_order['reference'] = $order->getRealOrderId();
         $azpay->config_order['totalAmount'] = Mage::helper('azpay')->formatAmount($amount);
         $azpay->config_options['urlReturn'] = Mage::getUrl('azpay/transaction_boleto/postback');
         /*$azpay->config_boleto['acquirer'] = $this->getConfigData('operator');
           $azpay->config_boleto['expire'] = $this->_generateExpirationDate();
           $azpay->config_boleto['nrDocument'] = substr($order->getRealOrderId(), 1);
           $azpay->config_boleto['amount'] = Mage::helper('azpay')->formatAmount($amount);
           $azpay->config_boleto['instructions'] = $this->getConfigData('instructions');*/
         $azpay->config_online_debit['acquirer'] = $this->getConfigData('operator');
         $billingAddress = $order->getBillingAddress();
         if ($order->getCustomerTaxvat()) {
             $azpay->config_billing['customerIdentity'] = $order->getCustomerTaxvat();
         } else {
             $azpay->config_billing['customerIdentity'] = $order->getRealOrderId();
         }
         $azpay->config_billing['name'] = $order->getCustomerName();
         $azpay->config_billing['address'] = $billingAddress->getStreet(1) . ',' . $billingAddress->getStreet(2);
         $azpay->config_billing['address2'] = $billingAddress->getStreet(3) ? $billingAddress->getStreet(3) : '';
         $azpay->config_billing['city'] = $billingAddress->getCity();
         $azpay->config_billing['state'] = $billingAddress->getRegionCode();
         $azpay->config_billing['postalCode'] = Zend_Filter::filterStatic($billingAddress->getPostcode(), 'Digits');
         $azpay->config_billing['phone'] = Mage::helper('azpay')->splitTelephone($billingAddress->getTelephone());
         $azpay->config_billing['email'] = $order->getCustomerEmail();
         $azpay->config_options['urlReturn'] = Mage::getUrl('azpay/transaction_boleto/postback');
         // Execute
         $azpay->online_debit()->execute();
         $azpay->getXml();
         // usado para salvar o XML gerado no log
         // Log
         if ($this->getConfigData('log')) {
             Mage::log($azpay, null, "azpay_boleto.log");
         }
     } catch (AZPay_Error $e) {
         Mage::log($e->getMessage(), null, "azpay_boleto_error.log");
         $error = $azpay->responseError();
         return Mage::throwException("Ocorreu um problema com o seu pedido. Tente novamente ou entre em contato conosco informando este código: " . $error['status_message']);
     }
     // Response
     $gateway_response = $azpay->response();
     $paymentDetails['azpayboletourl'] = (string) $gateway_response->processor->Transfer->urlTransfer;
     $payment->setAdditionalData(serialize($paymentDetails));
     // azpay info
     $payment->setAzpayTransactionId($gateway_response->transactionId)->setAzpayBoletoUrl((string) $gateway_response->processor->Transfer->urlTransfer);
     return $this;
 }