java 金额长度验证_验证条带付款金额

对于我的购物网站,我在前端有一个简单的条纹实现,用户点击"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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值