function PagSeguroOneOffPay($orderInfo, $params = array()) { require_once OSEMSC_B_LIB . DS . 'PagSeguroLibrary' . DS . 'PagSeguroLibrary.php'; $pConfig = oseMscConfig::getConfig('payment', 'obj'); $account = $pConfig->pagseguro_account; $token = $pConfig->pagseguro_token; $paymentRequest = new PaymentRequest(); $payment = oseRegistry::call('payment'); $paymentOrder = $payment->getInstance('Order'); $billinginfo = $paymentOrder->getBillingInfo($orderInfo->user_id); $address = $billinginfo->addr1 . ' ' . $billinginfo->addr2; $orderInfoParams = oseJson::decode($orderInfo->params); $redirectUrl = urldecode(JROUTE::_(JURI::base() . "index.php?option=com_osemsc&view=thankyou&order_id=" . $orderInfo->order_id)); $redirectUrl = $redirectUrl ? $redirectUrl : JURI::root() . "index.php?option=com_osemsc&view=member"; $des = $this->generateDesc($orderInfo->order_id); // Sets the currency $paymentRequest->setCurrency($orderInfo->payment_currency); // Add an item for this payment request $paymentRequest->addItem($orderInfo->order_id, $des, 1, $orderInfo->payment_price); // Sets a reference code for this payment request, it is useful to identify this payment in future notifications. $paymentRequest->setReference($orderInfo->order_number); // Sets shipping information for this payment request $CODIGO_SEDEX = ShippingType::getCodeByType('SEDEX'); $paymentRequest->setShippingType($CODIGO_SEDEX); $paymentRequest->setShippingAddress('', $address, $billinginfo->telephone, null, null, $billinginfo->city, $billinginfo->state, $billinginfo->country); // Sets your customer information. $paymentRequest->setSender($billinginfo->firstname . ' ' . $billinginfo->lastname, $billinginfo->email, null, null); $redirectUrl = str_replace('https://', '', $redirectUrl); $redirectUrl = str_replace('http://', '', $redirectUrl); $paymentRequest->setRedirectUrl($redirectUrl); $result = array(); $result['payment_method'] = 'pagseguro'; try { $credentials = new AccountCredentials($account, $token); $url = $paymentRequest->register($credentials); $result['success'] = true; $result['url'] = $url; } catch (PagSeguroServiceException $e) { $result['success'] = false; $result['title'] = 'Error'; $result['content'] = $e->getMessage(); //$result['url'] = ''; } return $result; }
function submit() { global $wpdb, $wpsc_cart, $wpsc_gateways; #echo '<pre>'; print_r($this->cart_data); echo '</pre>'; die('fim'); // Instantiate a new payment request $paymentRequest = new PaymentRequest(); // Sets the currency $paymentRequest->setCurrency("BRL"); $pagseguro_freight = $wpsc_cart->selected_shipping_method == $wpsc_gateways['wpsc_merchant_pagseguro']['name']; $freight = 0; if ($pagseguro_freight) { $freight = sprintf('%01.2f', $this->cart_data['cart_tax'] + $this->cart_data['base_shipping']); } foreach ($wpsc_cart->cart_items as $item) { $paymentRequest->addItem($item->product_id, $item->product_name, $item->quantity, $item->unit_price, intval(round($item->weight * 453.59237)), $freight); } // Sets a reference code for this payment request, it's useful to identify this payment in future notifications. $paymentRequest->setReference($this->cart_data['session_id']); $collected_data = array(); $checkout_form_sql = "SELECT id, unique_name FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "`"; $checkout_form = $wpdb->get_results($checkout_form_sql, ARRAY_A); // Pega a referência dos campos de formulário definido pelo usuário foreach ($checkout_form as $item) { $collected_data[$item['unique_name']] = $item['id']; } // Pega os dados do post $_client = $_POST["collected_data"]; list($prefix, $phone) = splitPhone($_client[if_isset($collected_data['billingphone'])]); $street = explode(',', $_client[if_isset($collected_data['billingaddress'])]); $street = array_slice(array_merge($street, array("", "", "", "")), 0, 4); list($address, $number, $complement, $neighborhood) = $street; // Sets your customer information. $paymentRequest->setSender($_client[if_isset($collected_data['billingfirstname'])] . ' ' . $_client[if_isset($collected_data['billinglastname'])], $_client[if_isset($collected_data['billingemail'])], $prefix, $phone); # $shipping = get_option('pagseguro_shipping_configs'); // Get the freight data if ($pagseguro_freight) { $freight_type = strtoupper($wpsc_cart->selected_shipping_option); $FREIGHT_CODE = 0; if ($freight_type == 'PAC') { $FREIGHT_CODE = ShippingType::getCodeByType('PAC'); } elseif ($freight_type == 'SEDEX') { $FREIGHT_CODE = ShippingType::getCodeByType('SEDEX'); } if ($FREIGHT_CODE > 0) { $paymentRequest->setShippingType($FREIGHT_CODE); $paymentRequest->setShippingAddress($_client[if_isset($collected_data['shippingpostcode'])], $address, $number, $complement, $neighborhood, $_client[if_isset(utf8_decode($collected_data['shippingcity']))], $_client[if_isset(utf8_decode($collected_data['shippingstate']))], $wpsc_gateways['wpsc_merchant_pagseguro']['supported_iso_codes'][$_client[if_isset($collected_data['shippingcountry'])]]); } } $extra = 0; if ($this->cart_data['has_discounts']) { $extra = $this->cart_data['cart_discount_value'] * -1; } $paymentRequest->setExtraAmount($extra); #$paymentRequest->setRedirectUrl($this->cart_data['transaction_results_url']); $paymentRequest->setRedirectUrl('http://homologacao.visie.com.br/bibliotecas/pagseguro/opencart1505/notification.php'); // Pegando as configurações definidas no admin do módulo $email = get_option('pagseguro_email'); $token = get_option("pagseguro_token"); /** * Você pode utilizar o método getData para capturar as credenciais * do usuário (email e token) * $email = PagSeguroConfig::getData('credentials', 'email'); * $token = PagSeguroConfig::getData('credentials', 'token'); */ try { /** * #### Crendenciais ##### * Se desejar, utilize as credenciais pré-definidas no arquivo de configurações * $credentials = PagSeguroConfig::getAccountCredentials(); */ $credentials = new AccountCredentials($email, $token); if ($geteway_url = $paymentRequest->register($credentials)) { $_SESSION["pagseguro_id"] = $sessionid; $wpsc_cart->empty_cart(); wp_redirect($geteway_url); exit; } } catch (PagSeguroServiceException $e) { die($e->getMessage()); } }