Problem using PayPalCheckoutSDK

Richard-R
Contributor
Contributor

I got the client side portion working on my website, and now I'm trying to implement the server side portion as described on this page in section 6 Verify the Transaction:

https://developer.paypal.com/docs/checkout/integrate/

 

The server side is an ASP.NET MVC application using .NET 4.6.1.  Using NuGet, I've installed the PayPalCheckSdk library.  But, I'm not getting the references that the documentation is showing, PayPalCheckoutSdk.Core and PayPalCheckSdk.Orders.  Is there some other library I need to install?

 

Also, when I attempt to install the BraintreeHttp library from NuGet, I'm getting "BraintreeHttp-DotNet could not be installed because it is not compatible with any project in the solution".  Any suggestions?  Does anyone know what version of .NET the library requires?

Thanks in advance,

 

Richard

Login to Me Too
5 REPLIES 5

MTS_Jennifer
Moderator
Moderator

Hello,

Thank you for posting to the PayPal Merchant Technical Support Community.

Since you are not using the Braintree library and 100% using the PayPal sdk, we will look into reasons for getting SDK errors. I know that all our SDKs require a minimum of .net 4.5 framework. Using .net 4.6 framework is ideal because of the TLS 1.2 industry requirements.

 

Thank you,

Jennifer

PayPal

 

 

 

Login to Me Too

Richard-R
Contributor
Contributor

Jennifer,

 

Thanks for the reply, but I'm confused by your answer.  The sample code provided on the Smart Button page, https://developer.paypal.com/docs/checkout/integrate/ , Step 6 - Verify the transaction, server-side, shows that both the BraintreeHTTP and PaypalCheckoutSDK libraries are being imported.

 

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

//1. Import the PayPal SDK client that was created in `Set up Server-Side SDK`.
using BraintreeHttp;
using PayPalCheckoutSdk.Core;
using PayPalCheckoutSdk.Orders;

namespace Samples
{
  public class GetOrderSample

.....

 All that I'm trying to do at this point is just verifying the transaction that was generated by the customer using the PayPal page that the PayPal button invokes.  The link you provide doesn't seem to be for doing that.

Login to Me Too

MTS_Jennifer
Moderator
Moderator

Hi Richard,

Thank you for giving additional clarification on this issue. We will work on getting the documentation updated.

Here is the updated SDK from Git Hub: https://github.com/paypal/Checkout-NET-SDK

Braintree HTTP should not be used, it should be PayPalHttp, which is the reason you were getting the error message. 

 
 
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using PayPalCheckoutSdk.Core;
using PayPalCheckoutSdk.Orders;
namespace checkout_sdk
{
    class Program
    {
        public static SandboxEnvironment sandboxEnv;
        public static PayPalHttpClient payPalClient;
        static void Main(string[] args)
        {
            var clientId = "YOUR_CLIENT_ID";
            var secret = "YOUR_SECRET";
            sandboxEnv = new SandboxEnvironment(clientId, secret);
            payPalClient = new PayPalHttpClient(sandboxEnv);
            Test_sdk();
        }
        public static void Test_sdk()
        {
            try
            {
                Console.WriteLine("creating order\n");
                var res = CreateOrder(true).Result.Result<Order>();
                Console.WriteLine("\n");
                Console.WriteLine("getting order details \n");
                var getdetails = GetOrder(res.Id).Result;
                System.Diagnostics.Process.Start(res.Links[1].Href);
                Console.WriteLine("Press any key to capture payment. Note: the buyer must approve the payment");
                Console.ReadLine();
                Console.WriteLine($"capturing order id: {res.Id} \n");
                var captureDetails = CaptureOrder(res.Id).Result;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.InnerException.Message) ;
            }
        }
        public async static Task<PayPalHttp.HttpResponse> CreateOrder(bool debug = false)
        {
            var order = new OrderRequest()
            {
                CheckoutPaymentIntent = "CAPTURE",
                PurchaseUnits = new List<PurchaseUnitRequest>()
                {
                    new PurchaseUnitRequest()
                    {
                        AmountWithBreakdown = new AmountWithBreakdown()
                        {
                            CurrencyCode = "USD",
                            Value = "100.00"
                        }
                    }
                },
                ApplicationContext = new ApplicationContext()
                {
                    ReturnUrl = "https://www.example.com",
                    CancelUrl = "https://www.example.com"
                }
            };
            // Call API with your client and get a response for your call
            var request = new OrdersCreateRequest();
            request.Prefer("return=representation");
            request.RequestBody(order);
            var response = await payPalClient.Execute<OrdersCreateRequest>(request);
            var statusCode = response.StatusCode;
            Order result = response.Result<Order>();
            Console.WriteLine("Status: {0}", result.Status);
            Console.WriteLine("Order Id: {0}", result.Id);
            Console.WriteLine("Intent: {0}", result.CheckoutPaymentIntent);
            Console.WriteLine("Links:");
            foreach (LinkDescription link in result.Links)
            {
                Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
            }
            return response;
        }
        public async static Task<PayPalHttp.HttpResponse> GetOrder(string orderId, bool debug = false)
        {
            OrdersGetRequest request = new OrdersGetRequest(orderId);
            var response = await payPalClient.Execute<OrdersGetRequest>(request);
            var result = response.Result<Order>();
            Console.WriteLine("Retrieved Order Status");
            Console.WriteLine("Status: {0}", result.Status);
            Console.WriteLine("Order Id: {0}", result.Id);
            Console.WriteLine("Links:");
            foreach (PayPalCheckoutSdk.Orders.LinkDescription link in result.Links)
            {
                Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
            }
            AmountWithBreakdown amount = result.PurchaseUnits[0].AmountWithBreakdown;
            Console.WriteLine("Total Amount: {0} {1}", amount.CurrencyCode, amount.Value);
            return response;
        }
        public async static Task<PayPalHttp.HttpResponse> CaptureOrder(string approvedOrderId)
        {
            // Construct a request object and set desired parameters
            // Replace ORDER-ID with the approved order id from create order
            //var request = new OrderCaptureRequest("APPROVED-ORDER-ID");
            var request = new OrdersCaptureRequest(approvedOrderId);
            request.RequestBody(new OrderActionRequest());
            var response = await payPalClient.Execute( request);
            var statusCode = response.StatusCode;
            var result = response.Result<Order>();
            Console.WriteLine("Status: {0}", result.Status);
            Console.WriteLine("Capture Id: {0}", result.Id);
            return response;
        }
    }
}

Thank you for bringing this to our attention.

Jennifer

PayPal

 

 

 

 

Login to Me Too

TemocGH
Contributor
Contributor

Help

In this line it stays loading and does not pass

var response = await payPalClient.Execute<OrdersCreateRequest>(request)

Login to Me Too

integracionpp
Contributor
Contributor

Hello TemocGH,

 

You were able to solve the problem, because I have the same problem right now
Any suggestion?
Thank you.

Login to Me Too

Haven't Found your Answer?

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