Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
<?php

date_default_timezone_set('America/Sao_Paulo');
include 'azpay.php';
// Instantiate AZPay
$azpay = new AZPay('00053232', 'xl4fgdwt6ukutyb99772555939853191');
$azpay->curl_timeout = 10;
/*=============================
=            Order            =
=============================*/
$azpay->config_order['reference'] = '123456789';
$azpay->config_order['totalAmount'] = '1000';
$azpay->config_rebill['period'] = '1';
$azpay->config_rebill['frequency'] = '15';
$azpay->config_rebill['dateStart'] = date('Y-m-d', strtotime('today + 1 day'));
$azpay->config_rebill['dateEnd'] = date('Y-m-d', strtotime('today + 1 year'));
/*-----  End of Order  ------*/
/*===============================
=            Billing            =
===============================*/
$azpay->config_billing['customerIdentity'] = '1';
$azpay->config_billing['name'] = 'Fulano de Tal';
$azpay->config_billing['address'] = 'Av. Federativa, 230';
$azpay->config_billing['address2'] = '10 Andar';
$azpay->config_billing['city'] = 'Mogi das Cruzes';
$azpay->config_billing['state'] = 'SP';
$azpay->config_billing['postalCode'] = '20031-170';
$azpay->config_billing['phone'] = '21 4009-9400';
$azpay->config_billing['email'] = '*****@*****.**';
/*-----  End of Billing  ------*/
/*==================================
Ejemplo n.º 3
0
 public function _place(Varien_Object $payment, $amount, $requestType)
 {
     try {
         $order = $payment->getOrder();
         $billingAddress = $order->getBillingAddress();
         $flag = $payment->getCcType();
         $parcels = $payment->getInstallments();
         $parcelMax = Mage::getStoreConfig('payment/azpay_cc/max_installments_' . $flag . '');
         $parcelMinValue = ceil(Mage::getStoreConfig('payment/azpay_cc/min_installment_value_' . $flag . ''));
         $amountTotal = ceil(Mage::helper('azpay')->formatAmount($amount));
         $parcelValue = ceil($amountTotal / $parcels);
         // Check quantity of parcels
         if ($parcels > $parcelMax) {
             return Mage::throwException("Quantidade inválida de parcelas.");
         }
         // Check value of parcel
         if ($parcelValue < $parcelMinValue) {
             return Mage::throwException("Valor da parcela inválido.");
         }
         //AZPay config
         $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_cc/postback');
         $azpay->config_card_payments['amount'] = Mage::helper('azpay')->formatAmount($amount);
         $azpay->config_card_payments['acquirer'] = $this->getConfigData('acquirer_' . $flag . '');
         $azpay->config_card_payments['method'] = $parcels == '1' ? 1 : 2;
         $azpay->config_card_payments['flag'] = $payment->getCcType();
         $azpay->config_card_payments['numberOfPayments'] = $parcels;
         $azpay->config_card_payments['cardHolder'] = $payment->getCcOwner();
         $azpay->config_card_payments['cardNumber'] = Mage::helper('core')->decrypt($payment->getCcNumber());
         $azpay->config_card_payments['cardSecurityCode'] = Mage::helper('core')->decrypt($payment->getCcCid());
         $azpay->config_card_payments['cardExpirationDate'] = $payment->getCcExpYear() . $payment->getCcExpMonth();
         if ($order->getCustomerId()) {
             $azpay->config_billing['customerIdentity'] = $order->getCustomerId();
         } else {
             $azpay->config_billing['customerIdentity'] = $order->getRealOrderId();
         }
         $azpay->config_billing['name'] = $order->getCustomerName();
         $azpay->config_billing['address'] = $billingAddress->getStreet(1);
         $azpay->config_billing['addressNumber'] = $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'] = $billingAddress->getTelephone();
         $azpay->config_billing['email'] = $order->getCustomerEmail();
         //Authorize method
         if ($requestType == "authorize") {
             //Fraud config
             $phoneData = Mage::helper('azpay')->splitTelephone($billingAddress->getTelephone());
             $costumerIP = $payment->getAdditionalInformation('customer_ip');
             $azpay->config_options['fraud'] = "true";
             $azpay->config_options['costumerIP'] = $costumerIP;
             $azpay->config_billing['phonePrefix'] = $phoneData['ddd'];
             $azpay->config_billing['phoneNumber'] = $phoneData['number'];
             foreach ($order->getItemsCollection() as $_item) {
                 $azpay->config_product['productName'] = $_item->getProduct()->getName();
                 $azpay->config_product['quantity'] = $_item->getQtyOrdered();
                 $azpay->config_product['price'] = $_item->getProduct()->getFinalPrice($_item->getQtyOrdered());
             }
             //Prepare authorization to transaction
             $operation = $azpay->authorize();
             //XML to save in log
             $azpay->getXml();
         }
         //Sale method
         if ($requestType == "authorize_capture") {
             //Prepare authorization to direct sale
             $operation = $azpay->sale();
         }
         //Log
         if ($this->getConfigData('log')) {
             Mage::log($azpay, null, "azpay_cc.log");
         }
         //Execute operation
         $operation->execute();
     } catch (AZPay_Error $e) {
         # HTTP 409 - AZPay Error
         $error = $azpay->responseError();
         $response_message = $error['error_message'];
         Mage::log($e->getMessage(), null, "azpay_cc_error.log");
         return Mage::throwException("Ocorreu um erro com o seu pagamento: " . $response_message);
     } catch (AZPay_Curl_Exception $e) {
         # Connection Error
         $response_message = $e->getMessage();
         return Mage::throwException("Ocorreu um erro com o seu pagamento: " . $response_message);
     } catch (AZPay_Exception $e) {
         # General Error
         $response_message = $e->getMessage();
         return Mage::throwException("Ocorreu um erro com o seu pagamento: " . $response_message);
     }
     //Response AZPay
     $gateway_response = $azpay->response();
     //Check response return
     if (!isset($gateway_response)) {
         return Mage::throwException("Ocorreu um erro com a resposta do pagamento");
     }
     $response_status = intval($gateway_response->status);
     $response_message = Config::$STATUS_MESSAGES[$response_status]['title'];
     if ($response_status == Config::$STATUS['AUTHORIZED'] || $response_status == Config::$STATUS['APPROVED']) {
     } else {
         return Mage::throwException("Ocorreu um erro com o seu pagamento: " . $response_message);
     }
     // azpay info
     $payment->setAzpayTransactionId($gateway_response->transactionId);
     return $this;
 }