troubleshooting Question

Paypal API

Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America asked on
ASP.NETC#PayPal
8 Comments1 Solution57 ViewsLast Modified:
I use this webpage to code the PayPal API https://tutorials.tinyappco.com/ASPNET/PayPal,
and some issues below.

1. When it runs, and alert about this (var createdPayment = payment.Create(apiContext);   )
and return ( The remote server returned an error: (400) Bad Request.  ). But I can see the API data into the Paypal already. how to fix it?

2. In Paypal, do you know how to code for Auth. only meaning that just want to hold the fund e.g. security deposit for 500.00. But not charge.

I follow this example (https://tutorials.tinyappco.com/ASPNET/PayPal)

protected void Page_Load(object sender, EventArgs e)
        {
            //https://stackoverflow.com/questions/30095448/paypal-rest-api-with-credit-cart-payment-method
            //https://tutorials.tinyappco.com/ASPNET/PayPal

            #region Authenticate with PayPal
            var config = ConfigManager.Instance.GetProperties();
            var accessToken = new OAuthTokenCredential(config).GetAccessToken();
            var apiContext = new APIContext(accessToken);
            #endregion

            //var apiContext = GetApiContext(clientId, clientSecret);

            
            CreditCard creditCard = new CreditCard();
            creditCard.number = " XXXXXXXXXXXXXXXX";
            creditCard.type = "Visa";
            creditCard.expire_month = 08;
            creditCard.expire_year = 2021;
            creditCard.cvv2 = "145";
            creditCard.first_name = "Ric";
            creditCard.last_name = "Chan";

            Amount amount = new Amount();
            amount.total = "7.47";
            amount.currency = "USD";

            Transaction transaction = new Transaction();
            transaction.amount = amount;
            transaction.description = "This is the payment transaction description.";

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

            FundingInstrument fundingInstrument = new FundingInstrument();
            fundingInstrument.credit_card = creditCard;

            List<FundingInstrument> fundingInstruments = new List<FundingInstrument>();
            fundingInstruments.Add(fundingInstrument);

            Payer payer = new Payer();
            payer.funding_instruments = fundingInstruments;
            payer.payment_method = "credit_card";

            var redirectUrls = new RedirectUrls();
            redirectUrls.return_url = "Default.aspx";

            Payment payment = new Payment();
            payment.intent = "sale";
            payment.payer = payer;
            payment.transactions = transactions;
            //payment.redirect_urls = redirectUrls;

            var createdPayment = payment.Create(apiContext);             
            //Response.Write(createdPayment.state);
            //Payment createdPayment = payment.Create(apiContext);

            Response.Write("Payment ID " + payment.id);

        }
ASKER CERTIFIED SOLUTION
David Johnson, CD
The More I know, the more I don't know
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros