pimcore / payment-provider-klarna
Pimcore 支付提供者 - Klarna
v1.0.4
2024-04-29 11:48 UTC
Requires
- klarna/checkout: ^3.0.0
- pimcore/pimcore: ^10.0.0
Requires (Dev)
- phpstan/phpstan: ^1.9
README
官方 Klarna 文档
测试电子邮件账户
- klarna@green.com ——> 选择支付方式的开发票
- klarna@yellow.com ——> 选择支付方式:开发票 + 信用卡
- klarna@red.com ——> 只能是信用卡
要求
- klarna/checkout
安装
使用 Composer 安装最新版本
composer require pimcore/payment-provider-klarna
在 Pimcore 后端通过控制台或扩展管理器启用插件
php bin/console pimcore:bundle:enable PimcorePaymentProviderKlarnaBundle
配置
<?php $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 ] ];
购物车商品
Klarna 提供商实现目前没有回退到默认结账管理器以提取购物车商品。因此,您必须将它们传递到配置数组 $config['cart']['items']
中。请参阅 "1. 添加购物车商品" https://developers.klarna.com/en/at/kco-v2/checkout/2-embed-the-checkout
实现示例
$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;
最重要的是价格格式,它们必须是整数。例如: 20.00 €
必须变成 2000
。Klarna 只接受整数,以避免四舍五入错误。
这里是所有接受的商品字段列表: https://developers.klarna.com/en/at/kco-v2/checkout-api#cart-item-object-properties