我试图通过Klarna结帐来验证客户是否在20以上.
它们有一个内置的验证函数,参见这里的https://developers.klarna.com/en/se/kco-v2/checkout/use-cases#validate-checkout-order
checkout.php页面看起来像这个
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
<?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?)
有人知道我做错了什么吗?
发布于 2016-05-12 05:44:25
我们终于开始工作了!
我们只需将此代码添加到验证文件中:
$post_data = json_decode(file_get_contents('php://input'),true);
如下所示:
<?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);
}
?>https://stackoverflow.com/questions/37159687
复制相似问题