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

时间:2014-05-06 02:20:19

标签: c# paypal

我有一个网站,我将用户的客户付款处理到他们(我的用户)的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中,我确实没有看到任何关于处理第三方付款的提及。似乎我在使用第三方帐户方面遗漏了一些东西。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分: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);
}

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