Пример #1
0
 /**
  * Construtor padrão
  *
  * @param array $settings
  */
 public function __construct($settings = array())
 {
     $this->settings['type'] = self::$TYPE_READ;
     $this->settings['onlyBasic'] = false;
     parent::__construct($settings);
     $this->URI['path'] = '/v2/transactions/';
 }
 public function setVariablesPaymentExecutionView()
 {
     $id_currency = PagSeguro::returnIdCurrency();
     if ($this->context->cart->id_currency != $id_currency && !is_null($id_currency)) {
         $this->setCurrencyVariable($id_currency);
     }
     if (version_compare(_PS_VERSION_, '1.5.0.2', '>=') && version_compare(_PS_VERSION_, '1.6.0.1', '<')) {
         $center_column = '757px';
     }
     if (version_compare(_PS_VERSION_, '1.6.0.1', '>=')) {
         $center_column = '100%';
     } else {
         $center_column = '535px';
     }
     $this->context->smarty->assign(array('version' => _PS_VERSION_, 'width_center_column' => $center_column, 'image_payment' => __PS_BASE_URI__ . 'modules/pagseguro/assets/images/logops_86x49.png', 'nbProducts' => $this->context->cart->nbProducts(), 'current_currency_id' => $this->context->currency->id, 'current_currency_name' => $this->context->currency->name, 'cust_currency' => $this->context->cart->id_currency, 'total' => $this->context->cart->getOrderTotal(true, Cart::BOTH), 'isocode' => $this->context->language->iso_code, 'this_path' => __PS_BASE_URI__, 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/pagseguro/', 'action_url' => _PS_BASE_URL_ . __PS_BASE_URI__ . $this->returnUrlPaymentForVersionModule(), 'checkout' => Configuration::get('PAGSEGURO_CHECKOUT')));
 }
Пример #3
0
 /**
  * Valida os dados de configuração caso falhe dispara uma exceção
  *
  * @throws PagSeguroException
  * @return void
  */
 protected function _settingsValidates()
 {
     parent::_settingsValidates();
     if (!isset($this->settings['currency']) || empty($this->settings['currency'])) {
         throw new PagSeguroException("Erro de configuração - Atributo 'currency' não definido.");
     }
     if ($this->settings['currency'] !== 'BRL') {
         throw new PagSeguroException("Erro de configuração - Atributo 'currency' só aceita o valor 'BRL'.");
     }
 }
 *
 *  @author    PagSeguro Internet Ltda.
 *  @copyright 2007-2014 PagSeguro Internet Ltda.
 *  @license   http://www.apache.org/licenses/LICENSE-2.0
 */
include_once dirname(__FILE__) . '/../../../../config/config.inc.php';
include_once dirname(__FILE__) . '/../../../../init.php';
include_once dirname(__FILE__) . '/../../pagseguro.php';
foreach (Language::getLanguages(false) as $language) {
    if (strcmp($language["iso_code"], 'br') == 0) {
        $idLang = $language["id_lang"];
    }
}
$recovery = "";
$ajaxRequest = Tools::getValue('action');
$pagseguro = new PagSeguro();
switch ($ajaxRequest) {
    case 'singleemail':
        $recoveryCode = Tools::getValue('recovery');
        $idCustomer = Tools::getValue('customer');
        $customer = new Customer((int) $idCustomer);
        $orderMessage = OrderMessage::getOrderMessages($idLang);
        $template = '';
        $message = '';
        foreach ($orderMessage as $key => $value) {
            if (strcmp($value["id_order_message"], Configuration::get('PAGSEGURO_MESSAGE_ORDER_ID')) == 0) {
                $template = $value['name'];
                $message = $value['message'];
            }
        }
        $params = array('{message}' => $message, '{link}' => '<a href="https://pagseguro.uol.com.br/checkout/v2/resume.html?r=' . $recoveryCode . '" target="_blank"> Clique aqui para continuar sua compra </a>');
Пример #5
0
 /**
  * set notification url
  */
 private function _setNotificationUrl()
 {
     $obj_ps = new PagSeguro();
     $this->_payment_request->setNotificationURL($obj_ps->getNotificationUrl());
 }
Пример #6
0
 public function purchase()
 {
     $shipping = UID::get('shipping_options', $this->getPost('shipping_option'));
     $address_id = $this->getPost('address_id');
     if (!$address_id) {
         $this->commitReplace('Informe o endereço de entrega', '#submitmsg');
         $this->commitShow('#submitmsg');
         return;
     }
     $order_id = $this->getQueryString('order_id');
     $cartItems = $this->getCartItems($order_id);
     if (!$order_id) {
         $cart = $this->createCart();
         foreach ($cartItems as $item) {
             $this->addCartItem($cart['id'], $item['id']);
         }
     }
     Session::del('cart');
     $hash = String::generateHash();
     if (!$shipping) {
         $this->commitReplace('Informe o tipo de envio', '#submitmsg');
         $this->commitShow('#submitmsg');
         return;
     }
     $shipping_fields = array('Codigo' => 'shipping_code', 'Valor' => 'shipping_value', 'PrazoEntrega' => 'delivery_time', 'ValorMaoPropria' => 'hand_value', 'ValorAvisoRecebimento' => 'notify_value', 'ValorValorDeclarado' => 'recover_value', 'EntregaDomiciliar' => 'home_delivery', 'EntregaSabado' => 'weekend_delivery');
     $orbit = new Orbit();
     $clientAddr = $orbit->get('client/address/' . $address_id);
     $address = $clientAddr['address'];
     $getCart = array('client_id' => UID::get('id'));
     if (isset($cart['id'])) {
         $getCart['id'] = $cart['id'];
     }
     $request = $orbit->get('request/cart', 1, 1, $getCart);
     if (!isset($request['cart']) || $request['cart'] === 0) {
         $this->commitReplace('Ocorreu um problema na sua sessão. Faça o login novamente.', '#submitmsg');
         $this->commitShow('#submitmsg');
         return;
     }
     $cart = $request['cart'];
     $purchaseData = array();
     foreach ($shipping_fields as $key => $field) {
         $purchaseData[$field] = $shipping[$key];
     }
     $requestItems = $orbit->get('client/cartitems', 1, 100, array('id' => UID::get('id'), 'request_id' => $cart['id']));
     if (!isset($requestItems['cart']) || count($requestItems['cart']) == 0) {
         $this->commitReplace('Não foi possível iniciar a transação. Por favor, entre em contato conosco e nos informe: ' . $requestItems['message'], '#submitmsg');
         $this->commitShow('#submitmsg');
     }
     $cartItems = $requestItems['cart'];
     $pagSeguro = new PagSeguro();
     $totalPrice = 0;
     foreach ($cartItems as $item) {
         //TODO: Quantidade variável
         $pagSeguro->addItem($item['id'], $item['product_name'], $item['price'], '1', $item['weight']);
         $totalPrice += $item['price'];
     }
     $orbit->put('request/' . $cart['id'], array('final_price' => $totalPrice));
     $totalPrice += floatval(str_replace(',', '.', $shipping['Valor']));
     $purchaseData['client_id'] = UID::get('id');
     $purchaseData['request_id'] = $cart['id'];
     $purchaseData['address_id'] = $address_id;
     $purchaseData['pay_hash'] = $hash;
     $purchaseData['price'] = $totalPrice;
     $config = $orbit->get('config');
     $config = current($config['config']);
     $phones = UID::get('phones');
     $area = '';
     $phone = '';
     if (count($phones) > 0) {
         $firstPhone = current($phones);
         $phoneInfo = explode(' ', $firstPhone['phone_number'], 2);
         if (count($phoneInfo) > 1) {
             $area = $phoneInfo[0];
             $phone = str_replace('-', '', $phoneInfo[1]);
         }
     }
     $pagSeguro->addSender(UID::get('client_name'), UID::get('email'), $area, $phone);
     $pagSeguro->addShipping(PagSeguro::getShippingType($purchaseData['shipping_code']), $purchaseData['shipping_value'], $address['street_addr'], $address['street_number'], $address['street_additional'], $address['hood'], $address['city'], $address['zip_code'], $address['state']);
     $pagSeguro->setReference($hash);
     $pagSeguro->setRedirectURL(MAINURL . '/cart/confirmed?order=' . $hash);
     $pagSeguro->setAccountEmail($config['payment_account']);
     $pagSeguro->setToken($config['token']);
     UID::set('purchase_data', $hash, $purchaseData);
     $code = $pagSeguro->submit();
     if ($code) {
         $response = $orbit->put('request/' . $cart['id'], array('pay_hash' => $hash, 'pay_token' => $code));
         $pagSeguro->redirect();
     }
     $submit = $pagSeguro->getResponse();
     if (isset($submit['error'])) {
         $this->commitReplace('Não foi possível iniciar a transação. Por favor, entre em contato conosco e nos informe: ' . $submit['error']['message'], '#submitmsg');
         $this->commitShow('#submitmsg');
     }
 }
Пример #7
0
 public function testGetStatusName()
 {
     $this->assertSame('Situação inválida', PagSeguro::getStatusName(999));
     $this->assertEquals(TransactionStatuses::$map[1], PagSeguro::getStatusName(1));
 }