Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Repository files navigation

Square logo

Square Connect .NET SDK - RETIRED


Build StatusNuGet versionApache-2 license

NOTICE: Square Connect .NET SDK retired

The Square Connect .NET SDK is retired (EOL) as of 2019-12-17 and will no longer receive bug fixes or product updates. To continue receiving API and SDK improvements, please follow the instructions below to migrate to the new Square .NET SDK.

The old Connect SDK documentation is available under the /docs folder.





Migrate to the Square .NET SDK

Follow the instructions below to migrate your apps from the deprecated Square.Connect library to the new Square library.

Update your package

Replace Square.Connect with the new Square package and update the version.

Update your code

  1. Change all instances of using Square.Connect.Api to using Square.
  2. Change all instances of using Square.Connect.Model to using Square.Models.
  3. Remove all instances of using Square.Connect.Client.
  4. Add a reference to using Square.Exceptions to anything that calls an endpoint.
  5. Update client instantiation to follow the method outlined below.

To simplify your code, we also recommend that you use method chaining to access APIs instead of explicitly instantiating multiple clients.

Client instantiation

SquareClientsquare=newSquareClient.Builder().Environment(Square.Environment.Sandbox).AccessToken("YOUR_SANDBOX_ACCESS_TOKEN").Build();// e.g to fetch a list of locationsvarresponse=square.LocationsApi.ListLocationsAsync();



Example code migration

As a specific example, consider the code used to create a new customer profile with the following CreateCustomerRequest object:

varbodyAddress=newAddress.Builder().AddressLine1("500 Electric Ave").AddressLine2("Suite 600").Locality("New York").AdministrativeDistrictLevel1("NY").PostalCode("10003").Country("US").Build();varbody=newCreateCustomerRequest.Builder().GivenName("Amelia").FamilyName("Earhart").EmailAddress("Amelia.Earhart@example.com").Address(bodyAddress).PhoneNumber("1-212-555-4240").ReferenceId("YOUR_REFERENCE_ID").Note("a customer").Build();

With the deprecated Square.Connect library, this is how you instantiate a client for the Customers API, format the request, and call the endpoint:

usingSystem;usingSystem.Diagnostics;usingSquare.Connect.Api;usingSquare.Connect.Client;usingSquare.Connect.Model;// Instantiate the clientvarconfiguration=newConfiguration(newApiClient("https://connect.squareupsandbox.com"));configuration.AccessToken="YOUR_SANDBOX_ACCESS_TOKEN";varcustomersApi=newCustomersApi(configuration);// Call the endpoint and handle the responsetry{// CreateCustomerCreateCustomerResponseresult=customersApi.CreateCustomer(body);Debug.WriteLine(result);}catch(Exceptione){Debug.Print("Exception when calling CustomersApi.CreateCustomer: "+e.Message);}

Now consider equivalent code using the new Square library:

usingSquare;usingSquare.Models;usingSquare.Exceptions;// Instantiate the clientSquareClientsquare=newSquareClient.Builder().Environment(Square.Environment.Sandbox).AccessToken("YOUR_SQUARE_ACCESS_TOKEN").Build();// Call the endpoint and handle the responsetry{CreateCustomerResponseresult=square.CustomersApi.CreateCustomerAsync(body).Result;// Business logic}catch(APIExceptione){// Error Handling};

That's it!

What was once a multi-block process can be handled in 1 line of code. Migrating to the Square library reduces boilerplate and lets you focus on the parts of your code that really matter.




Ask the community

Please join us in our Square developer community if you have any questions!

About

C# client library for the Square Connect APIs

Topics

Resources

Stars

27 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages