PayPal 账单协议 - 无效的计划 ID .NET
Posted
技术标签:
【中文标题】PayPal 账单协议 - 无效的计划 ID .NET【英文标题】:PayPal Billing Agreement - Invalid Plan Id .NET 【发布时间】:2020-10-05 01:10:06 【问题描述】:我正在尝试使用 .NET SDK 在 PayPal 中创建新协议,但是当我将我的协议连同我的计划和协议详细信息发送到 PayPal API 时,我收到了 400 Bad Request
错误。经过进一步调查,我发现这是由于Plan Id
无效,但我不知道为什么会这样,因为我已经在模型、BillingPlansController
和 PayPal 仪表板中创建了它。
这是来自 PayPal API 的响应 Json:
"name":"TEMPLATE_ID_INVALID",
"debug_id":"9e24570510a3e",
"message":"",
"information_link":"https://developer.paypal.com/docs/api/payments.billing-agreements#errors",
"details":[
"field":"validation_error",
"issue":"Incorrect Plan Id."
]
这是我的Plan
模型,我在其中创建了要在我的应用程序中使用的计划。
public class Plan
public string PayPalPlanId get; set;
public string Name get; set;
public decimal Price get; set;
public int NumberOfEmployees get; set;
public string Description get; set;
public static List<Plan> Plans => new List<Plan>()
new Plan()
Name = "Starter Subscription",
Price = 30,
PayPalPlanId = "P-27H34871BG666983A2CPYWUI",
NumberOfEmployees = 1,
Description = "Access to the website for a monthly payment"
;
这是我SubscriptonController
的相关部分
public ActionResult Purchase(PurchaseVm model)
var plan = Plan.Plans.FirstOrDefault(x => x.PayPalPlanId == model.Plan.PayPalPlanId);
if (ModelState.IsValid)
var startDate = DateTime.UtcNow.AddMonths(1);
var apiContext = GetApiContext();
var subscription = new Subscription()
FirstName = model.FirstName,
LastName = model.LastName,
Email = model.Email,
StartDate = startDate,
NumberOfEmployees = plan.NumberOfEmployees,
PayPalPlanId = plan.PayPalPlanId
;
_dbContext.Subscriptions.Add(subscription);
_dbContext.SaveChanges();
var agreement = new Agreement()
name = plan.Name,
description = $"blah blah blah",
start_date = startDate.ToString("yyyy-MM-ddTHH:mm:ssZ"),
create_time = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ"),
plan = new PayPal.Api.Plan()
id = plan.PayPalPlanId,
,
payer = new Payer()
payment_method = "paypal",
payer_info = new PayerInfo()
first_name = model.FirstName,
last_name = model.LastName,
email = model.Email
;
// the line below is where the error occurs
var createdAgreement = agreement.Create(apiContext);
subscription.PayPalAgreementToken = createdAgreement.token;
_dbContext.SaveChanges();
var approvalUrl = createdAgreement.links.FirstOrDefault(x => x.rel.Equals("approval_url",
StringComparison.OrdinalIgnoreCase));
return Redirect(approvalUrl.href);
model.Plan = plan;
return View(model);
请注意,在上面的代码中,我的控制器中有一个 GetAPIContext() 方法。
这是发送到 PayPal API 的数据
"name":"Starter Subscription",
"description":"Access to the website for a monthly payment",
"start_date":"2020-07-15T12:44:06Z",
"payer":
"payment_method":"paypal",
"payer_info":
"email":"xxxx",
"first_name":"xxx",
"last_name":"xxx"
,
"plan":
"id":"P-4PV26268V7918953BL3S3ZHA"
GitHub 存储库链接:https://github.com/spatrick195/OMS
【问题讨论】:
【参考方案1】:看起来 PayPal 已弃用我正在使用的 API 版本。
【讨论】:
以上是关于PayPal 账单协议 - 无效的计划 ID .NET的主要内容,如果未能解决你的问题,请参考以下文章