Ejemplo n.º 1
0
 public function startTransaction()
 {
     $this->load->model('payment/' . $this->_paymentMethodName);
     $this->load->model('checkout/order');
     $this->load->model('setting/setting');
     $settings = $this->model_setting_setting->getSetting('paynl');
     $statusPending = $settings[$this->_paymentMethodName . '_pending_status'];
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     // var_dump($order_info);
     $response = array();
     try {
         $apiStart = new Pay_Api_Start();
         $apiStart->setApiToken($settings[$this->_paymentMethodName . '_apitoken']);
         $apiStart->setServiceId($settings[$this->_paymentMethodName . '_serviceid']);
         $returnUrl = $this->url->link('payment/' . $this->_paymentMethodName . '/finish');
         $exchangeUrl = $this->url->link('payment/' . $this->_paymentMethodName . '/exchange');
         $apiStart->setFinishUrl($returnUrl);
         $apiStart->setExchangeUrl($exchangeUrl);
         $apiStart->setPaymentOptionId($this->_paymentOptionId);
         $currency_amount = $this->currency->format($order_info['total'], $order_info['currency_code'], '', false);
         $amount = round($currency_amount * 100);
         $apiStart->setAmount($amount);
         $apiStart->setCurrency($order_info['currency_code']);
         $optionSub = null;
         if (!empty($_POST['optionSubId'])) {
             $optionSub = $_POST['optionSubId'];
             $apiStart->setPaymentOptionSubId($optionSub);
         }
         $apiStart->setDescription($order_info['order_id']);
         $apiStart->setExtra1($order_info['order_id']);
         // Klantdata verzamelen en meesturen
         $strAddress = $order_info['shipping_address_1'] . ' ' . $order_info['shipping_address_2'];
         list($street, $housenumber) = Pay_Helper::splitAddress($strAddress);
         $arrShippingAddress = array('streetName' => $street, 'streetNumber' => $housenumber, 'zipCode' => $order_info['shipping_postcode'], 'city' => $order_info['shipping_city'], 'countryCode' => $order_info['shipping_iso_code_2']);
         $initialsPayment = substr($order_info['payment_firstname'], 0, 10);
         $initialsShipping = substr($order_info['shipping_firstname'], 0, 10);
         $strAddress = $order_info['payment_address_1'] . ' ' . $order_info['payment_address_2'];
         list($street, $housenumber) = Pay_Helper::splitAddress($strAddress);
         $arrPaymentAddress = array('initials' => substr($initialsPayment, 0, 1), 'lastName' => $order_info['payment_lastname'], 'streetName' => $street, 'streetNumber' => $housenumber, 'zipCode' => $order_info['payment_postcode'], 'city' => $order_info['payment_city'], 'countryCode' => $order_info['payment_iso_code_2']);
         $arrEnduser = array('initials' => substr($initialsShipping, 0, 1), 'lastName' => $order_info['shipping_lastname'], 'language' => substr($order_info['language_code'], 0, 2), 'emailAddress' => $order_info['email'], 'address' => $arrShippingAddress, 'invoiceAddress' => $arrPaymentAddress);
         $apiStart->setEnduser($arrEnduser);
         $totalAmount = 0;
         //Producten toevoegen
         foreach ($this->cart->getProducts() as $product) {
             $priceWithTax = $this->tax->calculate($product['price'], $product['tax_class_id'], true);
             $tax = $priceWithTax - $product['price'];
             $price = round($priceWithTax * 100);
             $totalAmount += $price * $product['quantity'];
             $apiStart->addProduct($product['product_id'], $product['name'], $price, $product['quantity'], Pay_Helper::calculateTaxClass($priceWithTax, $tax));
         }
         //            // Shipping costs?
         //            if (isset($this->session->data['shipping_method']['cost']) && $this->session->data['shipping_method']['cost'] != 0) {
         //                $arrShipping = $this->session->data['shipping_method'];
         //                $shippingCost = $this->tax->calculate($arrShipping['cost'], $arrShipping['tax_class_id'], true);
         //                $shippingCost = round($shippingCost*100);
         //                $apiStart->addProduct('0', 'Verzendkosten', $shippingCost, 1, 'H');
         //                $totalAmount += $shippingCost;
         //            }
         //Extra totals rijen
         $total_data = array();
         $total = 0;
         $taxes = $this->cart->getTaxes();
         $this->load->model('setting/extension');
         $results = $this->model_setting_extension->getExtensions('total');
         $taxesForTotals = array();
         foreach ($results as $result) {
             $taxesBefore = array_sum($taxes);
             if ($this->config->get($result['code'] . '_status')) {
                 $this->load->model('total/' . $result['code']);
                 $this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
                 $taxAfter = array_sum($taxes);
                 $taxesForTotals[$result['code']] = $taxAfter - $taxesBefore;
             }
         }
         foreach ($total_data as $total_row) {
             if (!in_array($total_row['code'], array('sub_total', 'tax', 'total'))) {
                 $totalIncl = $total_row['value'] + $taxesForTotals[$total_row['code']];
                 $apiStart->addProduct($total_row['code'], $total_row['title'], round($totalIncl * 100), 1, Pay_Helper::calculateTaxClass($totalIncl, $taxesForTotals[$total_row['code']]));
             }
         }
         $postData = $apiStart->getPostData();
         $result = $apiStart->doRequest();
         //transactie is aangemaakt, nu loggen
         $modelName = 'model_payment_' . $this->_paymentMethodName;
         $this->{$modelName}->addTransaction($result['transaction']['transactionId'], $order_info['order_id'], $this->_paymentOptionId, $amount, $postData, $optionSub);
         $message = 'Pay.nl Transactie aangemaakt. TransactieId: ' . $result['transaction']['transactionId'] . ' .<br />';
         if ($settings[$this->_paymentMethodName . '_send_confirm_email'] == 'start') {
             $this->model_checkout_order->confirm($order_info['order_id'], $statusPending, $message, true);
         }
         $response['success'] = $result['transaction']['paymentURL'];
     } catch (Pay_Api_Exception $e) {
         $response['error'] = "De pay.nl api gaf de volgende fout: " . $e->getMessage();
     } catch (Pay_Exception $e) {
         $response['error'] = "Er is een fout opgetreden: " . $e->getMessage();
     } catch (Exception $e) {
         $response['error'] = "Onbekende fout: " . $e->getMessage();
     }
     die(json_encode($response));
 }
Ejemplo n.º 2
0
 /**
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     //        parent::initContent();
     $cart = $this->context->cart;
     $deliveryAddress = new Address((int) $cart->id_address_delivery);
     $invoiceAddress = new Address((int) $cart->id_address_invoice);
     $paymentOptionId = Tools::getValue('pid');
     $token = Configuration::get('PAYNL_TOKEN');
     $serviceId = Configuration::get('PAYNL_SERVICE_ID');
     $statusPending = Configuration::get('PAYNL_WAIT');
     if (!isset($cart->id)) {
         echo "Can't find cart";
         exit;
     }
     try {
         //validate the order
         $customer = new Customer($cart->id_customer);
         $total = (double) $cart->getOrderTotal(true, Cart::BOTH);
         $orderStatus = Configuration::get('PAYNL_WAIT');
         $module = $this->module;
         $currencyId = $this->context->currency->id;
         $currencyCode = $this->context->currency->iso_code;
         //$paymentMethodName = $module->getPaymentMethodName($paymentOptionId);
         $extraFee = $module->getExtraCosts($paymentOptionId, $total);
         $total += $extraFee;
         //$cart->additional_shipping_cost = $extraFee;
         //$module->validateOrderPay((int) $cart->id, $orderStatus, $total, $extraFee, $module->getPaymentMethodName($paymentOptionId), NULL, array(), (int) $currencyId, false, $customer->secure_key);
         $cartId = $cart->id;
         $apiStart = new Pay_Api_Start();
         //Klantgegevens meesturen
         /* array(
          *  initals
          *  lastName
          *  language
          *  accessCode
          *  gender (M or F)
          *  dob (DD-MM-YYYY)
          *  phoneNumber
          *  emailAddress
          *  bankAccount
          *  iban
          *  bic
          *  sendConfirmMail
          *  confirmMailTemplate
          *  address => array(
          *      streetName
          *      streetNumber
          *      zipCode
          *      city
          *      countryCode
          *  )
          *  invoiceAddress => array(
          *      initials
          *      lastname
          *      streetName
          *      streetNumber
          *      zipCode
          *      city
          *      countryCode
          *  )
          * )
          */
         $language = new Language($cart->id_lang);
         $arrEnduser = array();
         $arrEnduser['language'] = $language->iso_code;
         $arrEnduser['phoneNumber'] = !empty($invoiceAddress->phone) ? $invoiceAddress->phone : $invoiceAddress->phone_mobile;
         $arrEnduser['initials'] = $customer->firstname;
         $arrEnduser['lastName'] = $customer->lastname;
         list($year, $month, $day) = explode('-', $customer->birthday);
         $arrEnduser['dob'] = $day . '-' . $month . '-' . $year;
         $arrEnduser['emailAddress'] = $customer->email;
         // delivery address
         $arrAddress = array();
         $strAddress = $deliveryAddress->address1 . $deliveryAddress->address2;
         $arrStreetHouseNr = Pay_Helper::splitAddress($strAddress);
         $arrAddress['streetName'] = $arrStreetHouseNr[0];
         $arrAddress['streetNumber'] = $arrStreetHouseNr[1];
         $arrAddress['zipCode'] = $deliveryAddress->postcode;
         $arrAddress['city'] = $deliveryAddress->city;
         $country = new Country($deliveryAddress->id_country);
         $arrAddress['countryCode'] = $country->iso_code;
         $arrEnduser['address'] = $arrAddress;
         // invoice address
         $arrAddress = array();
         $arrAddress['initials'] = $customer->firstname;
         $arrAddress['lastName'] = $customer->lastname;
         $strAddress = $invoiceAddress->address1 . $invoiceAddress->address2;
         $arrStreetHouseNr = Pay_Helper::splitAddress($strAddress);
         $arrAddress['streetName'] = $arrStreetHouseNr[0];
         $arrAddress['streetNumber'] = $arrStreetHouseNr[1];
         $arrAddress['zipCode'] = $invoiceAddress->postcode;
         $arrAddress['city'] = $invoiceAddress->city;
         $country = new Country($invoiceAddress->id_country);
         $arrAddress['countryCode'] = $country->iso_code;
         $arrEnduser['invoiceAddress'] = $arrAddress;
         $apiStart->setEnduser($arrEnduser);
         // producten toevoegen
         $products = $cart->getProducts();
         foreach ($products as $product) {
             $apiStart->addProduct($product['id_product'], $product['name'], round($product['price_wt'] * 100), $product['cart_quantity'], 'H');
         }
         //verzendkosten toevoegen
         $shippingCost = $cart->getTotalShippingCost();
         if ($shippingCost != 0) {
             $apiStart->addProduct('SHIPPING', 'Verzendkosten', round($shippingCost * 100), 1, 'H');
         }
         //Inpakservice toevoegen
         if ($cart->gift != 0) {
             $packingCost = $cart->getGiftWrappingPrice(true);
             if ($packingCost != 0) {
                 $apiStart->addProduct('PACKING', 'Inpakservice', round($packingCost * 100), 1, 'H');
             }
         }
         $cartRules = $cart->getCartRules();
         foreach ($cartRules as $cartRule) {
             $apiStart->addProduct('DISCOUNT' . $cartRule['id_cart_rule'], $cartRule['description'], round($cartRule['value_real'] * -100), 1, 'H');
         }
         if ($extraFee != 0) {
             $apiStart->addProduct('PAYMENTFEE', 'Betaalkosten', round($extraFee * 100), 1, 'H');
         }
         $apiStart->setApiToken($token);
         $apiStart->setServiceId($serviceId);
         $description = Configuration::get('PAYNL_DESCRIPTION_PREFIX') . ' ' . $cart->id;
         $description = trim($description);
         $apiStart->setDescription($description);
         $apiStart->setExtra1('CartId: ' . $cart->id);
         $apiStart->setPaymentOptionId($paymentOptionId);
         $finishUrl = Context::getContext()->link->getModuleLink('paynl_paymentmethods', 'return');
         $exchangeUrl = Context::getContext()->link->getModuleLink('paynl_paymentmethods', 'exchange');
         $apiStart->setFinishUrl($finishUrl);
         $apiStart->setExchangeUrl($exchangeUrl);
         $apiStart->setAmount(round($total * 100));
         $apiStart->setCurrency($currencyCode);
         $result = $apiStart->doRequest();
         $startData = $apiStart->getPostData();
         Pay_Helper_Transaction::addTransaction($result['transaction']['transactionId'], $paymentOptionId, round($total * 100), $currencyCode, $cartId, $startData);
         if ($this->module->validateOnStart($paymentOptionId)) {
             $module->validateOrderPay((int) $cart->id, $statusPending, $total, $extraFee, $module->getPaymentMethodName($paymentOptionId), NULL, array('transaction_id' => $result['transaction']['transactionId']), (int) $currencyId, false, $customer->secure_key);
         }
         Tools::redirect($result['transaction']['paymentURL']);
         //$url = $paynl->startTransaction($cart);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     //betaling starten
 }
Ejemplo n.º 3
0
 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'));
     }
 }
Ejemplo n.º 4
0
function fn_paynl_startTransaction($order_id, $order_info, $processor_data, $exchangeUrl, $finishUrl, $paymentOptionSubId = null)
{
    $paynl_setting = Registry::get('addons.paynl_addon');
    $currency = CART_PRIMARY_CURRENCY;
    $payNL = new Pay_Api_Start();
    $payNL->setApiToken($processor_data['processor_params']['token_api']);
    $payNL->setServiceId($processor_data['processor_params']['service_id']);
    $payNL->setAmount(floatval($order_info['total']) * 100);
    $payNL->setPaymentOptionId($processor_data['processor_params']['optionId']);
    if (!empty($paymentOptionSubId)) {
        $payNL->setPaymentOptionSubId($paymentOptionSubId);
    }
    $payNL->setExchangeUrl($exchangeUrl);
    $payNL->setCurrency($currency);
    $payNL->setFinishUrl($finishUrl);
    $payNL->setDescription($order_info['order_id']);
    $s_address = splitAddress(trim($order_info['s_address'] . ' ' . $order_info['s_address_2']));
    $b_address = splitAddress(trim($order_info['b_address'] . ' ' . $order_info['b_address_2']));
    $payNL->setEnduser(array('accessCode' => $order_info['user_id'], 'language' => $order_info['lang_code'], 'initials' => $order_info['s_firstname'], 'lastName' => $order_info['s_lastname'], 'phoneNumber' => $order_info['s_phone'], 'dob' => $order_info['birthday'], 'emailAddress' => $order_info['email'], 'address' => array('streetName' => $s_address[0], 'streetNumber' => substr($s_address[1], 0, 4), 'zipCode' => $order_info['s_zipcode'], 'city' => $order_info['s_city'], 'countryCode' => $order_info['s_country']), 'invoiceAddress' => array('initials' => $order_info['b_firstname'], 'lastname' => $order_info['b_lastname'], 'streetName' => $b_address[0], 'streetNumber' => substr($b_address[1], 0, 4), 'zipCode' => $order_info['b_zipcode'], 'city' => $order_info['b_city'], 'countryCode' => $order_info['b_country'])));
    $payNL->setExtra1($order_id);
    foreach ($order_info['products'] as $key => $product) {
        $payNL->addProduct($product['product_id'], $product['product'], floatval($product['price']) * 100, $product['amount'], 'H');
    }
    if (isset($order_info['subtotal_discount']) && $order_info['subtotal_discount'] > 0) {
        $payNL->addProduct(__('discount'), __('discount'), $order_info['subtotal_discount'] * 100, 1);
    }
    if (!empty($order_info['gift_certificates'])) {
        foreach ($order_info['gift_certificates'] as $k => $v) {
            $v['amount'] = !empty($v['extra']['exclude_from_calculate']) ? 0 : $v['amount'];
            $payNL->addProduct($v['gift_cert_id'], $v['gift_cert_code'], -100 * $v['amount'], 1);
        }
    }
    $surcharge = floatval($order_info['payment_surcharge']);
    $ship = fn_order_shipping_cost($order_info);
    if (floatval($order_info['payment_surcharge'])) {
        $item_name = $order_info['payment_method']['surcharge_title'];
        $payNL->addProduct(substr($item_name, 0, 24), $item_name, floatval($order_info['payment_surcharge']) * 100, 1);
    }
    // Shipping
    $shipping_cost = floatval($order_info['shipping_cost']) * 100;
    if (isset($shipping_cost) && $shipping_cost > 0) {
        $payNL->addProduct('shipping_cost', __('shipping_cost'), $shipping_cost, 1);
    }
    //gift
    if (!empty($order_info['use_gift_certificates'])) {
        foreach ($order_info['use_gift_certificates'] as $k => $v) {
            $payNL->addProduct($v['gift_cert_id'], $k, floatval($v['cost']) * -100, 1);
        }
    }
    try {
        $result = $payNL->doRequest();
        return $result;
    } catch (Exception $ex) {
        fn_set_notification('E', __('error'), $ex->getMessage());
        fn_redirect('/index.php?dispatch=checkout.checkout');
    }
}
Ejemplo n.º 5
0
 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&notif_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&notif_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;
     }
 }