paypal的新结账让我觉得不安全,用户不能在无声的一面触发假付款?
提供的代码如下所示
paypal.Button.render({
env: 'sandBox',client: {
sandBox: 'AapGZeCaaDK_q_KPeG19DHnD_kd18vr6BxNe4P6uuhfTKPjIedtNEI9plyDgmzfyI-xGhbxjpv0k-Ha9',production: 'xxxxxxxxx' // u expose the key to client side? is this ok?
},payment: function() {
var env = this.props.env;
var client = this.props.client;
return paypal.rest.payment.create(env,client,{
transactions: [{
amount: { total: ($scope.number_of_uses * 9) + '.00',currency: 'USD' },item_list: {
items: [{
"name": "example","quantity": $scope.number_of_uses,"price": "9.00","currency": "USD"
}]
}
}],redirect_urls: {
"return_url": $location.absUrl(),"cancel_url": $location.absUrl()
}
});
},onAuthorize: function(data,actions) {
return actions.payment.execute().then(function() {
actions.payment.get().then(function(data){
// here I will save data detail to db to record sales
// $http something something
});
});
}
},'#paypal-button');
在条带中,我必须将令牌传递给后面,然后在我的服务器端验证该令牌,如果一切正常则继续记录销售.但在paypal中,似乎这是我需要实现的唯一表达结账的东西.这甚至安全吗?
解决方法
您是正确的,这对更新数据库是不安全的.这是一种安全的付款方式,但是,您无法与客户验证付款是否成功,然后使用onAuthorize方法更新您的数据库.
要验证您的数据库的付款是否成功,您必须使用Server Side REST API.遗憾的是,PayPal文档非常缺乏,但有SDKs文档更具记录性且更易于实现. (Shortcut to Node SDK).
我建议您使用这些来实现数据库的更新. PayPal返回一个参数,告诉您付款成功.