AAAAhome/academiac/www/plugins/vmpayment/paypal/paypal/helpers/paypalhosted.php 0000604 00000040073 15137407715 0023346 0 ustar 00 _method->sandbox ) { $this->api_login_id = $this->_method->sandbox_api_login_id; $this->api_signature = $this->_method->sandbox_api_signature; $this->api_password = $this->_method->sandbox_api_password; } else { $this->api_login_id = $this->_method->api_login_id; $this->api_signature = $this->_method->api_signature; $this->api_password = $this->_method->api_password; } if (empty($this->api_login_id) || empty($this->api_signature) || empty($this->api_password)) { $text = JText::sprintf('VMPAYMENT_PAYPAL_CREDENTIALS_NOT_SET', $this->_method->payment_name, $this->_method->virtuemart_paymentmethod_id); vmError($text, $text); } if ((empty ($this->_method->payflow_partner) OR empty($this->_method->sandbox_payflow_partner))) { $sandbox = ""; if ($this->_method->sandbox ) { $sandbox = 'SANDBOX_'; } $text = JText::sprintf('VMPAYMENT_PAYPAL_PARAMETER_REQUIRED', JText::_('VMPAYMENT_PAYPAL_' . $sandbox . 'PAYFLOW_PARTNER'), $this->_method->payment_name, $this->_method->virtuemart_paymentmethod_id); vmError($text); } } public function ManageCheckout() { return $this->preparePost(); } // todo check the paypal langauge: can it be sent. Atm sent in the country lanaguge // verfiez la langue, à cause accent function initPostVariables($paypalMethod) { $post_variables = Array(); $post_variables['METHOD'] = $paypalMethod; $post_variables['VERSION'] = self::BM_BUTTON_VERSION; //https://developer.paypal.com/webapps/developer/docs/classic/release-notes/ $post_variables['USER'] = $this->api_login_id; $post_variables['PWD'] = $this->api_password; $post_variables['SIGNATURE'] = $this->api_signature; $post_variables['BUTTONTYPE'] = self::BM_BUTTON_TYPE; $post_variables['BUTTONCODE'] = self::BM_BUTTON_CODE; $post_variables['BUTTONIMAGEURL'] = 'https://www.paypal.com/en_US/i/btn/btn_paynow_SM.gif'; //we automatically redirect to paypal $post_variables['L_BUTTONVAR']['bn'] = self::BNCODE; // Identifies the source that built the code. return $post_variables; } function addBillTo(&$post_variables) { $addressBT = $this->order['details']['BT']; //Bill To $post_variables['L_BUTTONVAR']['billing_address1'] = isset($addressBT->address_1) ? $this->truncate($addressBT->address_1, 60) : ''; $post_variables['L_BUTTONVAR']['billing_address2'] = isset($addressBT->address_2) ? $this->truncate($addressBT->address_2, 60) : ''; $post_variables['L_BUTTONVAR']['billing_city'] = isset($addressBT->city) ? $this->truncate($addressBT->city, 40) : ''; $post_variables['L_BUTTONVAR']['billing_zip'] = isset($addressBT->zip) ? $this->truncate($addressBT->zip, 40) : ''; $post_variables['L_BUTTONVAR']['billing_state'] = isset($addressBT->virtuemart_state_id) ? $this->truncate(ShopFunctions::getStateByID($addressBT->virtuemart_state_id), 20) : ''; $post_variables['L_BUTTONVAR']['billing_country'] = ShopFunctions::getCountryByID($addressBT->virtuemart_country_id, 'country_2_code'); } function addShipTo(&$post_variables) { $addressST = ((isset($this->order['details']['ST'])) ? $this->order['details']['ST'] : $this->order['details']['BT']); //Ship To $post_variables['L_BUTTONVAR']['first_name'] = isset($addressST->first_name) ? $this->truncate($addressST->first_name, 50) : ''; // First name of person the item is being shipped to. $post_variables['L_BUTTONVAR']['last_name'] = isset($addressST->first_name) ? $this->truncate($addressST->address_1, 60) : ''; // Last name of person the item is being shipped to. $post_variables['L_BUTTONVAR']['address1'] = isset($addressST->address_1) ? $this->truncate($addressST->address_1, 60) : ''; $post_variables['L_BUTTONVAR']['address2'] = isset($addressST->address_2) ? $this->truncate($addressST->address_2, 60) : ''; } function addPaymentPageParams(&$post_variables) { $post_variables['L_BUTTONVAR']['template'] = $this->_method->template; if ($this->_method->bordercolor) { $post_variables['L_BUTTONVAR']['bodyBgColor'] = strtoupper($this->_method->bordercolor); $post_variables['L_BUTTONVAR']['payflowcolor'] = '#ff0033'; //str_replace('#','',strtoupper($this->_method->bordercolor)); } $post_variables['L_BUTTONVAR']['headerBgColor'] = strtoupper($this->_method->headerBgColor); $post_variables['L_BUTTONVAR']['headerHeight'] = $this->_method->headerHeight; $post_variables['L_BUTTONVAR']['logoFont'] = $this->_method->logoFont; $post_variables['L_BUTTONVAR']['logoFontSize'] = $this->_method->logoFontSize; $post_variables['L_BUTTONVAR']['logoFontColor'] = $this->_method->logoFontColor; if ($this->_method->bodyBgImg) { $post_variables['L_BUTTONVAR']['bodyBgImg'] = JURI::base() . 'images/stories/virtuemart/payment/' . $this->_method->bodyBgImg; } $post_variables['L_BUTTONVAR']['logoImage'] = $this->getLogoImage(); $post_variables['L_BUTTONVAR']['bodyBgColor'] = $this->_method->bodyBgColor; $post_variables['L_BUTTONVAR']['PageTitleTextColor'] = $this->_method->PageTitleTextColor; $post_variables['L_BUTTONVAR']['PageCollapseBgColor'] = $this->_method->PageCollapseBgColor; //$post_variables['L_BUTTONVAR']['PageCollapseTextColor'] = $this->_method->PageCollapseTextColor; $post_variables['L_BUTTONVAR']['orderSummaryBgColor'] = $this->_method->orderSummaryBgColor; if ($this->_method->orderSummaryBgImage) { $post_variables['L_BUTTONVAR']['orderSummaryBgImage'] = JURI::base() . 'images/stories/virtuemart/payment/' . $this->_method->orderSummaryBgImage; } $post_variables['L_BUTTONVAR']['footerTextColor'] = $this->_method->footerTextColor; $post_variables['L_BUTTONVAR']['footerTextlinkColor'] = $this->_method->footerTextlinkColor; $post_variables['L_BUTTONVAR']['pageButtonBgColor'] = $this->_method->pageButtonBgColor; $post_variables['L_BUTTONVAR']['pageButtonTextColor'] = $this->_method->pageButtonTextColor; $post_variables['L_BUTTONVAR']['pageTitleTextColor'] = $this->_method->pageTitleTextColor; $post_variables['L_BUTTONVAR']['sectionBorder'] = $this->_method->sectionBorder; } function addOrderInfos(&$post_variables) { $post_variables['L_BUTTONVAR']['buyer_email'] = $this->order['details']['BT']->email; //Email address of the buyer. if (is_array($this->order) && is_object($this->order['details']['BT'])) { $post_variables['L_BUTTONVAR']['invoice'] = $this->order['details']['BT']->order_number; } else { if (is_object($this->order)) { $post_variables['L_BUTTONVAR']['invoice'] = $this->order->order_number; } } } function addPrices(&$post_variables) { } function addAmount(&$post_variables) { // Website Payment Standard has separate values for amount and quantity, whereas Hosted Solution uses subtotal only. // Ensure that the subtotal includes the amount you want to charge the buyer, taking into account any applicable discount and the quantity of items. $post_variables['L_BUTTONVAR']['subtotal'] = $this->total; // Amount charged for the transaction. If shipping, handling, Yes and taxes are not specified, this is the total amount charged. $post_variables['L_BUTTONVAR']['currency_code'] = $this->currency_code_3; } function addUrls(&$post_variables) { $post_variables['L_BUTTONVAR']['return'] = JURI::root().'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&paypalproduct=hosted&on=' . $this->order['details']['BT']->order_number . '&pm=' . $this->order['details']['BT']->virtuemart_paymentmethod_id . '&Itemid=' . JRequest::getInt('Itemid').'&lang='. JRequest::getCmd('lang',''); $post_variables['L_BUTTONVAR']['notify_url'] = JURI::root().'index.php?option=com_virtuemart&view=pluginresponse&task=pluginnotification&tmpl=component'.'&lang='. JRequest::getCmd('lang',''); $post_variables['L_BUTTONVAR']['cancel_return'] =JURI::root().'index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel&paypalproduct=hosted&on=' . $this->order['details']['BT']->order_number . '&pm=' . $this->order['details']['BT']->virtuemart_paymentmethod_id . '&Itemid=' . JRequest::getInt('Itemid').'&lang='. JRequest::getCmd('lang',''); } function addConfigPaymentParams(&$post_variables) { $post_variables['L_BUTTONVAR']['address_override'] = $this->_method->address_override; $post_variables['L_BUTTONVAR']['noshipping'] = $this->_method->no_shipping; // for version 104 payment action must be lower case $post_variables['L_BUTTONVAR']['paymentaction'] = strtolower($this->_method->payment_action); // Identifies the source that built the code for the button. } public function preparePost() { $post_variables = $this->initPostVariables('BMCreateButton'); $this->setTimeOut(); $this->addOrderInfos($post_variables); $this->addPrices($post_variables); $this->addBillTo($post_variables); $this->addShipTo($post_variables); $this->addAmount($post_variables); $this->addUrls($post_variables); $this->addConfigPaymentParams($post_variables); $this->addPaymentPageParams($post_variables); $btn = 0; foreach ($post_variables['L_BUTTONVAR'] as $key => $buttonVar) { if (!empty($buttonVar)) { $post_variables['L_BUTTONVAR' . $btn++] = $key . '=' . $buttonVar; } } unset($post_variables['L_BUTTONVAR']); $this->sendRequest($post_variables); $valid = $this->handleResponse(); if ($valid) { //$this->customerData->setVar('token', $this->response['TOKEN']); //$this->customerData->save(); if ($this->_method->template != 'templateD') { $this->redirectToPayPal(); } else { return true; } } else { //$this->customerData->clear(); return false; } return true; } function redirectToPayPal() { $websitecode = $this->response['WEBSITECODE']; $emailink = $this->response['EMAILLINK']; if ($this->_method->debug AND $this->_method->template != 'templateD') { echo '