问题描述
我在尝试承诺 paypal-rest-sdk 的 billingPlan 和 billingAgreement 时收到未处理的承诺拒绝警告。我需要承诺它,因为我需要在后端使用 await 但我的编码方式可能有问题。请帮我找出我做错了什么。谢谢!
const Plan = util.promisify(paypal.billingPlan)
const agreement = util.promisify(paypal.billingAgreement)
try{
let billingPlan = await Plan.create(billingPlanAttributes)
try{
let response = await Plan.update(billingPlan.id,billingPlanUpdateAttributes)
console.log('Billing plan create response:::',billingPlan)
console.log("response from updatePlan",response)
try{
let billingAgreement = await agreement.create(billingAgreementAttributes)
console.log("Create Billing Agreement Response");
//console.log(billingAgreement);
for (var index = 0; index < billingAgreement.links.length; index++) {
if (billingAgreement.links[index].rel === 'approval_url') {
var approval_url = billingAgreement.links[index].href;
console.log("For approving subscription via Paypal,first redirect user to");
console.log(approval_url);
console.log("Payment token is");
console.log(url.parse(approval_url,true).query.token);
// See billing_agreements/execute.js to see example for executing agreement
// after you have payment token
}
}
}catch(err){
console.log('error found in agreemtne')
console.log(err)
}
}catch(err){
console.log('error found in updatePlan')
console.log(err)
}
}catch(err){
console.log('error found in createPlan')
console.log(err)
}
}
我收到的错误是- UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: “原始”参数必须是函数类型。在 Object.promisify 接收到一个 Object 实例。请帮忙!
我也尝试对整个 paypal.billingPlan.create、paypal.billingPlan.update 和 paypal.billingAgreement.create 进行承诺,但随后我收到一条错误消息,提示无法读取此 baseURL。这应该是 paypal.billingPlan/paypal.billingAgreement。不确定这条信息是否有价值,但请帮忙
解决方法
您显然在使用已弃用的 REST SDK,并且已弃用的计费协议与当前版本的 Subscriptions API(没有 REST SDK)不兼容。
请勿使用已弃用的 SDK。并且,实施当前版本的 PayPal 订阅。