Exemplo n.º 1
0
 /**
  * Test correct contentType is used
  *
  * @return void
  */
 public function testContentType()
 {
     Klarna_Checkout_Order::$contentType = "application/json";
     $this->assertEquals(
         "application/json",
         $this->order->getContentType()
     );
 }
Exemplo n.º 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);
    }
Exemplo n.º 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);
 }
Exemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function apply($method, \Klarna_Checkout_ResourceInterface $resource, array $options = null)
 {
     $previousContentType = \Klarna_Checkout_Order::$contentType;
     $options['url'] = isset($options['url']) ? $options['url'] : $this->baseUri;
     \Klarna_Checkout_Order::$contentType = $this->contentType;
     if ($this->baseUri == $options['url'] && false == isset($options['data']['merchant']['id']) && $this->merchantId) {
         $options['data']['merchant']['id'] = (string) $this->merchantId;
     }
     try {
         $this->internalConnector->apply($method, $resource, $options);
         \Klarna_Checkout_Order::$contentType = $previousContentType;
     } catch (\Exception $e) {
         \Klarna_Checkout_Order::$contentType = $previousContentType;
         throw $e;
     }
 }
 /**
  * @test
  */
 public function shouldSetBaseUrlAndContentTypeBackAfterInternalConnectorThrowsExceptionOnApply()
 {
     \Klarna_Checkout_Order::$baseUri = 'theBaseUri';
     \Klarna_Checkout_Order::$contentType = 'theContentType';
     $internalConnectorMock = $this->createConnectorMock();
     $internalConnectorMock->expects($this->once())->method('apply')->will($this->throwException(new \Exception()));
     $connector = new GlobalStateSafeConnector($internalConnectorMock, 'aMerchantId', 'theOtherBaseUri', 'theOtherContentType');
     $order = new \Klarna_Checkout_Order($connector);
     try {
         $connector->apply('GET', $order);
     } catch (\Exception $e) {
         $this->assertEquals('theBaseUri', \Klarna_Checkout_Order::$baseUri);
         $this->assertEquals('theContentType', \Klarna_Checkout_Order::$contentType);
         return;
     }
     $this->fail('Expect an exception to be thrown');
 }
Exemplo n.º 6
0
 *
 * @category  Payment
 * @package   Klarna_Checkout
 * @author    Klarna <*****@*****.**>
 * @copyright 2012 Klarna AB
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
 * @link      http://developers.klarna.com/
 */

require_once 'src/Klarna/Checkout.php';

session_start();

Klarna_Checkout_Order::$baseUri
    = 'https://checkout.testdrive.klarna.com/checkout/orders';
Klarna_Checkout_Order::$contentType
    = "application/vnd.klarna.checkout.aggregated-order-v2+json";

$order = null;
$eid = '0';
$sharedSecret = 'sharedSecret';
$cart = array(
    array(
        'reference' => '123456789',
        'name' => 'Klarna t-shirt',
        'quantity' => 2,
        'unit_price' => 12300,
        'discount_rate' => 1000,
        'tax_rate' => 2500
    ),
    array(
        'type' => 'shipping_fee',
Exemplo n.º 7
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');
 }