首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Klarna检查KCO验证

Klarna检查KCO验证
EN

Stack Overflow用户
提问于 2016-05-11 10:19:12
回答 1查看 1.1K关注 0票数 1

我试图通过Klarna结帐来验证客户是否在20以上.

它们有一个内置的验证函数,参见这里的https://developers.klarna.com/en/se/kco-v2/checkout/use-cases#validate-checkout-order

checkout.php页面看起来像这个

代码语言:javascript
复制
Accept: application/vnd.klarna.checkout.aggregated-order-v2+json
Authorization: Klarna pwhcueUff0MmwLShJiBE9JHA==
Content-Type: application/vnd.klarna.checkout.aggregated-order-v2+json

{
    "purchase_country": "se",
    "purchase_currency": "sek",
    "locale": "sv-se",
    "cart": {
        "items": [
            {
                "reference": "123456789",
                "name": "Klarna t-shirt",
                "quantity": 2,
                "unit_price": 12300,
                "discount": 1000,
                "tax_rate": 2500
            },
            {
                "type": "shipping_fee",
                "reference": "SHIPPING",
                "name": "Shipping fee",
                "quantity": 1,
                "unit_price": 4900,
                "tax_rate": 2500
            }
        ]
    },
        "merchant": {
        "id": "0",
        "terms_uri": "http://example.com/terms.php",
        "checkout_uri": "https://example.com/checkout.php",
        "confirmation_uri": "https://example.com/thankyou.php?sid=123&klarna_order={checkout.order.uri}",
        "push_uri": "https://example.com/push.php?sid=123&klarna_order={checkout.order.uri}",
        "validation_uri": "https://example.com/klarna_validation.php"
    }
}

当客户裁剪“立即购买”时,klarna_validation.php脚本将运行,并以HTTPSTAT202OK或303 (参见其他方式)向Klarna发送返回。

下面是我的klarna_validation.php

代码语言:javascript
复制
<?php
    $pno = $_POST['customer']['date_of_birth'];
    $birthdate = new DateTime("$pno");
    $today     = new DateTime();
    $interval  = $today->diff($birthdate);
    $interval2 = $interval->format('%y');
    if($interval2 <= "20"){
    header("Location: https://example.com/too_young.php?$pno", true, 303);
    exit;
    } else {
    http_response_code(200);
    }
?>

根据Klarna:的帖子请求将发送给merchant.validation_uri。请求的主体将包含当前的订单信息。订单信息的结构与获取订单的结果相同,正如您在呈现签出时所看到的那样。

问题是,我没有从$_POST'customer';中获得任何数据,它是空的。

为了验证这个$_POST'customer';是空的,我已经将它包含在too_young.php页面的URL中,如下面(too_young.php?$pno)所示。登陆too_young.php时,$pno是空的!( urls看起来像这个too_young.php?)

有人知道我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-12 05:44:25

我们终于开始工作了!

我们只需将此代码添加到验证文件中:

$post_data = json_decode(file_get_contents('php://input'),true);

如下所示:

代码语言:javascript
复制
<?php

$post_data = json_decode(file_get_contents('php://input'), true);

$pno = $post_data['customer']['date_of_birth'];
$birthdate = new DateTime("$pno");
$today     = new DateTime();
$interval  = $today->diff($birthdate);
$interval2 = $interval->format('%y');
if($interval2 < "60"){
header("Location: https://example.com/too_young.php?$pno&$interval2", true, 303);
exit;
} else {
http_response_code(200);
}
?>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37159687

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档