dongpao1926 2015-06-29 20:39
浏览 14
已采纳

PHP Klarna结帐项目价格问题

I am not very good at programming, but now i am having a learning project for testing a simple php cart

This >> http://www.sanwebe.com/2013/06/creating-simple-shopping-cart-with-php/comment-page-1

And implementing klarna checkout with it.

This klarna >> https://developers.klarna.com/en/se+php/kco-v2/checkout-api

I get it to "work", but not to pass the prices to klarna.

It seems to be something wrong with the format of the price value?

Example: i put something in the basket worth 200.50 USD.

Since klarna uses values without dots and commas i used the following code to clear the $total value.

$extotal = number_format("$total","2","","");

And if i print the value out like this

echo '<strong>Total : '.$extotal.'</strong>  ';

It prints this value 20050 and the original price is 200.50

But when i simply use this value $extotal in klarnas php code like below it dosen't work.

$cart = array(
array(
    'reference' => '123456789',
    'name' => 'Klarna t-shirt',
    'quantity' => 1,
    'unit_price' => $extotal,
    'tax_rate' => 2500
),
array(
    'type' => 'shipping_fee',
    'reference' => 'SHIPPING',
    'name' => 'Shipping Fee',
    'quantity' => 1,
    'unit_price' => 1000,
    'tax_rate' => 2500
));

I get the following message in klarna checkout DIV

string(9) "API Error" array(3) { ["http_status_code"]=> int(400) ["http_status_message"]=> string(11) "Bad Request" ["internal_message"]=> string(32) "Bad format: cart.item.unit_price" }

Can someone give some guidance pls =)

  • 写回答

1条回答 默认 最新

  • dqqs64238 2015-06-30 09:30
    关注

    Thanks to Marc B, i got it to work!

    $int = (int)$extotal;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路