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

3

我有一个网站,处理我的用户的客户支付并转入他们(我的用户)的PayPal账户。我创建了一个PayPal应用程序,并在第三方设置中加入了处理借记卡和信用卡付款的功能。使用第三方帐户,我通过第三方权限授予了我的用户名访问权限。通过这些步骤,我相信我已经在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中,我确实没有看到任何关于处理第三方付款的内容。看起来我在使用第三方账户方面遗漏了一些东西。 感谢您提供任何帮助!

你最终有没有了解更多关于这个问题?我也在尝试代表客户实现REST API请求。 - toabi
我也是。不过看起来它还没有成为REST API的一部分:https://github.com/paypal/PayPal-PHP-SDK/issues/99 - Iain M Norman
1个回答

1

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

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

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);
}

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接