我正在尝试制作一个 paypal 处理程序。你在输入中输入金额,然后按下捐赠按钮,你将被转发到 Paypal 页面,你可以登录然后按下继续按钮......按下继续按钮后的问题将我转发回 https://www.example.org/Account/PayPalHandler/页,仅此而已。我的代码缺少什么来完成 Paypal 交易?
[HttpPost]
public ActionResult DoPaymentPaypall(UserModel User_)
{
ResultModel<ManageAccountListModel> res_ = new ResultModel<ManageAccountListModel>();
res_.DataSelect = new ManageAccountListModel();
if (SessionManagement.LoginnedUser != null)
{
var config = ConfigManager.Instance.GetProperties();
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
var apiContext = new APIContext(accessToken);
string moneyCount_ = User_.moneycount.ToString();
var payment = Payment.Create(apiContext, new Payment
{
intent = "sale",
payer = new Payer
{
payment_method = "paypal"
},
transactions = new List<Transaction>
{
new Transaction
{
description = "Donation",
invoice_number = "001",
amount = new Amount
{
currency = "USD",
total = moneyCount_,
details = new Details
{
tax = "0",
shipping = "0",
subtotal = moneyCount_
}
},
item_list = new ItemList
{
items = new List<Item>
{
new Item
{
name = "Donation",
currency = "USD",
price = moneyCount_,
quantity = "1",
sku = "Custom Package"
}
}
}
}
},
redirect_urls = new RedirectUrls
{
return_url = "https://www.example.org/Account/PayPalHandler/",
cancel_url = "https://www.example.org/"
}
});
res_.SuccessMessage = payment.links.ToList()[1].href;
}
res_.Success = true;
return new JsonResult { Data = res_, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
最佳答案
您上面的代码似乎只显示流程的初始/开始...所以假设您的意思是在用户批准您的请求使用 Paypal 付款(不要将此与“付款”混淆 - 此步骤仅表示用户同意使用 Paypal 付款)您需要 Execute
the payment .
链接显示完整流程
Create
payment(这是您上面的代码映射到的内容)- 您将在此步骤中获得一个payment id
- 使用您收到的
id
将用户重定向到 Paypalapproval_url
以获得批准(详细信息在上面的Create
中) - Paypal 将用户发送回您的网站,并提供有关如何
执行
付款的信息(如果用户同意) 执行
付款(这是在您的站点/应用程序中完成的)
高度
关于c# - Asp MVC Paypal 交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42175221/