array("API_USERNAME",'input'), 'apipassword' => array("API_PASSWORD",'input'), 'apisignature' => array("API_SIGNATURE",'input'), 'apiversion' => array("API_VERSION",'input'), 'notification' => array('ALLOW_NOTIFICATIONS_FROM_X', 'boolean','0'), 'landingpage' => array('Express Checkout as guest by default', 'boolean','0'), 'cartdetail' => array('SEND_CART_DETAIL', 'boolean','0'), 'displaycheckout' => array('DISPLAY_BUTTON_CHECKOUT', 'boolean','0'), 'displaycart' => array('DISPLAY_BUTTON_CART', 'boolean','0'), 'debug' => array('DEBUG', 'boolean','0'), 'sandbox' => array('SANDBOX', 'boolean','0'), 'return_url' => array('RETURN_URL', 'input'), 'invalid_status' => array('INVALID_STATUS', 'orderstatus'), 'verified_status' => array('VERIFIED_STATUS', 'orderstatus') ); var $multiple = true; var $name = 'paypalexpress'; var $doc_form = 'paypalexpress'; var $button = ''; function __construct(&$subject, $config) { $notif = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment='.$this->name.'&tmpl=component'; $this->pluginConfig['notification'][0] = JText::sprintf('ALLOW_NOTIFICATIONS_FROM_X','Paypal'); $lang = JFactory::getLanguage(); $this->button = '
'; return parent::__construct($subject, $config); } function onPaymentDisplay(&$order,&$methods,&$usable_methods) { } function onAfterOrderConfirm(&$order,&$methods,$method_id) { parent::onAfterOrderConfirm($order,$methods,$method_id); } function getPaymentDefaultValues(&$element) //To set the back end default values { $element->payment_name='PaypalExpress'; $element->payment_description='You can pay by credit card using this payment method'; $element->payment_images='MasterCard,VISA,Credit_card,American_Express'; $element->payment_params->address_type="billing"; $element->payment_params->apiversion='109.0'; $element->payment_params->landingpage=1; $element->payment_params->notification=1; $element->payment_params->invalid_status='cancelled'; $element->payment_params->verified_status='confirmed'; } function onPaymentNotification(&$statuses) { $cartClass = hikashop_get('class.cart'); $cart = $cartClass->loadFullCart(true); $currencyClass = hikashop_get('class.currency'); $currency = $currencyClass->get($cart->full_total->prices[0]->price_currency_id); $config = hikashop_config(); $discountstate = $config->get('discount_before_tax'); $app = JFactory::getApplication(); if(!empty($_SESSION['paypal_express_checkout_payment_method'])){ $this->pluginParams($_SESSION['paypal_express_checkout_payment_method']->payment_id); }else{ $this->pluginParams(); } $menuClass = hikashop_get('class.menus'); $url_menu_id = $menuClass->getCheckoutMenuIdForURL(); $cancel_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=cancel_order'.$url_menu_id; $notify_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment='.$this->name.'&tmpl=component'.$url_menu_id; $return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end'.$url_menu_id; if (isset($cart->full_total->prices[0]->price_value_without_payment_with_tax)) $amountTheorical = round($cart->full_total->prices[0]->price_value_without_payment_with_tax,2); else $amountTheorical = round($cart->full_total->prices[0]->price_value_with_tax,2); $vars = $this->getRequestDatas(); if (isset($vars['setExpressCheckout'])) { if ($this->plugin_params->cartdetail) { $i = 0; $tax = 0; $amountCalculated = 0; $items = array(); $config = hikashop_config(); $group = $config->get('group_options',0); foreach ($cart->products as $p) { $productprice = 0; $optionalProdDesc = ''; if($p->cart_product_quantity<=0) continue; if($group) { if($p->cart_product_option_parent_id) continue; foreach ($cart->products as $p2) { if ($p2->cart_product_option_parent_id==$p->cart_product_id) { if(isset($p2->prices[0]->unit_price)){ $unit2 =& $p2->prices[0]->unit_price; }else{ $unit2 =& $p2->prices[0]; } $productprice += round($unit2->price_value,2); $tax += (round($unit2->price_value_with_tax,2) - round($unit2->price_value,2))*$p->cart_product_quantity; $amountCalculated += $p->cart_product_quantity*round($unit2->price_value,2); $optionalProdDesc .= $p2->product_name.','; } } } if(isset($p->prices[0]->unit_price)){ $unit =& $p->prices[0]->unit_price; }else{ $unit =& $p->prices[0]; } $tax += (round($unit->price_value_with_tax,2) - round($unit->price_value,2))*$p->cart_product_quantity; $amountCalculated += $p->cart_product_quantity*round($unit->price_value,2); $productprice += round($unit->price_value,2); $item = array( 'L_PAYMENTREQUEST_0_NAME'.$i => substr(strip_tags($p->product_name), 0, 126), 'L_PAYMENTREQUEST_0_NUMBER'.$i => $p->product_id, 'L_PAYMENTREQUEST_0_AMT'.$i =>$productprice, 'L_PAYMENTREQUEST_0_QTY'.$i => $p->cart_product_quantity, ); if (!empty($optionalProdDesc)){ $optionalProdDesc = rtrim($optionalProdDesc,','); if(strlen($optionalProdDesc)>=127){ $optionalProdDesc = substr($optionalProdDesc,0,123).'...'; } $item['L_PAYMENTREQUEST_0_DESC'.$i] = $optionalProdDesc; } $i++; $items = array_merge($items,$item); } $shipping = 0; if (!empty($cart->shipping)) $shipping = round($cart->shipping[0]->shipping_price_with_tax,2); $discount = 0; if (!empty($cart->coupon)) $discount = round($cart->coupon->discount_value,2); if ($this->plugin_data->payment_price>0 or $this->plugin_params->payment_percentage>0) { $feesValue = round($this->plugin_data->payment_price + $amountTheorical * $this->plugin_params->payment_percentage / 100,2); $item = array( 'L_PAYMENTREQUEST_0_NAME'.$i => JText::_('HIKASHOP_PAYMENT'), 'L_PAYMENTREQUEST_0_NUMBER'.$i => 99999, //? 'L_PAYMENTREQUEST_0_AMT'.$i => $feesValue, 'L_PAYMENTREQUEST_0_QTY'.$i => 1, ); $amountCalculated += $feesValue; $items = array_merge($items,$item); } $amountTheorical += round($amountTheorical * $this->plugin_params->payment_percentage / 100,2); $amountTheorical += round($this->plugin_data->payment_price,2); $endItem = array( 'PAYMENTREQUEST_0_ITEMAMT' => $amountCalculated, 'PAYMENTREQUEST_0_TAXAMT' => $tax, 'PAYMENTREQUEST_0_SHIPPINGAMT' => $shipping, 'PAYMENTREQUEST_0_SHIPDISCAMT' => -$discount, 'PAYMENTREQUEST_0_HANDLINGAMT' => 0, 'PAYMENTREQUEST_0_AMT' => $amountTheorical, 'PAYMENTREQUEST_0_CURRENCYCODE' => $currency->currency_code, 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'ALLOWNOTE' => 1 ); $varform = array_merge($items,$endItem); } if(empty($this->plugin_params->landingpage)) $this->plugin_params->landingpage = 'Login'; else $this->plugin_params->landingpage ='Billing'; $arrayparams = array( 'USER' => $this->plugin_params->apiuser, 'PWD' => $this->plugin_params->apipassword, 'SIGNATURE' => $this->plugin_params->apisignature, 'VERSION' => $this->plugin_params->apiversion, 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'SOLUTIONTYPE' => 'Sole', 'LANDINGPAGE' => $this->plugin_params->landingpage, 'PAYMENTREQUEST_0_AMT' => $amountTheorical, 'PAYMENTREQUEST_0_CURRENCYCODE' => $currency->currency_code, 'RETURNURL' => $notify_url, 'CANCELURL' => $cancel_url, 'METHOD' => 'SetExpressCheckout' ); if ($this->plugin_params->cartdetail) $varform = array_merge($arrayparams, $varform); else $varform = $arrayparams; $request = $this->initCurlToPaypal($varform,$this->plugin_params->sandbox); $post_response = curl_exec($request); if(empty($post_response)) { $app->enqueueMessage('The connection to the payment plateform did not succeed. It is often caused by the hosting company blocking external connections so you should contact him for further guidance. The cURL error message was: '.curl_error($request),'error'); curl_close ($request); return false; } else { curl_close ($request); $vars = $this->getPostDatas($post_response); $urlstring = $_SERVER['HTTP_REFERER']; $post = $this->getPostDatas($urlstring); if ($vars['ACK']=='Success') { if ($this->plugin_params->sandbox) $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$vars['TOKEN']; else $url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$vars['TOKEN']; $order = $this->createOrder($cart); $orderClass = hikashop_get('class.order'); $order->order_payment_id = $this->plugin_data->payment_id; $order->order_payment_method = $this->name; $order->history->history_data = $vars['TOKEN']; $order->order_id = $orderClass->save($order); $app->redirect($url); } else { $error = 'Connection failure - error code : '.$vars['L_ERRORCODE0'].' , error message : '.$vars['L_LONGMESSAGE0']; if($this->plugin_params->debug){ $this->writeToLog('Fail at step 0 :'.$error); $this->writeToLog(print_r($varform,true)); } $app->enqueueMessage($error); (isset($post['step'])) ? $add = '&step='.$post['step'] : $add = '&step=0'; $app->redirect($cancel_url.$add); return false; } } } else { $datas = $this->loadOrderId($vars['token']); $orderid = $datas[0]->history_order_id; $dbOrder = $this->getOrder($orderid); $this->loadOrderData($dbOrder); if(!empty($dbOrder->order_payment_id)){ $this->pluginParams($dbOrder->order_payment_id); } $cancel_url .= '&order_id='.$orderid.$this->url_itemid; $return_url .= '&order_id='.$orderid.$this->url_itemid; $varform = array( 'USER' => $this->plugin_params->apiuser, 'PWD' => $this->plugin_params->apipassword, 'SIGNATURE' => $this->plugin_params->apisignature, 'VERSION' => $this->plugin_params->apiversion, 'TOKEN' => $vars['token'], 'METHOD' => 'GetExpressCheckoutDetails' ); $request = $this->initCurlToPaypal($varform,$this->plugin_params->sandbox); $post_response = curl_exec($request); if(empty($post_response)) { if($this->plugin_params->debug) $this->writeToLog('Fail at step 1 :'.curl_error($request)); $app->enqueueMessage('The connection to the payment plateform did not succeed. It is often caused by the hosting company blocking external connections so you should contact him for further guidance. The cURL error message was: '.curl_error($request),'error'); curl_close ($request); $this->modifyOrder($orderid, $this->plugin_params->invalid_status, true, true); $app->redirect($cancel_url); return false; } else { curl_close ($request); $vars = $this->getPostDatas($post_response); if ($vars['ACK']!='Success') { if($this->plugin_params->debug) $this->writeToLog('Fail at step 2 :'.curl_error($request)); $app->enqueueMessage('An error has been encountered - error code : '.$vars['L_ERRORCODE0'].' , error message : '.$vars['L_LONGMESSAGE0']); $this->modifyOrder($orderid, $this->plugin_params->invalid_status, true, true); $app->redirect($cancel_url); return false; } else { if (empty($dbOrder->order_user_id)) { $user = $this->createUser($vars); $userClass = hikashop_get('class.user'); $getuser = $userClass->get($vars['EMAIL'],'email'); if (empty($getuser)) $userid = $userClass->save($user); else $userid = $getuser->user_id; if($this->plugin_params->debug) $this->writeToLog('user : '.$userid); } else $userid = $dbOrder->order_user_id; if (!isset($dbOrder->order_shipping_address_id) || $dbOrder->order_shipping_address_id==0) { $address = $this->createAddress($vars,$userid); $addressClass = hikashop_get('class.address'); $addressid = $addressClass->save($address); $dbOrder->order_shipping_address_id = $addressid; $dbOrder->order_billing_address_id = $addressid; } $orderClass = hikashop_get('class.order'); $dbOrder->order_user_id = $userid; $orderClass->save($dbOrder); $varform = array( 'USER' => $this->plugin_params->apiuser, 'PWD' => $this->plugin_params->apipassword, 'SIGNATURE' => $this->plugin_params->apisignature, 'VERSION' => $this->plugin_params->apiversion, 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'PAYERID' => $vars['PAYERID'], 'TOKEN' => $vars['TOKEN'], 'PAYMENTREQUEST_0_AMT' => $amountTheorical, 'PAYMENTREQUEST_0_CURRENCYCODE' => $currency->currency_code, 'METHOD' => 'DoExpressCheckoutPayment' ); $request = $this->initCurlToPaypal($varform,$this->plugin_params->sandbox); $post_response = curl_exec($request); if(empty($post_response)) { if($this->plugin_params->debug) $this->writeToLog('Fail at step 3 :'.curl_error($request)); $app->enqueueMessage('The connection to the payment plateform did not succeed. It is often caused by the hosting company blocking external connections so you should contact him for further guidance. The cURL error message was: '.curl_error($request),'error'); curl_close ($request); $this->modifyOrder($orderid, $this->plugin_params->invalid_status, true, true); $app->redirect($cancel_url); return false; } else { curl_close ($request); $vars = $this->getPostDatas($post_response); if ($vars['ACK']!='Success') { if($this->plugin_params->debug) $this->writeToLog('Fail at step 4 :'.curl_error($request)); $app->enqueueMessage('An error has been encountered - error code : '.$vars['L_ERRORCODE0'].' , error message : '.$vars['L_LONGMESSAGE0']); $this->modifyOrder($orderid, $this->plugin_params->invalid_status, true, true); $app->redirect($cancel_url); return false; } else { if($this->plugin_params->debug) $this->writeToLog('SUCCESS !'); $history = new stdClass(); $history->notified = 1; $history->data = 'PayPal transaction id: '.$vars['PAYMENTINFO_0_TRANSACTIONID'] . "\r\n\r\n"; $this->modifyOrder($orderid, $this->plugin_params->verified_status, $history, true); $this->app->redirect($return_url); return true; } } } } } } function onHikashopBeforeDisplayView(&$element) { $this->pluginParams(); $this->layout = $element->getLayout(); if (isset($element->ctrl)) if($element->ctrl=='checkout' && $this->layout=='step' && $this->canDisplayButton($element)) ob_start(); } function onHikashopAfterDisplayView(&$element) { if (isset($element->ctrl)) { if ($element->ctrl=='product' && $this->layout=='cart' && $element->element->cart_type=='cart' && $this->canDisplayButton($element,'cart')) echo $this->button; elseif($element->ctrl=='checkout' && $this->layout=='step' && $this->canDisplayButton($element)) { $contenttable = array(); $contentth = array(); $inserthtml = '