Exemplo n.º 1
0
    /**
     * Test that location can be set
     *
     * @return void
     */
    public function testSetLocation()
    {
        $url = "http://foo";
        $this->order->setLocation($url);

        $this->assertEquals($url, $this->order->getLocation());

        $url = 5;
        $this->order->setLocation($url);
        $this->assertInternalType("string", $this->order->getLocation());
    }
    /**
     * Test that update works as intended
     *
     * @return void
     */
    public function testUpdate()
    {
        $this->order->setLocation("http://klarna.com/foo/bar/15");
        $uri = $this->order->getLocation();
        $this->order->update(
            array(
                'foo' => 'boo'
            )
        );

        $this->assertEquals("POST", $this->connector->applied["method"]);
        $this->assertEquals($this->order, $this->connector->applied["resource"]);
        $this->assertArrayHasKey("url", $this->connector->applied["options"]);
        $this->assertEquals($uri, $this->connector->applied["options"]["url"]);
    }
Exemplo n.º 3
0
    $create['locale'] = 'sv-se';
    $create['merchant']['id'] = $eid;
    $create['merchant']['terms_uri'] = 'http://example.com/terms.html';
    $create['merchant']['checkout_uri'] = 'http://example.com/checkout.php';
    $create['merchant']['confirmation_uri']
        = 'http://example.com/confirmation.php' .
        '?sid=123&klarna_order={checkout.order.uri}';
    // You can not receive push notification on non publicly available uri
    $create['merchant']['push_uri'] = 'http://example.com/push.php' .
        '?sid=123&klarna_order={checkout.order.uri}';
    $create['cart'] = array();

    foreach ($cart as $item) {
        $create['cart']['items'][] = $item;
    }

    $order = new Klarna_Checkout_Order($connector);
    $order->create($create);
    $order->fetch();
}

// Store location of checkout session
$_SESSION['klarna_checkout'] = $sessionId = $order->getLocation();

// Display checkout
$snippet = $order['gui']['snippet'];
// DESKTOP: Width of containing block shall be at least 750px
// MOBILE: Width of containing block shall be 100% of browser window (No
// padding or margin)
echo "<div>{$snippet}</div>";
Exemplo n.º 4
0
 function plgVmOnCheckoutAdvertise($cart, &$payment_advertise)
 {
     if ($this->getPluginMethods($cart->vendorId) === 0) {
         return FALSE;
     }
     $virtuemart_paymentmethod_id = 0;
     foreach ($this->methods as $method) {
         if ($cart->virtuemart_paymentmethod_id == $method->virtuemart_paymentmethod_id) {
             $virtuemart_paymentmethod_id = $method->virtuemart_paymentmethod_id;
         }
     }
     if ($virtuemart_paymentmethod_id == 0 or empty($cart->products)) {
         return;
     }
     if (!($this->method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
         return NULL;
         // Another method was selected, do nothing
     }
     // Check if it is the same payment_method_id as the previous one.
     $session = JFactory::getSession();
     $klarna_paymentmethod_id_active = $session->get('klarna_paymentmethod_id_active', '', 'vm');
     if ($klarna_paymentmethod_id_active != $cart->virtuemart_paymentmethod_id) {
         $session->clear('klarna_checkout', 'vm');
         $session->clear('klarna_paymentmethod_id_active', 'vm');
     }
     $return = $this->initKlarnaParams($this->method);
     if (!$return) {
         return;
     }
     $message = '';
     $snippet = '';
     $hide_BTST = true;
     if ($cart->virtuemart_shipmentmethod_id == 0) {
         $message = vmText::sprintf('VMPAYMENT_KLARNACHECKOUT_SELECT_SHIPMENT_FIRST', $this->method->payment_name);
     } else {
         $session = JFactory::getSession();
         require_once 'klarnacheckout/library/Checkout.php';
         $cartIdInTable = $this->storeCartInTable($cart);
         if ($this->method->server == 'beta') {
             Klarna_Checkout_Order::$baseUri = 'https://checkout.testdrive.klarna.com/checkout/orders';
         } else {
             Klarna_Checkout_Order::$baseUri = 'https://checkout.klarna.com/checkout/orders';
         }
         Klarna_Checkout_Order::$contentType = "application/vnd.klarna.checkout.aggregated-order-v2+json";
         //session_start();
         $klarna_checkout = $session->get('klarna_checkout', '', 'vm');
         $connector = Klarna_Checkout_Connector::create($this->sharedsecret);
         $klarnaOrder = null;
         //if (array_key_exists('klarna_checkout', $_SESSION)) {
         if (!empty($klarna_checkout)) {
             // Resume session
             $klarnaOrder = new Klarna_Checkout_Order($connector, $klarna_checkout);
             try {
                 $klarnaOrder->fetch();
                 // Reset cart
                 $update['cart']['items'] = array();
                 $update['cart']['items'] = $this->getCartItems($cart);
                 if (!empty($cart->BT['email'])) {
                     $update['shipping_address']['email'] = $cart->BT['email'];
                     $hide_BTST = false;
                     $address = $cart->ST == 0 ? $cart->BT : $cart->ST;
                     if (isset($address['zip']) and !empty($address['zip'])) {
                         $update['shipping_address']['postal_code'] = $cart->BT['zip'];
                     }
                 }
                 $klarnaOrder->update($update);
                 $this->debugLog($update, 'plgVmOnCheckoutAdvertise update', 'debug');
             } catch (Exception $e) {
                 // Reset session
                 $klarnaOrder = null;
                 //unset($_SESSION['klarna_checkout']);
                 $session->clear('klarna_checkout', 'vm');
                 $session->clear('klarna_paymentmethod_id_active', 'vm');
             }
         }
         if ($klarnaOrder == null) {
             // Start new session
             $create['purchase_country'] = $this->country_code_2;
             $create['purchase_currency'] = $this->currency_code_3;
             $create['locale'] = $this->locale;
             $create['merchant']['id'] = $this->merchantid;
             $create['merchant']['terms_uri'] = $this->getTermsURI($cart->vendorId);
             $create['merchant']['checkout_uri'] = JURI::root() . 'index.php?option=com_virtuemart&view=cart';
             $create['merchant']['confirmation_uri'] = JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&t&pm=' . $virtuemart_paymentmethod_id . '&cartId=' . $cartIdInTable . '&klarna_order={checkout.order.uri}';
             // You can not receive push notification on non publicly available uri
             $create['merchant']['push_uri'] = JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginnotification&tmpl=component&pm=' . $virtuemart_paymentmethod_id . '&cartId=' . $cartIdInTable . '&klarna_order={checkout.order.uri}';
             if (!empty($cart->BT['email'])) {
                 $create['shipping_address']['email'] = $cart->BT['email'];
                 $hide_BTST = false;
                 $address = $cart->ST == 0 ? $cart->BT : $cart->ST;
                 if (isset($address['zip']) and !empty($address['zip'])) {
                     $create['shipping_address']['postal_code'] = $cart->BT['zip'];
                 }
             }
             $create['cart']['items'] = $this->getCartItems($cart, $method);
             try {
                 $klarnaOrder = new Klarna_Checkout_Order($connector);
                 $klarnaOrder->create($create);
                 $klarnaOrder->fetch();
                 $this->debugLog($create, 'plgVmOnCheckoutAdvertise create', 'debug');
             } catch (Exception $e) {
                 $session->clear('klarna_checkout', 'vm');
                 $session->clear('klarna_paymentmethod_id_active', 'vm');
                 $admin_msg = $e->getMessage();
                 vmError($admin_msg, vmText::sprintf('VMPAYMENT_KLARNACHECKOUT_ERROR_OCCURRED', $method->payment_name));
                 $this->debugLog($admin_msg, 'plgVmOnCheckoutAdvertise', 'error');
                 $this->debugLog($create, 'plgVmOnCheckoutAdvertise', 'error');
                 return NULL;
             }
         }
         // Store location of checkout session
         //$_SESSION['klarna_checkout'] = $sessionId = $order->getLocation();
         $session->set('klarna_checkout', $klarnaOrder->getLocation(), 'vm');
         $session->set('klarna_paymentmethod_id_active', $virtuemart_paymentmethod_id, 'vm');
         // Display checkout
         $snippet = $klarnaOrder['gui']['snippet'];
         // DESKTOP: Width of containing block shall be at least 750px
         // MOBILE: Width of containing block shall be 100% of browser window (No
         // padding or margin)
     }
     $payment_advertise[] = $this->renderByLayout('cart_advertisement', array('snippet' => $snippet, 'message' => $message, 'hide_BTST' => $hide_BTST));
 }
Exemplo n.º 5
0
    /**
     * Sample component test
     *
     * @group component
     *
     * @return void
     */
    public function testShow()
    {
        // Start new session
        $banana = array(
            'type' => 'physical',
            'reference' => 'BANAN01',
            'name' => 'Bananana',
            'unit_price' => 450,
            'discount_rate' => 0,
            'tax_rate' => 2500
        );

        $shipping = array(
            'type' => 'shipping_fee',
            'reference' => 'SHIPPING',
            'name' => 'Shipping Fee',
            'unit_price' => 450,
            'discount_rate' => 0,
            'tax_rate' => 2500
        );

        $order = new Klarna_Checkout_Order($this->connector);
        $order->create(
            array(
                'purchase_country' => 'SE',
                'purchase_currency' => 'SEK',
                'locale' => 'sv-se',
                'merchant' => array(
                    'id' => 2,
                    'terms_uri' => 'http://localhost/terms.html',
                    'checkout_uri' => 'http://localhost/checkout.php',
                    'confirmation_uri' =>'http://localhost/thank-you.php',
                    'push_uri' => 'http://localhost/push.php'
                ),
                'cart' => array(
                    'total_price_including_tax' => 9000,
                    'items' => array(
                        $banana,
                        $shipping
                    )
                )
            )
        );

        $this->assertEquals($order->getLocation(), 'test2');
        $order->fetch();
    }