Paypal SDK giving error when trying to create Payment

MeriJang27
Contributor
Contributor

I created an app on PayPal with sandbox account. Then i picked up its API Client id and Secret. I created a new console application and added paypal nuget package version 1.9.1.

 internal class Program { static void Main(string[] args) { // 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["clientId"], config["clientSecret"]);

        var apiContext = new APIContext(accessToken.GetAccessToken());


        try
        {

            var payment = new Payment()
            {
                intent = "authorize",
                // A resource representing a Payer that funds a payment. Use the List of `FundingInstrument` and the Payment Method as 'credit_card'
                payer = new Payer()
                {
                    // The Payment creation API requires a list of
                    // FundingInstrument; add the created `FundingInstrument`
                    // to a List
                    funding_instruments = new List<FundingInstrument>()
                {
                    // A resource representing a Payeer's funding instrument.
                    // Use a Payer ID (A unique identifier of the payer generated
                    // and provided by the facilitator. This is required when
                    // creating or using a tokenized funding instrument)
                    // and the `CreditCardDetails`
                    new FundingInstrument()
                    {
                        // A resource representing a credit card that can be used to fund a payment.
                        credit_card = new CreditCard()
                        {
                            billing_address = new Address()
                            {
                                city = "Johnstown",
                                country_code = "US",
                                line1 = "52 N Main ST",
                                postal_code = "43210",
                                state = "OH"
                            },
                            cvv2 = "874",
                            expire_month = 11,
                            expire_year = 2023,
                            first_name = "Joe",
                            last_name = "Shopper",
                            number = "5105105105105100",
                            type = "visa"
                        }
                    }
                },
                    payment_method = "credit_card"
                },
                // The Payment creation API requires a list of transactions; add the created `Transaction` to a List
                transactions = new List<Transaction>()
            {
                // A transaction defines the contract of a payment - what is the payment for and who is fulfilling it. Transaction is created with a `Payee` and `Amount` types
                new Transaction()
                {
                    // Let's you specify a payment amount.
                    amount = new Amount()
                    {
                        currency = "USD",
                        // Total must be equal to sum of shipping, tax and subtotal.
                        total = "107.47",
                        details = new Details()
                        {
                            shipping = "0.03",
                            subtotal = "107.41",
                            tax = "0.03"
                        }
                    },
                    description = "This is the payment transaction description."
                }
            },
                     payee = new Payee { email = "email-address" }
            };
            var createdPayment = payment.Create(apiContext);
    
        }
        catch (Exception ex)
        {

            throw;
        }
       
    }
}

Using the code above i get the error mentioned below.

{"name":"VALIDATION_ERROR","message":"Invalid request - see details","debug_id":"f3c178cb2a17b","details":[{"field":"/payee","location":"body","issue":"MALFORMED_REQUEST_JSON"}],"links":[]}

is there anything i am doing wrong ?

i tried adding more information to Payee for example its account merchand_id and stuff but didnt worked.

i am expecting the exception to be resolved.

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.