简体   繁体   中英

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. I've created a paypal application and under the 3rd party settings I included the ability to process debit and credit card payments. 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.

Here is my c# code where I setup the configuration:

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. 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. But for your question above this should work as we are already using this code in our website.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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