ElCamino.PayPalCheckoutSdk 2.2.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package ElCamino.PayPalCheckoutSdk --version 2.2.0
NuGet\Install-Package ElCamino.PayPalCheckoutSdk -Version 2.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ElCamino.PayPalCheckoutSdk" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ElCamino.PayPalCheckoutSdk --version 2.2.0
#r "nuget: ElCamino.PayPalCheckoutSdk, 2.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ElCamino.PayPalCheckoutSdk as a Cake Addin
#addin nuget:?package=ElCamino.PayPalCheckoutSdk&version=2.2.0

// Install ElCamino.PayPalCheckoutSdk as a Cake Tool
#tool nuget:?package=ElCamino.PayPalCheckoutSdk&version=2.2.0

ElCamino.PayPalCheckoutSdk

REST API SDK for Dotnet 6 and greater

Home Image

To consolidate support across various channels, we have currently turned off the feature of GitHub issues. Please visit https://www.paypal.com/support to submit your request or ask questions within our community forum.

Welcome to PayPal Dotnet SDK. This repository contains PayPal's Dotnet SDK and samples for v2/checkout/orders and v2/payments APIs.

This is a part of the next major PayPal SDK. It includes a simplified interface to only provide simple model objects and blueprints for HTTP calls. This repo currently contains functionality for PayPal Checkout APIs which includes Orders V2 and Payments V2.

Please refer to the PayPal Checkout Integration Guide for more information. Also refer to Setup your SDK for additional information about setting up the SDK's.

Prerequisites

.NET .net6 and higher

An environment which supports TLS 1.2 (see the TLS-update site for more information)

ElCamino.PayPalHttp 2.0

Usage

Binaries

It is not necessary to fork this repository for using the PayPal SDK. Please take a look at PayPal Checkout Server SDK for configuring and working with SDK without forking this code.

For contributing to this repository or using the samples you can fork this repository.

Setting up credentials

Get client ID and client secret by going to https://developer.paypal.com/developer/applications and generating a REST API app. Get <b>Client ID</b> and <b>Secret</b> from there.

using System;
using PayPalCheckoutSdk.Core;
using PayPalCheckoutSdk.Orders;
using PayPalHttp;
using System.Collections.Generic;
using System.Threading.Tasks;

public class CaptureOrderSample
{
    static String clientId = "PAYPAL-CLIENT-ID";
    static String secret = "PAYPAL-CLIENT-SECRET";

    public static HttpClient client()
    {
    // Creating a sandbox environment
    PayPalEnvironment environment = new SandboxEnvironment(clientId, secret);

    // Creating a client for the environment
    PayPalHttpClient client = new PayPalHttpClient(environment);
    return client;
    }
}

Examples

Creating an Order

This will create an order and print order id for the created order

public async static Task<HttpResponse> createOrder()
 {
         HttpResponse response;
        // Construct a request object and set desired parameters
        // Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
        var order = new OrderRequest() {
                CheckoutPaymentIntent = "CAPTURE",
                PurchaseUnits = new List<PurchaseUnitRequest>()
                {
                    new PurchaseUnitRequest()
                    {
                        Amount = 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);
            response = await client().Execute(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.Intent);
            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;
    }

Capturing an Order

Before capturing an order, order should be approved by the buyer using the approve link in create order response

  public async static Task<HttpResponse> captureOrder()
    {
            // Construct a request object and set desired parameters
            // Replace ORDER-ID with the approved order id from create order
            var request = new OrdersCaptureRequest("APPROVED-ORDER-ID");
            request.RequestBody(new OrderActionRequest());
            HttpResponse response = await client().Execute(request);
            var statusCode = response.StatusCode;
            Order result = response.Result<Order>();
            Console.WriteLine("Status: {0}", result.Status);
            Console.WriteLine("Capture Id: {0}", result.Id);
            return response;
    }

Running tests

To run integration tests using your client id and secret, run the test gradle command with the -Pintegration flag

$ PAYPAL_CLIENT_ID=YOUR_SANDBOX_CLIENT_ID PAYPAL_CLIENT_SECRET=YOUR_SANDBOX_CLIENT_SECRET dotnet test -v normal

You may use the client id and secret above for demonstration purposes.

Samples

You can start off by trying out creating and capturing an order.

To try out different samples for both create and authorize intent head to this link.

Note: Update the PayPalClient.cs with your sandbox client credentials or pass your client credentials as environment variable while executing the samples.

License

Code released under SDK LICENSE

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 388 4/30/2023
2.1.0 179 4/27/2023
2.0.1 195 4/22/2023
2.0.0 198 4/10/2023
1.9.0 208 4/8/2023
1.8.0 411 11/23/2022
1.7.0 340 11/21/2022
1.5.0 723 4/1/2021

Added recurring billing support via products, plans and subscriptions. Support for Webhooks now available. Fork from https://github.com/paypal/Checkout-NET-SDK