ElCamino.PayPalCheckoutSdk
2.0.1
Prefix Reserved
See the version list below for details.
dotnet add package ElCamino.PayPalCheckoutSdk --version 2.0.1
NuGet\Install-Package ElCamino.PayPalCheckoutSdk -Version 2.0.1
<PackageReference Include="ElCamino.PayPalCheckoutSdk" Version="2.0.1" />
paket add ElCamino.PayPalCheckoutSdk --version 2.0.1
#r "nuget: ElCamino.PayPalCheckoutSdk, 2.0.1"
// Install ElCamino.PayPalCheckoutSdk as a Cake Addin #addin nuget:?package=ElCamino.PayPalCheckoutSdk&version=2.0.1 // Install ElCamino.PayPalCheckoutSdk as a Cake Tool #tool nuget:?package=ElCamino.PayPalCheckoutSdk&version=2.0.1
ElCamino.PayPalCheckoutSdk
- New! Adding System.Text.Json serialization options
- New! Full support of the Webhooks Management API https://developer.paypal.com/docs/api/webhooks/v1/
- Added recurring billing support via products, plans and subscriptions https://developer.paypal.com/docs/api/subscriptions/v1/
- Uses the regex and threading performance and current .NET frameworks in ElCamino.PayPalHttp library.
- Supports .net6 and higher
- Check the unit tests for the latest examples for using Subscription and Webhooks APIs
- Forked from deprecated https://github.com/paypal/Checkout-NET-SDK
REST API SDK for Dotnet 6 and greater
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 | Versions 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. |
-
net6.0
- ElCamino.PayPalHttp (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.2.0)
-
net7.0
- ElCamino.PayPalHttp (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added recurring billing support via products, plans and subscriptions. Support for Webhooks now available. Fork from https://github.com/paypal/Checkout-NET-SDK