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'); } }
function geocode($addr) { $addrParts = splitAddress($addr); $a = urlencode($addrParts[0]); $c = urlencode($addrParts[1]); $geocodeURL = "http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_EU/GeocodeServer/findAddressCandidates?Address={$a}&City={$c}&Country=France&outFields=&outSR=&f=pjson"; //$geocodeURL = "http://maps.googleapis.com/maps/api/geocode/json?address=$a&sensor=false"; $ch = curl_init($geocodeURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode == 200) { $geocode = json_decode($result); if (count($geocode->candidates) > 0) { $candidate = $geocode->candidates[0]; $formatted_address = $candidate->address; $lat = $candidate->location->y; $lng = $candidate->location->x; return array($lat, $lng, $formatted_address); } } return array(); }
function geocode($addr) { $addrParts = splitAddress($addr); $a = urlencode($addrParts[0]); $c = urlencode($addrParts[1]); $geocodeURL = "http://www.urbanspoon.com/n/332/"; //$geocodeURL = "http://maps.googleapis.com/maps/api/geocode/json?address=$a&sensor=false"; $ch = curl_init($geocodeURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode == 200) { $geocode = json_decode($result); if (count($geocode->candidates) > 0) { $candidate = $geocode->candidates[0]; $formatted_address = $candidate->address; $lat = $candidate->location->y; $lng = $candidate->location->x; return array($lat, $lng, $formatted_address); } } return array(); }
/** * Process the payment and return the result * * @since 1.0.0 **/ function process_payment($order_id) { global $woocommerce; $klarna_gender = null; $order = wc_get_order($order_id); // Get values from klarna form on checkout page // Collect the DoB $klarna_pno = $this->collect_dob(); // Store Klarna specific form values in order as post meta update_post_meta($order_id, 'klarna_pno', $klarna_pno); $klarna_pclass = isset($_POST['klarna_invoice_pclass']) ? woocommerce_clean($_POST['klarna_invoice_pclass']) : ''; $klarna_gender = isset($_POST['klarna_invoice_gender']) ? woocommerce_clean($_POST['klarna_invoice_gender']) : ''; $klarna_de_consent_terms = isset($_POST['klarna_de_consent_terms']) ? woocommerce_clean($_POST['klarna_de_consent_terms']) : ''; // Split address into House number and House extension for NL & DE customers $klarna_billing = array(); $klarna_shipping = array(); if (isset($_POST['billing_country']) && ($_POST['billing_country'] == 'NL' || $_POST['billing_country'] == 'DE')) { require_once KLARNA_DIR . 'split-address.php'; // Set up billing address array $klarna_billing_address = $order->billing_address_1; $splitted_address = splitAddress($klarna_billing_address); $klarna_billing['address'] = $splitted_address[0]; $klarna_billing['house_number'] = $splitted_address[1]; $klarna_billing['house_extension'] = $splitted_address[2]; // Set up shipping address array $klarna_shipping_address = $order->shipping_address_1; $splitted_address = splitAddress($klarna_shipping_address); $klarna_shipping['address'] = $splitted_address[0]; $klarna_shipping['house_number'] = $splitted_address[1]; $klarna_shipping['house_extension'] = $splitted_address[2]; } else { $klarna_billing['address'] = $order->billing_address_1; $klarna_billing['house_number'] = ''; $klarna_billing['house_extension'] = ''; $klarna_shipping['address'] = $order->shipping_address_1; $klarna_shipping['house_number'] = ''; $klarna_shipping['house_extension'] = ''; } $klarna = new Klarna(); /** * Setup Klarna configuration */ $country = $this->klarna_helper->get_klarna_country(); $this->configure_klarna($klarna, $country); $klarna_order = new WC_Gateway_Klarna_Order($order, $klarna); $klarna_order->prepare_order($klarna_billing, $klarna_shipping, $this->ship_to_billing_address); // Set store specific information so you can e.g. search and associate invoices with order numbers. $klarna->setEstoreInfo($orderid1 = ltrim($order->get_order_number(), '#'), $orderid2 = $order_id, $user = ''); try { // Transmit all the specified data, from the steps above, to Klarna. $result = $klarna->reserveAmount($klarna_pno, $klarna_gender, -1, KlarnaFlags::NO_FLAG, $klarna_pclass); // Prepare redirect url $redirect_url = $order->get_checkout_order_received_url(); // Store the selected pclass in the order update_post_meta($order_id, '_klarna_order_pclass', $klarna_pclass); // Retreive response $invno = $result[0]; switch ($result[1]) { case KlarnaFlags::ACCEPTED: $order->add_order_note(__('Klarna payment completed. Klarna Invoice number: ', 'woocommerce-gateway-klarna') . $invno); if ($this->debug == 'yes') { $this->log->add('klarna', __('Klarna payment completed. Klarna Invoice number: ', 'woocommerce-gateway-klarna') . $invno); } update_post_meta($order_id, '_klarna_order_reservation', $invno); update_post_meta($order_id, '_transaction_id', $invno); $order->payment_complete(); // Payment complete $woocommerce->cart->empty_cart(); // Remove cart // Return thank you redirect return array('result' => 'success', 'redirect' => $redirect_url); break; case KlarnaFlags::PENDING: update_post_meta($order_id, '_klarna_order_reservation', $invno); wp_schedule_single_event(time() + 7200, 'check_klarna_pending', array($order_id)); $order->add_order_note(__('Order is PENDING APPROVAL by Klarna. Please visit Klarna Online for the latest status on this order. Klarna reservation number: ', 'woocommerce-gateway-klarna') . $invno); if ($this->debug == 'yes') { $this->log->add('klarna', __('Order is PENDING APPROVAL by Klarna. Please visit Klarna Online for the latest status on this order. Klarna reservation number: ', 'woocommerce-gateway-klarna') . $invno); } $order->update_status('on-hold'); // Change order status to On Hold $woocommerce->cart->empty_cart(); // Remove cart // Return thank you redirect return array('result' => 'success', 'redirect' => $redirect_url); break; case KlarnaFlags::DENIED: // Order is denied, store it in a database. $order->add_order_note(__('Klarna payment denied.', 'woocommerce-gateway-klarna')); if ($this->debug == 'yes') { $this->log->add('klarna', __('Klarna payment denied.', 'woocommerce-gateway-klarna')); } wc_add_notice(__('Klarna payment denied.', 'woocommerce-gateway-klarna'), 'error'); return; break; default: // Unknown response, store it in a database. $order->add_order_note(__('Unknown response from Klarna.', 'woocommerce-gateway-klarna')); if ($this->debug == 'yes') { $this->log->add('klarna', __('Unknown response from Klarna.', 'woocommerce-gateway-klarna')); } wc_add_notice(__('Unknown response from Klarna.', 'woocommerce-gateway-klarna'), 'error'); return; break; } } catch (Exception $e) { // The purchase was denied or something went wrong, print the message: wc_add_notice(sprintf(__('%s (Error code: %s)', 'woocommerce-gateway-klarna'), utf8_encode($e->getMessage()), $e->getCode()), 'error'); if ($this->debug == 'yes') { $this->log->add('klarna', sprintf(__('%s (Error code: %s)', 'woocommerce-gateway-klarna'), utf8_encode($e->getMessage()), $e->getCode())); } return; } }