c# - 通过 Paypal C# Rest API 处理第三方支付

标签 c# paypal

我有一个网站,我在其中处理我用户的客户向他们(我的用户)的 Paypal 账户付款。我创建了一个 Paypal 应用程序,并在第 3 方设置下包含了处理借记卡和信用卡付款的功能。使用第三方帐户,我通过第三方权限授予了对我的用户名的访问权限。通过这些步骤,我相信我已经在 paypal 端授予了适当的访问权限。

这是我设置配置的 C# 代码:

Dictionary<string, string> PaypalConfig = new Dictionary<string, string>();
PaypalConfig.Add("account1.apiUsername", "my api username");
PaypalConfig.Add("account1.apiPassword", "my api password");
PaypalConfig.Add("account1.apiSignature", "my api signature");

PaypalConfig.Add("subject", "email address of my user");

PaypalConfig.Add("account1.applicationId", "my app id");
PaypalConfig.Add("mode", "live");


OAuthTokenCredential tokenCredential = new OAuthTokenCredential("my client id", "my client secret", PaypalConfig);
 string accessToken = tokenCredential.GetAccessToken();

//Code to fill in the transaction details

//Create Payment
Payment payment = new Payment();
payment.intent = "sale";
payment.payer = payer;
payment.transactions = transactions;

Payment createdPayment = payment.Create(accessToken);

当我进行交易时,付款返回已获批准,但似乎忽略了主题,钱已存入我的帐户。

我在 https://developer.paypal.com/docs/classic/invoicing/ht_invoicing-3p/ 找到了有关为第三方发送发票的文档,但在 REST API 中,我真的没有看到任何关于处理第 3 方付款的内容。关于使用第 3 方帐户,我似乎遗漏了一些信息。感谢您的帮助!

最佳答案

为什么不使用简单的重定向选项来处理付款,这样,您只需提及用户的商家电子邮件即可。

您需要按以下格式传递变量:

private void PayPal()
{
    string _MerchantEmail = "youremailwithpaypal@domain.com";
    string _ReturnURL = "https://www.yourwebsite.com/paymentsuccess";
    string _CancelURL = "https://www.yourwebsite.com/paymentfailed";
    string _CurrencyCode = "USD";
    int _Amount = 100;
    string _ItemName = "itme1"; //We are using this field to pass the order number
    int _Discount = 10;
    double _Tax = 1.5;
    string _PayPalURL = $"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business={_MerchantEmail}&return={_ReturnURL}&cancel_return={_CancelURL}&currency_code={_CurrencyCode}&amount={_Amount}&item_name={_ItemName}&discount_amount={_Discount}&tax={_Tax}";

    Response.Redirect(_PayPalURL);
}

您可能还需要 PayPal IPN 的回调 URL 来验证付款状态。但是对于您上面的问题,这应该可行,因为我们已经在我们的网站上使用了此代码。

关于c# - 通过 Paypal C# Rest API 处理第三方支付,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23484961/

相关文章:

c# - 如何从 ()=>foo.Title 表达式中获取对象实例

c# - Windows 应用商店应用程序中的 System.Environment 替换?

wordpress - Paypal 沙盒支付成功但未显示在沙盒摘要中

paypal - X-PAYPAL-APPLICATION-ID header 包含无效值

ruby - Paypal Adaptive Payments 移动应用程序在完成或取消时挂起

php - 如何保护用于 paypal 支付处理的敏感页面?

c# - 如何覆盖 ASP.NET Web API 中的异常消息

c# - ServiceStack JSONSerializer 和 HashSet<x>

c# - 共享正则表达式(C# 到 JS)- 始终为 false - 这里有什么问题?

php - 多重条件下的重力形式支付