GithubHelp home page GithubHelp logo

square / connect-java-sdk Goto Github PK

View Code? Open in Web Editor NEW
39.0 21.0 25.0 1.92 MB

Java client library for the Square Connect v2 API

License: Apache License 2.0

Java 99.98% Shell 0.02%
java ecommerce square squareup payments sdk

connect-java-sdk's Introduction

Square logo

Square Connect Java SDK - RETIRED


Maven Central Apache-2 license

NOTICE: Square Connect Java SDK retired

The Square Connect Java 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 Java SDK.

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





Migrate to the Square Java SDK

Follow the instructions below to migrate your apps from the deprecated com.squareup.connect library to the new com.squareup.square library.

Update your project

Update the dependency in your Maven or Gradle project.

Update Maven

Update the Square dependency in the POM for your project:

<dependency>
    <groupId>com.squareup</groupId>
    <artifactId>square</artifactId>
    <version>4.0.0.20191217</version>
    <scope>compile</scope>
</dependency>

Update Gradle

Replace the com.squareup.connect dependency in the build file of your project:

implementation "com.squareup:square:4.0.0.20191217"

Update your code

  1. Change all instances of import com.squareup.connect' to import com.squareup.square.
  2. Update client instantiation to follow the method outlined below.
  3. Use thenAccept and exceptionally rather than try and catch for flow control.

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

Client instantiation

import com.squareup.square.SquareClient;
import com.squareup.square.Environment;

SquareClient square = new SquareClient.Builder()
    .environment(Environment.SANDBOX)
    .accessToken("YOUR_SANDBOX_ACCESS_TOKEN")
    .build();

Accessing response data

Using listLocations as an example

square.getLocationsApi().listLocationsAsync().thenAccept(result -> {
    // Business logic
    }).exceptionally(exception -> {
    // Exception handling
    return null;
});



Example code migration

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

Address bodyAddress = new Address.Builder()
    .addressLine1("500 Electric Ave")
    .addressLine2("Suite 600")
    .locality("New York")
    .administrativeDistrictLevel1("NY")
    .postalCode("10003")
    .country("US")
    .build();

CreateCustomerRequest body = new CreateCustomerRequest.Builder()
    .givenName("Amelia")
    .familyName("Earhart")
    .emailAddress("[email protected]")
    .address(bodyAddress)
    .phoneNumber("1-212-555-4240")
    .referenceId("YOUR_REFERENCE_ID")
    .note("a customer")
    .build();

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

ApiClient defaultClient = Configuration.getDefaultApiClient();
CustomersApi customersApi = new CustomersApi();

try {
    CreateCustomerResponse result = customersApi.createCustomer(body);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling CustomersApi.createCustomer");
    e.printStackTrace();
}

Now consider equivalent code using the new squareup.square library:

// Instantiate the client
SquareClient square = new SquareClient.Builder()
    .environment(Environment.SANDBOX)
    .accessToken("YOUR_SANDBOX_ACCESS_TOKEN")
    .build();

// Call the endpoint
square.getCustomersApi().createCustomerAsync(body).thenAccept(result -> {
    System.out.println("Successfully created customer with id:"+ result.getCustomer().getId());
}).exceptionally(e -> {
    System.err.println("Exception when calling CustomersApi.createCustomer");
    e.printStackTrace();
    return null;
});

That's it!

What was once a multi-object process can be handled asynchronously with a single client. Migrating to the com.squareup.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!

connect-java-sdk's People

Contributors

alecholmes avatar bunnyc1986 avatar cszhu avatar deanpapastrat avatar frojasg avatar goblinhorde avatar hukid avatar jawspeak avatar jessdelacruzsantos avatar jguinta avatar jlabanca avatar mikekono avatar okenshields avatar shaofu88 avatar square-sdk-deployer avatar tristansokol avatar yonpols avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

connect-java-sdk's Issues

Timecard events throws exception.

        V1EmployeesApi v1EmployeesApi  = new V1EmployeesApi();
       V1EmployeesApi v1EmployeesApi  = new V1EmployeesApi();
        List<V1TimecardEvent> timeCardEvents = new ArrayList<>();
        for(String id : timeCardIds){
            timeCardEvents.addAll(v1EmployeesApi.listTimecardEvents(id));
        }

I have timecard Ids , this used to work with earlier versions.
I have recently updated SDK.

Now it gives me this error.

java.lang.IllegalStateException: The template variable 'timecard_id' has no value
	at org.glassfish.jersey.client.JerseyWebTarget.getUri(JerseyWebTarget.java:135)
	at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:215)
	at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:60)
	at com.squareup.connect.ApiClient.invokeAPI(ApiClient.java:649)

Thank you :)

Issue with create Order for OrderApi for sandbox.

I am trying to create order with sandbox , simply copy pasted code from Documentation.

{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"API endpoint for URL path /v2/locations/orders and HTTP method GET is not found."}]}

Program type already present: javax.inject.Inject

I am getting this issue
Message{kind=ERROR, text=Program type already present: javax.inject.Inject, sources=[Unknown source file], tool name=Optional.of(D8)}

I am using sample app. Here is my build.gradle

apply plugin: 'com.android.application'

android {
  compileSdkVersion 27
  defaultConfig {
    applicationId "com.example.supercookie"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}


repositories {
  google()
  jcenter()
  maven {
    url 'https://sdk.squareup.com/public/android'
  }
}

dependencies {
  def inAppPaymentsSdkVersion = '1.0.3'
  implementation "com.squareup.sdk.in-app-payments:card-entry:$inAppPaymentsSdkVersion"
  implementation "com.squareup.sdk.in-app-payments:google-pay:$inAppPaymentsSdkVersion"
  implementation 'com.squareup.retrofit2:retrofit:2.4.0'
  implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
  def supportLibraryVersion = '27.1.1'
  implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
  implementation "com.android.support:design:$supportLibraryVersion"
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  // Play Services Wallet 16.0.1 was published with dependencies on maps & identities 16.0.0.
  implementation 'com.google.android.gms:play-services-wallet:16.0.1'
  implementation 'com.squareup:connect:2.20181212.0' //Getting error after adding this line
}

issue when build

Results :

Tests in error:
com.squareup.connect.api.CatalogApiTest: .\travis-ci\accounts.json
com.squareup.connect.api.CheckoutApiTest: .\travis-ci\accounts.json
com.squareup.connect.api.CustomersApiTest: .\travis-ci\accounts.json
com.squareup.connect.api.LocationsApiTest: .\travis-ci\accounts.json
com.squareup.connect.api.ReportingApiTest: .\travis-ci\accounts.json
com.squareup.connect.api.TransactionsApiTest: .\travis-ci\accounts.json

Tests run: 17, Failures: 0, Errors: 6, Skipped: 9

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.389 s
[INFO] Finished at: 2019-02-28T17:26:03+07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project connect: There are test failures.
[ERROR]
[ERROR] Please refer to D:\data\mydoforms\connect-java-sdk-master\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
com.squareup.connect.api.LocationsApiTest.txt
com.squareup.connect.api.CustomersApiTest.txt
com.squareup.connect.api.ReportingApiTest.txt
com.squareup.connect.api.TransactionsApiTest.txt
com.squareup.connect.api.CheckoutApiTest.txt
com.squareup.connect.api.CatalogApiTest.txt

Employee API : null data returns.

while using employee api no data returns,

        V1EmployeesApi roles = new V1EmployeesApi();
        CompleteResponse<List<V1EmployeeRole>> employeeRolesResponse;
        List<V1EmployeeRole> employeeRolesList = new ArrayList<>();
        String batchToken = null;
        do {
            employeeRolesResponse = roles.listEmployeeRolesWithHttpInfo(SortOrder.ASC.name(), 100, batchToken);
            employeeRolesList.addAll(employeeRolesResponse.getData());
            batchToken = employeeRolesResponse.getBatchToken();
        } while (batchToken != null);

I don't know if I am doing something wrong.
Thank you.

Issue using Api in Android

i add sqaure point of sale api in android from this
compile 'com.squareup:connect:2.2.0' and use Retrolamda with Java 8 butt i got this error on run .

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/inject/Inject.class

account.json

hi, I am new to java. I try to run the test case it shows the error there is no account.json. but that file location there is another file that is account.enc which is encrypted. so I need the structure of the account so I can replace my key to that account.json plz any one send that JSON

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.