/** * {@inheritDoc} * * @param CreateOrder $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $model = ArrayObject::ensureArrayObject($request->getModel()); $this->addMerchantId($model); $order = new \Klarna_Checkout_Order($this->getConnector()); $order->create($model->toUnsafeArray()); $request->setOrder($order); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request CreateOrder */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); $order = new \Klarna_Checkout_Order($this->api); $order->create($model->toUnsafeArray()); $order->fetch(); $request->setOrder($order); }
/** * Test that entry point (Base URL) can be changed * * @return void */ public function testCreateAlternativeEntryPoint() { $data = array("foo" => "boo"); $baseUri = "https://checkout.klarna.com/beta/checkout/orders"; Klarna_Checkout_Order::$baseUri = $baseUri; $order = new Klarna_Checkout_Order($this->connector); $order->create($data); $this->assertEquals($baseUri, $this->connector->applied["options"]["url"]); }
$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>";
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)); }
/** * 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(); }
'id' => $method->id, 'name' => $method->label, 'price' => round( ( $method->cost + array_sum( $method->taxes ) ) * 100 ), 'tax_amount' => round( array_sum( $method->taxes ) * 100 ), 'tax_rate' => $tax_rate, 'description' => '', 'preselected' => $preselected ); } } } } $create['shipping_options'] = $shipping_options; */ $klarna_order = new \Klarna\Rest\Checkout\Order($connector); } else { // Klarna_Checkout_Order::$baseUri = $this->klarna_server; // Klarna_Checkout_Order::$contentType = 'application/vnd.klarna.checkout.aggregated-order-v2+json'; $klarna_order = new Klarna_Checkout_Order($connector, $this->klarna_server); } try { $klarna_order->create(apply_filters('kco_create_order', $create)); $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 class="woocommerce-error">'; print_r($e->getMessage()); echo '</div>'; } }
'foo' => 'Foo', 'bar' => 'bar' ) ); $connector = new Klarna_Checkout_Connector( new Klarna_Checkout_HTTP_CURLTransport( new CURLStubFactory ), new Klarna_Checkout_Digest, 'sharedSecret' ); $count = 20000; $start = microtime(true); for ($i = 0; $i < $count; $i++) { $resource->create($connector); $resource->fetch($connector); $resource->update($connector); } $end = microtime(true); echo json_encode( array( 'start' => $start, 'end' => $end, 'duration' => $end - $start, 'count' => $count ) );