![]() |
VOOZH | about |
dotnet add package Square --version 44.0.0
NuGet\Install-Package Square -Version 44.0.0
<PackageReference Include="Square" Version="44.0.0" />
<PackageVersion Include="Square" Version="44.0.0" />Directory.Packages.props
<PackageReference Include="Square" />Project file
paket add Square --version 44.0.0
#r "nuget: Square, 44.0.0"
#:package Square@44.0.0
#addin nuget:?package=Square&version=44.0.0Install as a Cake Addin
#tool nuget:?package=Square&version=44.0.0Install as a Cake Tool
The Square .NET library provides convenient access to the Square API from C#, VB.NET, and F#.
The Square .NET SDK is supported with the following target frameworks:
dotnet add package Square
Instantiate and use the client with the following:
using Square.Payments;
using Square;
var client = new SquareClient();
await client.Payments.CreateAsync(
new CreatePaymentRequest
{
SourceId = "ccof:GaJGNaZa8x4OgDJn4GB",
IdempotencyKey = "7b0f3ec5-086a-4871-8f13-3c81b3875218",
AmountMoney = new Money { Amount = 1000, Currency = Currency.Usd },
AppFeeMoney = new Money { Amount = 10, Currency = Currency.Usd },
Autocomplete = true,
CustomerId = "W92WH6P11H4Z77CTET0RNTGFW8",
LocationId = "L88917AVBK2S5",
ReferenceId = "123456",
Note = "Brief description",
}
);
To get started with the Square SDK, instantiate the SquareClient class as follows:
using Square;
var client = new SquareClient("SQUARE_TOKEN");
Alternatively, you can omit the token when constructing the client.
In this case, the SDK will automatically read the token from the
SQUARE_TOKEN environment variable:
using Square;
var client = new SquareClient(); // Token is read from the SQUARE_TOKEN environment variable.
This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.
using Square;
var client = new SquareClient(clientOptions: new ClientOptions
{
BaseUrl = SquareEnvironment.Production // Used by default
});
using Square;
var client = new SquareClient(clientOptions: new ClientOptions
{
BaseUrl = "https://custom-staging.com"
});
This SDK uses forward-compatible enums that provide type safety while maintaining forward compatibility with API updates.
// Use predefined enum values
var accountType = BankAccountType.Checking;
// Use unknown/future enum values
var customType = BankAccountType.FromCustom("FUTURE_VALUE");
// String conversions and equality
string typeString = accountType.ToString(); // Returns "CHECKING"
var isChecking = accountType == "CHECKING"; // Returns true
// When writing switch statements, always include a default case
switch (accountType.Value) {
case BankAccountType.Values.Checking:
// Handle checking accounts
break;
case BankAccountType.Values.BusinessChecking:
// Handle business checking accounts
break;
default:
// Handle unknown values for forward compatibility
break;
}
List endpoints are paginated. The SDK provides an async enumerable so that you can simply loop over the items:
using Square.BankAccounts;
using Square;
var client = new SquareClient();
var pager = await client.BankAccounts.ListAsync(new ListBankAccountsRequest());
await foreach (var item in pager)
{
// do something with item
}
When the API returns a non-success status code (4xx or 5xx response), a SquareApiException will be thrown.
using Square;
try {
var response = await client.Payments.CreateAsync(...);
} catch (SquareApiException e) {
Console.WriteLine(e.Body);
Console.WriteLine(e.StatusCode);
// Access the parsed error objects
foreach (var error in e.Errors) {
Console.WriteLine($"Category: {error.Category}");
Console.WriteLine($"Code: {error.Code}");
Console.WriteLine($"Detail: {error.Detail}");
Console.WriteLine($"Field: {error.Field}");
}
}
The SDK provides utility methods that allow you to verify webhook signatures and ensure
that all webhook events originate from Square. The WebhooksHelper.verifySignature method
can be used to verify the signature like so:
using Microsoft.AspNetCore.Http;
using Square;
public static async Task CheckWebhooksEvent(
HttpRequest request,
string signatureKey,
string notificationUrl
)
{
var signature = request.Headers["x-square-hmacsha256-signature"].ToString();
using var reader = new StreamReader(request.Body, System.Text.Encoding.UTF8);
var requestBody = await reader.ReadToEndAsync();
if (!WebhooksHelper.VerifySignature(requestBody, signature, signatureKey, notificationUrl))
{
throw new Exception("A webhook event was received that was not from Square.");
}
}
In .NET 6 and above, there are also overloads using spans for allocation free webhook verification.
While the new SDK has a lot of improvements, we at Square understand that it takes time to upgrade when there are breaking changes.
To make the migration easier, the legacy SDK is available as a separate NuGet package Square.Legacy with all functionality under the Square.Legacy namespace. Here's an example of how you can use the legacy SDK alongside the new SDK inside a single file:
using Square;
using Square.Legacy.Authentication;
var accessToken = "YOUR_SQUARE_TOKEN";
// NEW
var client = new SquareClient(accessToken);
// LEGACY
var legacyClient = new Square.Legacy.SquareClient.Builder()
.BearerAuthCredentials(
new BearerAuthModel.Builder(accessToken)
.Build())
.Environment(Square.Legacy.Environment.Production)
.Build();
We recommend migrating to the new SDK using the following steps:
Square.Legacy NuGet package alongside your existing Square SDKSquare to Square.LegacySquare namespace.The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
Use the MaxRetries request option to configure this behavior.
var response = await client.Payments.CreateAsync(
...,
new RequestOptions {
MaxRetries: 0 // Override MaxRetries at the request level
}
);
The SDK defaults to a 30 second timeout. Use the Timeout option to configure this behavior.
var response = await client.Payments.CreateAsync(
...,
new RequestOptions {
Timeout: TimeSpan.FromSeconds(3) // Override timeout to 3s
}
);
Every response type includes the AdditionalProperties property, which returns an IDictionary<string, JsonElement> that contains any properties in the JSON response that were not specified in the returned class. Similar to the use case for sending additional parameters, this can be useful for API features not present in the SDK yet.
You can access the additional properties like so:
var payments = client.Payments.Create(...);
IDictionary<string, JsonElement> additionalProperties = payments.AdditionalProperties;
The AdditionalProperties dictionary is populated automatically during deserialization using the [JsonExtensionData] attribute. This provides you with access to any fields that may be added to the API response in the future before they're formally added to the SDK models.
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Square:
| Package | Downloads |
|---|---|
|
ImmediaC.SimpleCms
ASP.NET Core based CMS |
|
|
Rescope.Commerce.PaymentProcessors.Square
Square payment provider for Rescope Commerce on Umbraco. |
|
|
DanSaul.SharedCode
Package Description |
|
|
TheFusionWorks.Platforms
These are base utility classes developed by The Fusion Works which other packages and applications are built off. |
|
|
DanSaul.SharedCode.DatabaseSchemas
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 44.0.0 | 3,538 | 5/20/2026 |
| 43.0.0 | 26,145 | 1/23/2026 |
| 42.2.1 | 22,722 | 12/17/2025 |
| 42.0.2 | 43,644 | 8/20/2025 |
| 42.0.1 | 19,513 | 7/16/2025 |
| 42.0.0 | 19,085 | 6/18/2025 |
| 41.2.0 | 7,368 | 5/21/2025 |
| 41.1.0 | 11,081 | 4/16/2025 |
| 41.0.3 | 3,889 | 4/7/2025 |
| 41.0.2 | 3,565 | 3/31/2025 |
| 41.0.1 | 5,513 | 3/19/2025 |
| 41.0.0 | 2,279 | 3/19/2025 |
| 40.1.0 | 75,828 | 2/20/2025 |
| 40.0.0 | 65,141 | 1/23/2025 |
| 39.1.0 | 13,550 | 12/18/2024 |
| 39.0.0 | 15,107 | 11/20/2024 |
| 38.2.0 | 16,775 | 10/17/2024 |
| 38.1.0 | 23,601 | 9/18/2024 |
| 38.0.0 | 72,053 | 8/21/2024 |
| 37.1.1 | 29,966 | 7/17/2024 |