public function connector($merchant_id, $secret, $url) { try { $connector = KCConnector::create($merchant_id, $secret, $url); return $connector; } catch (\Exception $e) { $this->log($e->getMessage()); return false; } }
/** * Make sure that the factory method uses the default user agent. * * @return void */ public function testCreateDefaultUserAgent() { $connector = Connector::create(self::MERCHANT_ID, self::SHARED_SECRET, self::BASE_URL); $userAgent = $connector->getUserAgent(); $this->assertInstanceOf('Klarna\\Rest\\Transport\\UserAgent', $userAgent); $this->assertContains('Library/Klarna.kco_rest_php', strval($userAgent)); }
function getKlarnaConnector() { return \Klarna\Rest\Transport\Connector::create($this->_currentMethod->merchantid, $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; }
// Connect to Klarna 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($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>'; }
/** * Make sure that the factory method creates a connector as expected. * * @return void */ public function testCreate() { $userAgent = $this->getMockBuilder('Klarna\\Rest\\Transport\\UserAgent')->getMock(); $connector = Connector::create(self::MERCHANT_ID, self::SHARED_SECRET, self::BASE_URL, $userAgent); $this->assertSame($userAgent, $connector->getUserAgent()); $this->assertEquals(self::BASE_URL, $connector->getClient()->getBaseUrl()); }