Avatar of ITsolutionWizard
ITsolutionWizard
Flag for United States of America

asked on 

Paypal API

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);

        }

Open in new window

ASP.NETC#PayPal

Avatar of undefined
Last Comment
ITsolutionWizard

8/22/2022 - Mon