对于我的购物网站,我在前端有一个简单的条纹实现,用户点击"pay through stripe"按钮在弹出窗口中填充CC细节并点击继续 . 如果一切顺利,我会得到一个令牌 $_POST['stripeToken'] ,我会像下面一样处理(用于网络支付)
try
{
$stripe = new Stripe();
$stripe = Stripe::make();
$customer = $stripe->customers()->create([
'email' => $_POST['email_id'],
'source' => $_POST['stripeToken']
]);
$charge = $stripe->charges()->create([
'customer' => $customer['id'],
'amount' => $total_amount, // note this is calculated again on server to prevent fraud
'currency' => 'sgd'
]);
}
catch (\Cartalyst\Stripe\Exception\CardErrorException $e)
{
return view('front.payment_error')->with('message', $e->getMessage());
}
事情是我们不能依赖来自前端表单提交的 $total_amount ,因为用户可以轻松欺骗这个金额,只需支付$ 1条纹并获得一个令牌和欺骗 $total_amount 到 1 从而以他想要的任何价格获得产品,'s why I need to calculate his `$total_amount again on the server (from his cart) and use that to process stripe on the server.If that amount doesn't匹配令牌代表,stripe会自动引发异常并防止欺诈 .
到目前为止很好..但问题来自处理API,移动应用程序将使用自己的库处理条带 . 在客户端,他们只会发送最终版本(用于在db中录制),但显然我不能用它来收费,因为已经在移动设备上完成了 . 因为这些天很容易改变应用程序行为(通过修补apks)或工艺自定义HTTP请求(邮递员),在付款的情况下必须进行服务器检查 .
所以我的问题是如何从令牌验证用户支付的实际金额
即 . 反转 stripeToken => actual paid amount