function after_process() { global $customer_id, $order, $insert_id; $paynlService = new Pay_Api_Start(); $paynlService->setAmount(intval($this->format_raw($order->info['total']) * 100)); $paynlService->setApiToken(constant('MODULE_PAYMENT_PAYNL_' . $this->payment_method_description . '_API_TOKEN')); $paynlService->setServiceId(constant('MODULE_PAYMENT_PAYNL_' . $this->payment_method_description . '_SERVICE_ID')); $paynlService->setCurrency(DEFAULT_CURRENCY); $paynlService->setPaymentOptionId($this->payment_method_id); $paynlService->setExchangeUrl($this->generateReturnURL('ext/modules/payment/paynl/paynl_exchange.php?method=' . $this->payment_method_description)); $paynlService->setFinishUrl($this->generateReturnURL('ext/modules/payment/paynl/paynl_exchange.php?method=' . $this->payment_method_description)); $paynlService->setDescription('Order ' . $insert_id); $paynlService->setExtra1($insert_id); $paynlService->setExtra2($customer_id); $b_address = $this->splitAddress(trim($order->billing['street_address'])); $d_address = $this->splitAddress(trim($order->delivery['street_address'])); $paynlService->setEnduser(array('language' => strtoupper($_SESSION['languages_code']), 'initials' => substr($order->delivery['firstname'], 0, 1), 'lastName' => substr($order->delivery['lastname'], 0, 50), 'phoneNumber' => $order->customer['telephone'], 'emailAddress' => $order->customer['email_address'], 'address' => array('streetName' => $d_address[0], 'streetNumber' => substr($d_address[1], 0, 4), 'zipCode' => $order->delivery['postcode'], 'city' => $order->delivery['city'], 'countryCode' => $order->delivery['country']['iso_code_2']), 'invoiceAddress' => array('initials' => substr($order->billing['firstname'], 0, 1), 'lastname' => substr($order->billing['lastname'], 0, 50), 'streetName' => $d_address[0], 'streetNumber' => substr($d_address[1], 0, 4), 'zipCode' => $order->billing['postcode'], 'city' => $order->billing['city'], 'countryCode' => $order->billing['country']['iso_code_2']))); //add products foreach ($order->products as $product) { list($productId) = explode(':', $product['id']); $paynlService->addProduct($productId, $product['name'], $product['final_price'] * 100, $product['qty']); } //add ship cost $paynlService->addProduct('shipcost', $order->info['shipping_method'], $order->info['shipping_cost'] * 100, 1); //add taxes $countTaxes = 1; foreach ($order->info['tax_groups'] as $tax_name => $tax_cost) { if ($tax_cost > 0) { $paynlService->addProduct($countTaxes, $tax_name, $tax_cost * 100, 1); } $countTaxes++; } //add coupon // no information in $order about the discount amount! try { $result = $paynlService->doRequest(); $url = $result['transaction']['paymentURL']; $this->insertPaynlTransaction($result['transaction']['transactionId'], $this->payment_method_id, intval($this->format_raw($order->info['total'])) * 100, $insert_id); zen_redirect($url); } catch (Exception $error) { zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=paynl&paynlErrorMessage=' . urlencode($error->getMessage()), 'SSL')); } }
function onAfterOrderConfirm(&$order, &$methods, $method_id) { parent::onAfterOrderConfirm($order, $methods, $method_id); // This is a mandatory line in order to initialize the attributes of the payment method //Here we can do some checks on the options of the payment method and make sure that every required parameter is set and otherwise display an error message to the user if (empty($this->payment_params->service_id)) { $this->app->enqueueMessage('You have to configure a Service ID for the Pay.nl plugin payment first : check your plugin\'s parameters, on your website backend', 'error'); //Enqueued messages will appear to the user, as Joomla's error messages return false; } elseif (empty($this->payment_params->token_api)) { $this->app->enqueueMessage('You have to configure an api token for the Pay.nl plugin payment first : check your plugin\'s parameters, on your website backend', 'error'); return false; } elseif (empty($this->payment_params->option_id)) { $this->app->enqueueMessage('You have to configure a payment option for the Pay.nl plugin payment first : check your plugin\'s parameters', 'error'); return false; } else { if (!class_exists('Pay_Api_Start')) { require JPATH_SITE . '/plugins/hikashoppayment/paynl/paynl/Api.php'; require JPATH_SITE . '/plugins/hikashoppayment/paynl/paynl/api/Start.php'; require JPATH_SITE . '/plugins/hikashoppayment/paynl/paynl/Exception.php'; require JPATH_SITE . '/plugins/hikashoppayment/paynl/paynl/api/Exception.php'; } if (!class_exists('Pay_Helper')) { require JPATH_SITE . '/plugins/hikashoppayment/paynl/paynl/Helper.php'; } if ($this->currency->currency_locale['int_frac_digits'] > 2) { $this->currency->currency_locale['int_frac_digits'] = 2; } $notify_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=' . $this->name . '&tmpl=component&lang=' . $this->locale . $this->url_itemid; $return_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&user=true&ctrl=checkout&task=notify¬if_payment=' . $this->name . '&order_id=' . $order->order_id . $this->url_itemid; //buyer data $addressBT = $this->splitAddress($order->cart->billing_address->address_street . ' ' . $order->cart->billing_address->address_street2); $addressST = $this->splitAddress($order->cart->shipping_address->address_street . ' ' . $order->cart->shipping_address->address_street2); $lang = JFactory::getLanguage(); $enduser = array('initials' => substr($order->cart->billing_address->address_firstname, 0, 1), 'lastName' => $order->cart->billing_address->address_lastname, 'language' => substr($lang->getTag(), 0, 2), 'emailAddress' => $order->customer->email, 'invoiceAddress' => array('streetName' => $addressBT[0], 'streetNumber' => $addressBT[1], 'city' => $order->cart->billing_address->address_city, 'zipCode' => $order->cart->billing_address->address_post_code, 'countryCode' => $order->cart->billing_address->address_country->zone_code_2), 'address' => array('initials' => substr($order->cart->shipping_address->address_firstname, 0, 1), 'lastName' => $order->cart->shipping_address->address_firstname, 'streetName' => $addressST[0], 'streetNumber' => $addressST[1], 'city' => $order->cart->shipping_address->address_city, 'zipCode' => $order->cart->shipping_address->address_post_code, 'countryCode' => $order->cart->shipping_address->address_country->zone_code_2)); $paynlService = new Pay_Api_Start(); $paynlService->setServiceId($this->payment_params->service_id); $paynlService->setApiToken($this->payment_params->token_api); $paynlService->setPaymentOptionId($this->payment_params->option_id); $paynlService->setAmount(round($order->cart->full_total->prices[0]->price_value_with_tax, 2) * 100); $paynlService->setDescription(JText::_('INVOICE') . ': ' . $order->order_number); $paynlService->setCurrency($this->currency->currency_code); $paynlService->setExchangeUrl($notify_url); $paynlService->setFinishUrl($return_url); $paynlService->setExtra1($order->order_id); $paynlService->setExtra2($order->order_number); $paynlService->setEnduser($enduser); //add items foreach ($order->cart->products as $product) { $amount = round($product->order_product_total_price * 100); if ($amount != 0) { $price = $product->order_product_total_price; $tax = $product->order_product_tax; $taxClass = Pay_Helper::calculateTaxClass($price, $tax); $paynlService->addProduct($product->order_product_id, $product->order_product_name, $amount, $product->order_product_quantity, $taxClass); } } //shipment if (!empty($order->order_shipping_price) && $order->order_shipping_price != 0) { $taxClass = Pay_Helper::calculateTaxClass($order->order_shipping_price, $order->order_shipping_tax); $paynlService->addProduct('shipment', $order->order_shipping_method, round($order->order_shipping_price * 100), 1, $taxClass); } //coupon if (!empty($order->order_discount_price) && $order->order_discount_price != 0) { $taxClass = Pay_Helper::calculateTaxClass($order->order_discount_price, $order->order_discount_tax); $paynlService->addProduct('discount', $order->order_discount_code, round($order->order_discount_price * -100), 1); } //payment if (!empty($order->order_payment_price) && $order->order_payment_price != 0) { $paynlService->addProduct('payment', $order->order_payment_method, round($order->order_payment_price, (int) $this->currency->currency_locale['int_frac_digits']) * 100, 1); } try { $result = $paynlService->doRequest(); } catch (Exception $ex) { die($ex); } $paynlUrl = $result['transaction']['paymentURL']; $this->saveTransaction(array('transaction_id' => $result['transaction']['transactionId'], 'option_id' => $this->payment_params->option_id, 'amount' => round($order->cart->full_total->prices[0]->price_value_with_tax, 2) * 100, 'order_id' => $order->order_id, 'status' => 'PENDING')); $this->app->redirect($paynlUrl); return true; } }