I am using PayPal REST API 1.9.1 in my dotnet core project. I have created sandbox account and when I am trying to make any payment getting "Payee account is invalid." error.
Api endpoint is "/v1/payments/payment" and payment method is "credit_card".
Below is code snippet:
string accessToken = new PayPal.Api.OAuthTokenCredential(config).GetAccessToken();
var apiContext = new PayPal.Api.APIContext(accessToken);
// A transaction defines the contract of a payment.
var transaction = new PayPal.Api.Transaction()
{
amount = new PayPal.Api.Amount()
{
currency = "USD",
total = totalAmount,
details = new PayPal.Api.Details()
{
shipping = shipping,
subtotal = subTotal,
tax = tax
}
},
description = description,
item_list = new PayPal.Api.ItemList()
{
items = new List<PayPal.Api.Item>()
{
new PayPal.Api.Item()
{
name = itemName,
currency = "USD",
price = "1",
quantity = "5",
sku = "sku"
}
},
shipping_address = new PayPal.Api.ShippingAddress
{
city = "Johnstown",
country_code = "US",
line1 = "52 N Main ST",
postal_code = "43210",
state = "OH",
recipient_name = "Basher Buyer"
}
},
invoice_number = invoice_number
};
// A resource representing a Payer that funds a payment.
var payer = new PayPal.Api.Payer()
{
payment_method = "credit_card",
funding_instruments = new List<PayPal.Api.FundingInstrument>()
{
new PayPal.Api.FundingInstrument()
{
credit_card = new PayPal.Api.CreditCard()
{
billing_address = new PayPal.Api.Address()
{
city = "Johnstown",
country_code = "US",
line1 = "52 N Main ST",
postal_code = "43210",
state = "OH"
},
cvv2 = card.CVV,
expire_month = Convert.ToInt32(card.ExpirationMonth),
expire_year = Convert.ToInt32(card.ExpirationYear),
first_name = firstName,
last_name =lastName,
number = card.CardNumber,
type = card.CardType
}
}
},
payer_info = new PayPal.Api.PayerInfo
{
email = "test@gmail.com"
},
};
// A Payment resource; create one using the above types and intent as `sale`, 'order', 'none' or `authorize`
var payment = new PayPal.Api.Payment()
{
intent = "sale",
payer = payer,
transactions = new List<PayPal.Api.Transaction>() { transaction }
};
// Create a payment using a valid APIContext
var createdPayment = payment.Create(apiContext);
Same code is working fine with payment method "paypal" by making minor changes in request.
How can I make it work for card payments?
Api endpoint is "/v1/payments/payment" and payment method is "credit_card".
You are using an API and feature that was deprecated a long time (eight years?) ago.
Current integrations use the v2/checkout/orders API. As of this writing there is no SDK for them, use direct HTTPS calls to first obtain an access_token , then send payloads in JSON format.