Пример #1
0
 /**
  * Make sure the factory returns a instance of the expected type
  *
  * @return void
  */
 public function testFactory()
 {
     $connector = Klarna_Checkout_Connector::create('sharedSecret');
     $this->assertInstanceOf(
         'Klarna_Checkout_ConnectorInterface',
         $connector
     );
 }
Пример #2
0
    /**
     * @return \Klarna_Checkout_ConnectorInterface
     */
    protected function getConnector()
    {
        if ($this->connector) {
            return $this->connector;
        }

        \Klarna_Checkout_Order::$contentType = $this->config->contentType;
        \Klarna_Checkout_Order::$baseUri = $this->config->baseUri;

        return \Klarna_Checkout_Connector::create($this->config->secret);
    }
Пример #3
0
 /**
  * @return \Klarna_Checkout_ConnectorInterface
  */
 protected function getConnector()
 {
     if ($this->connector) {
         return $this->connector;
     }
     \Klarna_Checkout_Order::$contentType = $this->config->contentType;
     \Klarna_Checkout_Order::$baseUri = $this->config->baseUri;
     if (property_exists('Klarna_Checkout_Order', 'accept')) {
         \Klarna_Checkout_Order::$accept = $this->config->acceptHeader;
     }
     return \Klarna_Checkout_Connector::create($this->config->secret);
 }
Пример #4
0
        'quantity' => 2,
        'unit_price' => 12300,
        'discount_rate' => 1000,
        'tax_rate' => 2500
    ),
    array(
        'type' => 'shipping_fee',
        'reference' => 'SHIPPING',
        'name' => 'Shipping Fee',
        'quantity' => 1,
        'unit_price' => 4900,
        'tax_rate' => 2500
    )
);

$connector = Klarna_Checkout_Connector::create($sharedSecret);

if (array_key_exists('klarna_checkout', $_SESSION)) {
    // Resume session
    $order = new Klarna_Checkout_Order(
        $connector,
        $_SESSION['klarna_checkout']
    );
    try {
        $order->fetch();

        // Reset cart
        $update['cart']['items'] = array();
        foreach ($cart as $item) {
            $update['cart']['items'][] = $item;
        }
Пример #5
0
 /**
  * @return bool|null
  */
 function plgVmOnPaymentNotification()
 {
     $virtuemart_paymentmethod_id = vRequest::getInt('pm', '');
     $checkoutId = vRequest::getString('klarna_order', '');
     $cartId = vRequest::getString('cartId', '');
     if (empty($virtuemart_paymentmethod_id) or !$this->selectedThisByMethodId($virtuemart_paymentmethod_id) or empty($checkoutId) or empty($cartId)) {
         return NULL;
     }
     if (!($this->method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
         return NULL;
         // Another method was selected, do nothing
     }
     if (!($cartDataFromTable = $this->getCartFromTable($cartId))) {
         $this->debugLog('No cart with this  Id=' . $cartId, 'plgVmOnPaymentNotification', 'error');
         return NULL;
         // No cart with this  Id
     }
     $this->debugLog($cartDataFromTable, 'plgVmOnPaymentNotification getCartFromTable', 'debug');
     require_once 'klarnacheckout/library/Checkout.php';
     Klarna_Checkout_Order::$contentType = "application/vnd.klarna.checkout.aggregated-order-v2+json";
     $this->initKlarnaParams($this->method);
     $connector = Klarna_Checkout_Connector::create($this->sharedsecret);
     $klarna_order = new Klarna_Checkout_Order($connector, $checkoutId);
     $klarna_order->fetch();
     if ($klarna_order['status'] != "checkout_complete") {
         $this->debugLog($klarna_order, 'plgVmOnPaymentNotification Klarna_Checkout_Order', 'error');
         return NULL;
     }
     // At this point make sure the order is created in your system and send a
     // confirmation email to the customer
     $vmOrderNumber = $this->createVmOrder($klarna_order, $cartDataFromTable, (int) $cartId);
     // update Order status
     $update['status'] = 'created';
     $update['merchant_reference'] = array('orderid1' => $vmOrderNumber);
     $klarna_order->update($update);
     if (!class_exists('VirtueMartModelOrders')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php';
     }
     $values['virtuemart_order_id'] = VirtueMartModelOrders::getOrderIdByOrderNumber($vmOrderNumber);
     $dbValues = array('virtuemart_order_id' => VirtueMartModelOrders::getOrderIdByOrderNumber($vmOrderNumber), 'order_number' => $vmOrderNumber, 'virtuemart_paymentmethod_id' => $this->method->virtuemart_paymentmethod_id, 'payment_name' => $this->renderPluginName($this->method, 'create_order'), 'action' => 'update', 'klarna_status' => $update['status'], 'format' => 'json', 'data' => json_encode($update));
     $this->debugLog($dbValues, 'plgVmOnPaymentNotification update', 'debug');
     //$this->storePSPluginInternalData($dbValues );
     $return = $this->storePluginInternalData($dbValues, 0, 0, false);
     $this->debugLog($return, 'plgVmOnPaymentNotification RETURN', 'debug');
 }
Пример #6
0
 function getKlarnaConnector()
 {
     return Klarna_Checkout_Connector::create($this->_currentMethod->sharedsecret, $this->getKlarnaUrl());
 }
 /**
  * Fetch KCO order.
  *
  * @since  2.0.0
  * @access public
  */
 public function retrieve_klarna_order()
 {
     if ($this->klarna_debug == 'yes') {
         $this->klarna_log->add('klarna', 'Klarna order - ' . $this->klarna_order_uri);
     }
     if (sanitize_key($_GET['klarna-api']) && 'rest' == sanitize_key($_GET['klarna-api'])) {
         $klarna_country = sanitize_key($_GET['scountry']);
         if ($this->klarna_test_mode == 'yes') {
             if ('gb' == $klarna_country) {
                 $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL;
             } elseif ('us' == $klarna_country) {
                 $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::NA_TEST_BASE_URL;
             }
         } else {
             if ('gb' == $klarna_country) {
                 $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::EU_BASE_URL;
             } elseif ('us' == $klarna_country) {
                 $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::NA_BASE_URL;
             }
         }
         $connector = \Klarna\Rest\Transport\Connector::create($this->eid, $this->secret, $klarna_server_url);
         $klarna_order = new \Klarna\Rest\OrderManagement\Order($connector, $this->klarna_order_uri);
     } else {
         $connector = Klarna_Checkout_Connector::create($this->secret, $this->klarna_server);
         $checkoutId = $this->klarna_order_uri;
         $klarna_order = new Klarna_Checkout_Order($connector, $checkoutId);
     }
     $klarna_order->fetch();
     return $klarna_order;
 }
Пример #8
0
            $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL;
        } elseif ('us' == $this->klarna_country) {
            $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::NA_TEST_BASE_URL;
        }
    } else {
        if ('gb' == $this->klarna_country) {
            $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::EU_BASE_URL;
        } elseif ('us' == $this->klarna_country) {
            $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::NA_BASE_URL;
        }
    }
    $connector = \Klarna\Rest\Transport\Connector::create($merchantId, $sharedSecret, $klarna_server_url);
    $klarna_order = new Klarna\Rest\Checkout\Order($connector, $orderUri);
} else {
    // Klarna_Checkout_Order::$contentType = 'application/vnd.klarna.checkout.aggregated-order-v2+json';
    $connector = Klarna_Checkout_Connector::create($sharedSecret, $this->klarna_server);
    $klarna_order = new Klarna_Checkout_Order($connector, $orderUri);
}
try {
    $klarna_order->fetch();
} catch (Exception $e) {
    if (is_user_logged_in() && $this->debug) {
        // The purchase was denied or something went wrong, print the message:
        echo '<div>';
        print_r($e->getMessage());
        echo '</div>';
    }
}
if ($klarna_order['status'] == 'checkout_incomplete') {
    wp_redirect($this->klarna_checkout_url);
    exit;
 /**
  * Pushes Klarna order update in AJAX calls.
  *
  * @since  2.0
  **/
 function ajax_update_klarna_order()
 {
     global $woocommerce;
     // Check if Euro is selected, get correct country
     if ('EUR' == get_woocommerce_currency() && WC()->session->get('klarna_euro_country')) {
         $klarna_c = strtolower(WC()->session->get('klarna_euro_country'));
         $eid = $this->settings["eid_{$klarna_c}"];
         $sharedSecret = $this->settings["secret_{$klarna_c}"];
     } else {
         $eid = $this->klarna_eid;
         $sharedSecret = $this->klarna_secret;
     }
     if ($this->is_rest()) {
         if ($this->testmode == 'yes') {
             if ('gb' == $this->klarna_country) {
                 $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL;
             } elseif ('us' == $this->klarna_country) {
                 $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::NA_TEST_BASE_URL;
             }
         } else {
             if ('gb' == $this->klarna_country) {
                 $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::EU_BASE_URL;
             } elseif ('us' == $this->klarna_country) {
                 $klarna_server_url = Klarna\Rest\Transport\ConnectorInterface::NA_BASE_URL;
             }
         }
         $connector = Klarna\Rest\Transport\Connector::create($eid, $sharedSecret, $klarna_server_url);
         $klarna_order = new \Klarna\Rest\Checkout\Order($connector, WC()->session->get('klarna_checkout'));
     } else {
         $connector = Klarna_Checkout_Connector::create($sharedSecret, $this->klarna_server);
         $klarna_order = new Klarna_Checkout_Order($connector, WC()->session->get('klarna_checkout'));
         $klarna_order->fetch();
     }
     // Process cart contents and prepare them for Klarna
     include_once KLARNA_DIR . 'classes/class-wc-to-klarna.php';
     $wc_to_klarna = new WC_Gateway_Klarna_WC2K($this->is_rest(), $this->klarna_country);
     $cart = $wc_to_klarna->process_cart_contents();
     if (0 == count($cart)) {
         $klarna_order = null;
     } else {
         // Reset cart
         if ($this->is_rest()) {
             $update['order_lines'] = array();
             $klarna_order_total = 0;
             $klarna_tax_total = 0;
             foreach ($cart as $item) {
                 $update['order_lines'][] = $item;
                 $klarna_order_total += $item['total_amount'];
                 // Process sales_tax item differently
                 if (array_key_exists('type', $item) && 'sales_tax' == $item['type']) {
                     $klarna_tax_total += $item['total_amount'];
                 } else {
                     $klarna_tax_total += $item['total_tax_amount'];
                 }
             }
             $update['order_amount'] = $klarna_order_total;
             $update['order_tax_amount'] = $klarna_tax_total;
         } else {
             $update['cart']['items'] = array();
             foreach ($cart as $item) {
                 $update['cart']['items'][] = $item;
             }
         }
         try {
             $klarna_order->update(apply_filters('kco_update_order', $update));
         } catch (Exception $e) {
             if ($this->debug == 'yes') {
                 $this->log->add('klarna', 'KCO ERROR: ' . var_export($e, true));
                 error_log('ERROR: ' . var_export($e, true));
             }
         }
     }
 }