Example #1
0
 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 client is retrievable.
  *
  * @return void
  */
 public function testGetClient()
 {
     $client = $this->object->getClient();
     $this->assertInstanceOf('GuzzleHttp\\ClientInterface', $client);
     $this->assertSame($this->client, $client);
 }
Example #3
0
 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;
 }
Example #5
0
// 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());
 }
Example #7
0
 /**
  * Sends a HTTP request to the specified url.
  *
  * @param string $method  HTTP method, e.g. 'GET'
  * @param string $url     Request destination
  * @param array  $options Request options
  *
  * @throws ConnectorException When the API replies with an error response
  * @throws RequestException   When an error is encountered
  * @throws \LogicException    When Guzzle cannot populate the response
  *
  * @return ResponseValidator
  */
 protected function request($method, $url, array $options = [])
 {
     $request = $this->connector->createRequest($url, $method, $options);
     return new ResponseValidator($this->connector->send($request));
 }