PayPal REST SDK:删除送货地址和付款授权,使其进入待定状态
PayPal REST SDK: Remove shipping address and payment authorization so it does go to pending state
我想向我的客户出售 feature/features 并且付款应该是即时的,以便在交易完成时立即解锁功能。
我成功执行了交易,沙盒个人帐户显示了该交易,但沙盒商家帐户没有显示任何批准交易的信息。沙箱个人账户显示“这是一个临时授权,以确保您的付款方式能够支付款项。当 jawad 商家的测试商店完成您的订单时,您的付款方式将被收取费用。”
这是代码:
var express = require('express');
const router = express.Router();
var paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'client id',
'client_secret': 'client secret'
});
// payment process
router.use('/buy', (req, res) => {
// payment object
var payment = {
"intent": "authorize",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost:4040/xyz/paypal/success",
"cancel_url": "http://localhost:4040/xyz/paypal/err"
},
"transactions": [{
"item_list": {
"items": [{
"name": 'item1',
"sku": "item",
"price": '39',
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"total": 39.00,
"currency": "USD"
},
"description": "A feature "
}]
}
// calling the create Pay method
createPay(payment)
.then((transaction) => {
var id = transaction.id;
var links = transaction.links;
var counter = links.length;
while (counter--) {
if (links[counter].method == 'REDIRECT') {
// redirecting to paypal where user approves the transaction
return res.redirect(links[counter].href)
}
}
})
.catch((err) => {
console.log(err);
res.redirect('/err');
});
});
// success page
router.use('/success', (req, res) => {
var paymentId = req.query.paymentId;
var payerId = { 'payer_id': req.query.PayerID };
paypal.payment.execute(paymentId, payerId, function(error, payment){
if(error){
console.error(error);
} else {
if (payment.state === 'approved'){
res.send('payment completed successfully');
console.log(payment);
} else {
res.send('payment not successful');
}
}
});
})
// error page
router.use('/err', (req, res) => {
console.log(req.query);
res.redirect('https://soundcloud.com/');
})
// helper functions
var createPay = (payment) => {
return new Promise((resolve, reject) => {
paypal.payment.create(payment, function (err, payment) {
if (err) {
reject(err);
}
else {
resolve(payment);
console.log(payment)
}
});
});
}
module.exports = router;
帮我解决以下问题:
我的交易不应链接到送货地址,
交易应该是即时的和paypal个人沙盒账户
不应该这样说:
用户可以购买一项或多项功能,
解释一下最后的辅助函数是做什么的
提前谢谢你。我希望这段代码也能帮助其他人
在经典 API 中有一个 NOSHIPPING 标志,您可以在您的请求中包含该标志,该标志将在结帐时禁用送货地址要求。我知道它在 REST 的某个地方,但我现在正在努力在参考中找到它。
而不是 "authorize" 你应该使用 "sale" 作为 intent 参数。
不确定你在这里问什么..??只需构建您的购物车,这样您的用户就可以将任意数量的商品添加到他们的购物车中,然后将这些购物车详细信息传递到您的 PayPal 付款请求中。
它似乎正在处理对 PayPal 的实际付款调用(即 paypal.payment.create)
本文档展示了按钮代码中 no_shipping 字段的用法:
https://developer.paypal.com/docs/checkout/how-to/customize-flow/#pass-experience-profile-options
要直接调用 API,您必须创建一个包含此字段 (input_fields.no_shipping) 的 Web 体验配置文件对象:
https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_create
然后在您的 /payment 调用中引用它(experience_profile_id 字段)
https://developer.paypal.com/docs/api/payments/v1/#payment
我想向我的客户出售 feature/features 并且付款应该是即时的,以便在交易完成时立即解锁功能。
我成功执行了交易,沙盒个人帐户显示了该交易,但沙盒商家帐户没有显示任何批准交易的信息。沙箱个人账户显示“这是一个临时授权,以确保您的付款方式能够支付款项。当 jawad 商家的测试商店完成您的订单时,您的付款方式将被收取费用。”
这是代码:
var express = require('express');
const router = express.Router();
var paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox', //sandbox or live
'client_id': 'client id',
'client_secret': 'client secret'
});
// payment process
router.use('/buy', (req, res) => {
// payment object
var payment = {
"intent": "authorize",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost:4040/xyz/paypal/success",
"cancel_url": "http://localhost:4040/xyz/paypal/err"
},
"transactions": [{
"item_list": {
"items": [{
"name": 'item1',
"sku": "item",
"price": '39',
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"total": 39.00,
"currency": "USD"
},
"description": "A feature "
}]
}
// calling the create Pay method
createPay(payment)
.then((transaction) => {
var id = transaction.id;
var links = transaction.links;
var counter = links.length;
while (counter--) {
if (links[counter].method == 'REDIRECT') {
// redirecting to paypal where user approves the transaction
return res.redirect(links[counter].href)
}
}
})
.catch((err) => {
console.log(err);
res.redirect('/err');
});
});
// success page
router.use('/success', (req, res) => {
var paymentId = req.query.paymentId;
var payerId = { 'payer_id': req.query.PayerID };
paypal.payment.execute(paymentId, payerId, function(error, payment){
if(error){
console.error(error);
} else {
if (payment.state === 'approved'){
res.send('payment completed successfully');
console.log(payment);
} else {
res.send('payment not successful');
}
}
});
})
// error page
router.use('/err', (req, res) => {
console.log(req.query);
res.redirect('https://soundcloud.com/');
})
// helper functions
var createPay = (payment) => {
return new Promise((resolve, reject) => {
paypal.payment.create(payment, function (err, payment) {
if (err) {
reject(err);
}
else {
resolve(payment);
console.log(payment)
}
});
});
}
module.exports = router;
帮我解决以下问题:
我的交易不应链接到送货地址,
交易应该是即时的和paypal个人沙盒账户 不应该这样说:
用户可以购买一项或多项功能,
解释一下最后的辅助函数是做什么的
提前谢谢你。我希望这段代码也能帮助其他人
在经典 API 中有一个 NOSHIPPING 标志,您可以在您的请求中包含该标志,该标志将在结帐时禁用送货地址要求。我知道它在 REST 的某个地方,但我现在正在努力在参考中找到它。
而不是 "authorize" 你应该使用 "sale" 作为 intent 参数。
不确定你在这里问什么..??只需构建您的购物车,这样您的用户就可以将任意数量的商品添加到他们的购物车中,然后将这些购物车详细信息传递到您的 PayPal 付款请求中。
它似乎正在处理对 PayPal 的实际付款调用(即 paypal.payment.create)
本文档展示了按钮代码中 no_shipping 字段的用法:
https://developer.paypal.com/docs/checkout/how-to/customize-flow/#pass-experience-profile-options
要直接调用 API,您必须创建一个包含此字段 (input_fields.no_shipping) 的 Web 体验配置文件对象:
https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_create
然后在您的 /payment 调用中引用它(experience_profile_id 字段) https://developer.paypal.com/docs/api/payments/v1/#payment