简体   繁体   English

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

[英]Processing 3rd Party Payments via Paypal C# Rest API

I have a website in which I process my user's customer's payments into their(my users) paypal account. 我有一个网站,我将用户的客户付款处理到他们(我的用户)的paypal帐户。 I've created a paypal application and under the 3rd party settings I included the ability to process debit and credit card payments. 我创建了一个paypal应用程序,在第三方设置下,我包括处理借记卡和信用卡付款的功能。 Using a 3rd party account, I granted access through the third party permissions to my username. 使用第三方帐户,我通过第三方授予了对用户名的权限。 Through those steps I believe I have I've granted proper access on the paypal side. 通过这些步骤,我相信我已经在paypal方面获得了适当的访问权限。

Here is my c# code where I setup the configuration: 这是我设置配置的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);

When I run a transaction, the payment comes back approved but seems it is ignoring the subject, and money is deposited into MY ACCOUNT. 当我进行交易时,付款会重新获得批准,但似乎忽略了主题,并且资金存入我的账户。

I found documentation on sending an invoice for a third party at https://developer.paypal.com/docs/classic/invoicing/ht_invoicing-3p/ , but in the REST API I really do not see anything mentioned about processing 3rd party payments. 我在https://developer.paypal.com/docs/classic/invoicing/ht_invoicing-3p/上找到了为第三方发送发票的文档,但是在REST API中我真的没有看到任何关于处理第三方付款的提及。 It seems that I am missing something in regards to using the 3rd party account. 似乎我在使用第三方帐户方面遗漏了一些东西。 Any help is appreciated! 任何帮助表示赞赏!

Why dont you use simple redirect option to process the payments, this way, all you need to mention is your user's merchant email. 为什么不使用简单的重定向选项来处理付款,这样,您需要提及的只是您的用户的商家电子邮件。

You need to pass the variables in the following format: 您需要以以下格式传递变量:

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

You might also need a callback URL for PayPal IPN to verify the payments status. 您可能还需要PayPal IPN的回调网址来验证付款状态。 But for your question above this should work as we are already using this code in our website. 但是对于上面的问题,这应该可行,因为我们已经在我们的网站上使用此代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM