PHP code example of pimcore / payment-provider-klarna

1. Go to this page and download the library: Download pimcore/payment-provider-klarna library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pimcore / payment-provider-klarna example snippets



$url = $this->view->serverUrl();
$config = [
    'purchase_country' => 'AT'
    , 'merchant_reference' => [
        'orderid2' => $paymentInfo->getInternalPaymentId()
    ]
    , 'locale' => 'de-at'
    , 'merchant' => [
        'back_to_store_uri' => $url(['action' => 'payment'])
        , 'terms_uri' => $this->view->serverUrl() . '/agb'
        , 'checkout_uri' => $url(['action' => 'payment']) . '?klarna_order={checkout.order.uri}'
        , 'confirmation_uri' => $url(['action' => 'confirm'], 'payment') . '?klarna_order={checkout.order.uri}'
        , 'push_uri' => $url(['action' => 'confirm'], 'payment') . '?klarna_order={checkout.order.uri}'
        , 'validation_uri' => $this->view->serverUrl() . '/<LINK TO VALIDATE ORDER>?klarna_order={checkout.order.uri}'
    ]
    , 'options' => [
        'color_button' => '#557F0D'
        , 'color_button_text' => '#FFFFFF'
        , 'color_checkbox' => '#FF0000'
        , 'color_checkbox_checkmark' => '#FF0000'
        , 'color_header' => '#EA5B0C'
        , 'color_link' => '#FF0000'
        , 'allow_separate_shipping_address' => true
    ]
];

    $items = [];

    foreach ( $cart->getItems() as $cartItem){

            $item = [];
            $item['reference'] = $cartItem->getProduct()->getOSProductNumber(); // a unique reference for this product / variant
            $item['name'] = $cartItem->getProduct()->getOSName(); 
            $item['quantity'] = (int) $cartItem->getCount();

            $unitPrice = $cartItem->getProduct()->getOSPrice(); // the price for 1 piece
            $item['unit_price'] =  (int) $unitPrice->getAmount()->asRawValue() / 100; // format to integer
            
            $item['discount_rate'] = 0; // mostly implemented via an cart modificator
            $item['tax_rate'] = 0; // can be null, if you don't need tax calculation in the Klarna checkout
            $items[]  = $item; // push it to the items array
     }
     
     $config['cart']['items'] = $items;
bash
php bin/console pimcore:bundle:enable PimcorePaymentProviderKlarnaBundle