Search code examples
c#.netpaypal

PayPal: Internal Server Error on Create Payment


I am using Paypal API for .NET to create payments.

My exact code in Console Application:

// Get a reference to the config
var config = ConfigManager.Instance.GetProperties();

// Use OAuthTokenCredential to request an access token from PayPal
var accessToken = new OAuthTokenCredential(config).GetAccessToken();

var apiContext = new APIContext(accessToken);

var p = new Payment();
p.intent = "sale";

p.payer = new Payer();
p.payer.payment_method = "credit_card"; //paypal or credit_card

var t = new Transaction();
t.amount = new Amount();
t.amount.currency = "GBP";
t.amount.total = "10.00";

t.amount.details = new Details();
t.amount.details.subtotal = "6.00";
t.amount.details.tax = "2.00";
t.amount.details.shipping = "2.00";

t.item_list = new ItemList();
t.item_list.items = new List<Item>();

var i1 = new Item();

i1.quantity = "1";
i1.name = "OBJETO TESTE";
i1.price = "6.00";
i1.currency = "GBP";

i1.sku = "TESTE";

t.item_list.items.Add(i1);

var a = new ShippingAddress();
a.recipient_name = "ADDRESS";
a.line1 = "LINE1";
a.line2 = "LINE2";
a.city = "LONDOM";
a.country_code = "GB";
a.postal_code = "NW19EA";

t.item_list.shipping_address = a;

p.transactions = new List<Transaction>();
p.transactions.Add(t);

p.redirect_urls = new RedirectUrls();
p.redirect_urls.cancel_url = string.Format("{0}{1}", "http://localhost:3161/", "Order/CancelPayment");
p.redirect_urls.return_url = string.Format("{0}{1}", "http://localhost:3161/", "Order/CompletePayment");

var payment = Payment.Create(apiContext, p);

If I change payment method to Paypal, its working. If I send credit_card I get error 500.

debug_id: 30e0f1bb08d3f

configuration: live


Solution

  • Merchants from UK cannot make Direct(Credit Card) Payments using REST API. You will need to upgrade your account to PRO to make use of Direct Card Payments. Only US merchants can make direct card payments in REST API without a PRO account.