private function _generatePagSeguroRequestData($order, $notify_url, $return_url)
 {
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName('REAL'));
     // currency
     $paymentRequest->setReference($order->order_id);
     // reference
     $paymentRequest->setRedirectURL($return_url);
     // redirect url
     $paymentRequest->setNotificationURL($notify_url);
     // notification url
     $paymentRequest->setItems($this->_generateProductsData($order));
     // products
     $paymentRequest->setExtraAmount($this->_getExtraAmountValues($order));
     // extra values
     $paymentRequest->setSender($this->_generateSenderData($order));
     // sender
     $paymentRequest->setShipping($this->_generateShippingData($order));
     // shipping
     return $paymentRequest;
 }
Beispiel #2
0
 /**
  * Generate PagSeguro Payment Request
  * @return \PagSeguroPaymentRequest
  */
 private function _generatePagSeguroPaymentRequestObject()
 {
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName("REAL"));
     $paymentRequest->setExtraAmount($this->_generateExtraAmount());
     $paymentRequest->setRedirectURL($this->_getPagSeguroRedirectUrl());
     $paymentRequest->setNotificationURL($this->_getPagSeguroNotificationURL());
     $paymentRequest->setItems($this->_generatePagSeguroProductsData());
     $paymentRequest->setSender($this->_generatepagSeguroSenderDataObject());
     $paymentRequest->setShipping($this->_generatePagSeguroShippingDataObject());
     return $paymentRequest;
 }
 /**
  * Create PagSeguro payment request html with payment url
  * @return string
  */
 private function createPaymentRequest()
 {
     $helper = Mage::helper('pagseguro');
     // Get references that stored in the database
     $reference = $helper->getStoreReference();
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName(self::REAL));
     $paymentRequest->setReference($reference . $this->order->getId());
     //Order ID
     $paymentRequest->setShipping($this->getShippingInformation());
     //Shipping
     $paymentRequest->setSender($this->getSenderInformation());
     //Sender
     $paymentRequest->setItems($this->getItensInformation());
     //Itens
     $paymentRequest->setShippingType(SHIPPING_TYPE);
     $paymentRequest->setShippingCost(number_format($this->order->getShippingAmount(), 2, '.', ''));
     $paymentRequest->setNotificationURL($this->getNotificationURL());
     $helper->getDiscount($paymentRequest);
     //Define Redirect Url
     $redirectUrl = $this->getRedirectUrl();
     if (!empty($redirectUrl) and $redirectUrl != null) {
         $paymentRequest->setRedirectURL($redirectUrl);
     } else {
         $paymentRequest->setRedirectURL(Mage::getUrl() . 'checkout/onepage/success/');
     }
     //Define Extra Amount Information
     $paymentRequest->setExtraAmount($this->extraAmount());
     try {
         $paymentUrl = $paymentRequest->register($this->getCredentialsInformation());
     } catch (PagSeguroServiceException $ex) {
         Mage::log($ex->getMessage());
         $this->redirectUrl(Mage::getUrl() . 'checkout/onepage');
     }
     return $paymentUrl;
 }
Beispiel #4
0
 /**
  * Use PagSeguroLibrary
  * 
  * @param type $order_id
  * @return type
  */
 public function payment($order)
 {
     global $woocommerce;
     // Instantiate a new payment request
     $paymentRequest = new PagSeguroPaymentRequest();
     // Set cms version
     PagSeguroLibrary::setCMSVersion('woocommerce-v.' . $woocommerce->version);
     // Set plugin version
     PagSeguroLibrary::setModuleVersion('woocommerce-v.' . $this->plugin_version);
     // Set charset
     PagSeguroConfig::setApplicationCharset($this->charset);
     // Sets the currency
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName("REAL"));
     // Set a reference
     $paymentRequest->setReference($this->invoice_prefix . $order->id);
     //Sets shipping data
     $paymentRequest->setShippingAddress($order->billing_postcode, $order->billing_address_1, '', $order->billing_address_2, '', $order->billing_city, $order->billing_state, $order->billing_country);
     $paymentRequest->setShippingCost($order->order_shipping);
     $paymentRequest->setShippingType(PagSeguroShippingType::getCodeByType('NOT_SPECIFIED'));
     // Sets your customer information.
     $paymentRequest->setSender($order->billing_first_name . ' ' . $order->billing_last_name, $order->billing_email, substr($order->billing_phone, 0, 2), substr($order->billing_phone, 2));
     // Sets the url used by PagSeguro for redirect user after ends checkout process
     if (!empty($this->url_redirect)) {
         $paymentRequest->setRedirectUrl($this->url_redirect);
     } else {
         $paymentRequest->setRedirectUrl($this->get_return_url($order));
     }
     // Sets the url used by PagSeguro for redirect user after ends checkout process
     if (!empty($this->url_notification)) {
         $paymentRequest->setNotificationURL($this->url_notification);
     } else {
         $paymentRequest->setNotificationURL(home_url() . '/index.php?notificationurl=true');
     }
     //Sets Items
     if (sizeof($order->get_items()) > 0) {
         $paymentRequest->setItems($this->setItems($order));
     }
     // Sets the sum of discounts
     $paymentRequest->setExtraAmount(($order->order_discount + $order->cart_discount) * -1 + ($order->order_tax + $order->order_shipping_tax + $order->prices_include_tax));
     try {
         $credentials = new PagSeguroAccountCredentials($this->email, $this->token);
         return $paymentRequest->register($credentials);
     } catch (PagSeguroServiceException $e) {
         $woocommerce->add_error(__('Sorry, unfortunately there was an error during checkout. Please contact the store administrator if the problem persists.', 'wpwcpagseguro'));
         $woocommerce->show_messages();
         wp_die();
     }
 }
Beispiel #5
0
 /**
  *  Generates PagSeguro request data
  */
 private function _generatePagSeguroRequestData()
 {
     $payment_request = new PagSeguroPaymentRequest();
     $payment_request->setCurrency(PagSeguroCurrencies::getIsoCodeByName('Real'));
     /* Currency */
     $payment_request->setExtraAmount($this->_getExtraAmountValues());
     /* Extra amount */
     $payment_request->setItems($this->_generateProductsData());
     /* Products */
     $payment_request->setSender($this->_generateSenderData());
     /* Sender */
     $payment_request->setShipping($this->_generateShippingData());
     /* Shipping */
     if (!Tools::isEmpty(Configuration::get('PAGSEGURO_URL_REDIRECT'))) {
         /* Redirect URL */
         $payment_request->setRedirectURL(Configuration::get('PAGSEGURO_URL_REDIRECT'));
     }
     $this->_payment_request = $payment_request;
 }
 /**
  * Generates PagSeguro request data
  * @param VirtueMartCart $cart
  * @param array $order
  * @param TablePaymentmethods $method
  * @return PagSeguroPaymentRequest
  */
 private function _generatePagSeguroRequestData(VirtueMartCart $cart, array $order, TablePaymentmethods $method)
 {
     $paymentRequest = new PagSeguroPaymentRequest();
     $paymentRequest->setCurrency(PagSeguroCurrencies::getIsoCodeByName('REAL'));
     // currency
     $paymentRequest->setReference($order['details']['BT']->virtuemart_order_id);
     // reference
     $paymentRequest->setRedirectURL($this->_getRedirectUrl($method->pagseguro_url_redirect));
     // redirect url
     $paymentRequest->setNotificationURL($this->_getNotificationUrl($method->pagseguro_url_notification));
     // notification url
     $paymentRequest->setItems($this->_generateProductsData($cart));
     // products
     $paymentRequest->setExtraAmount($this->_getExtraAmountValues($cart));
     // extra values
     $sender = isset($order['details']['ST']) && count($order['details']['ST'] > 0) ? $order['details']['ST'] : $order['details']['BT'];
     $paymentRequest->setSender($this->_generateSenderData($sender));
     // sender
     $paymentRequest->setShipping($this->_generateShippingData($sender, $cart->pricesUnformatted['salesPriceShipment']));
     // shipping
     return $paymentRequest;
 }