From 6dd77309e82506e00929e376ac518949ad422569 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Wed, 22 Aug 2018 21:28:30 -0700 Subject: [PATCH 01/26] Added customization --- pom.xml | 19 ++- .../java/co/poynt/api/sdk/ApiCustomer.java | 20 +++ .../co/poynt/api/sdk/JsonWebTokenService.java | 122 ++++++++++++++++ src/main/java/co/poynt/api/sdk/Main2.java | 65 +++++++++ .../co/poynt/api/sdk/PoyntSdkBuilder.java | 135 ++++++++++++++++++ .../java/co/poynt/api/sdk/PoyntSdkConfig.java | 23 +++ src/main/resources/log4j.xml | 40 ++++++ ...b97-a84c-348ba0f21c3f_publicprivatekey.pem | 36 +++++ 8 files changed, 455 insertions(+), 5 deletions(-) create mode 100644 src/main/java/co/poynt/api/sdk/ApiCustomer.java create mode 100644 src/main/java/co/poynt/api/sdk/JsonWebTokenService.java create mode 100644 src/main/java/co/poynt/api/sdk/Main2.java create mode 100644 src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java create mode 100644 src/main/java/co/poynt/api/sdk/PoyntSdkConfig.java create mode 100644 src/main/resources/log4j.xml create mode 100644 src/main/resources/urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem diff --git a/pom.xml b/pom.xml index 561eb05..c797e65 100755 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,17 @@ co.poynt.api - java-cloud-sdk + poynt-java-cloud-sdk 1.0.0-SNAPSHOT 4.0.0 jar Poynt Java Cloud SDK http://services.poynt.net + + 1.2.16 + 1.7.2 + 6.1.1 + https://github.com/poynt/java-cloud-sdk scm:git:ssh://git@github.com/poynt/java-cloud-sdk @@ -38,7 +43,7 @@ co.poynt.api api-model - 1.2.64 + 1.2.116 com.fasterxml.jackson.core @@ -70,7 +75,11 @@ slf4j-api 1.7.12 - + + log4j + log4j + ${log4j.version} + @@ -83,8 +92,8 @@ maven-compiler-plugin 2.3.2 - 1.8 - 1.8 + 1.7 + 1.7 diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java new file mode 100644 index 0000000..ecc4c2c --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -0,0 +1,20 @@ +package co.poynt.api.sdk; + +import java.util.List; + +import co.poynt.api.model.Customer; + +public class ApiCustomer extends Api { + public static final String API_CUSTOMERS = "/businesses/{businessId}/customers"; + + public ApiCustomer(PoyntSdk sdk) { + super(sdk, Constants.POYNT_API_HOST + API_CUSTOMERS); + } + + public List getAll(String businessId) { + + Customer customer = new Customer(); + createAtBusiness(customer, "businessId"); + return getAllFromBusiness(Customer.class, businessId); + } +} diff --git a/src/main/java/co/poynt/api/sdk/JsonWebTokenService.java b/src/main/java/co/poynt/api/sdk/JsonWebTokenService.java new file mode 100644 index 0000000..2fede3f --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/JsonWebTokenService.java @@ -0,0 +1,122 @@ +package co.poynt.api.sdk; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.security.KeyPair; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.bouncycastle.openssl.PEMKeyPair; +import org.bouncycastle.openssl.PEMParser; +import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; + +import com.nimbusds.jose.JOSEException; +import com.nimbusds.jose.JWSAlgorithm; +import com.nimbusds.jose.JWSHeader; +import com.nimbusds.jose.JWSSigner; +import com.nimbusds.jose.JWSVerifier; +import com.nimbusds.jose.crypto.RSASSASigner; +import com.nimbusds.jose.crypto.RSASSAVerifier; +import com.nimbusds.jwt.JWTClaimsSet; +import com.nimbusds.jwt.SignedJWT; + +public class JsonWebTokenService extends JsonWebToken { + private String appId; + private KeyPair keyPair; + + public JsonWebTokenService(Config config) { + super(config); + } + + /** + * init initializes with given appId and key pair in string format + * @param appId + * @param keyPairString + * @return + * @throws IOException + */ + public JsonWebTokenService init(String appId, Reader keyPairReader) throws IOException { + if (appId == null || appId.isEmpty()) { + throw new IllegalArgumentException("appId is required"); + } + if (keyPairReader == null) { + throw new IllegalArgumentException("keyPairReader is required"); + } + this.appId = appId; + + try (PEMParser pp = new PEMParser(keyPairReader)) { + PEMKeyPair pemKeyPair = (PEMKeyPair)pp.readObject(); + keyPair = new JcaPEMKeyConverter().getKeyPair(pemKeyPair); + } + return this; + } + + @Override + public String selfIssue() { + JWSSigner signer = new RSASSASigner((RSAPrivateKey)keyPair.getPrivate()); + + List aud = new ArrayList(); + aud.add(Constants.POYNT_API_HOST); + + JWTClaimsSet claimsSet = new JWTClaimsSet(); + claimsSet.setAudience(aud); + claimsSet.setSubject(appId); + claimsSet.setIssuer(appId); + Calendar now = Calendar.getInstance(); + claimsSet.setIssueTime(now.getTime()); + now.add(Calendar.MINUTE, 15); + claimsSet.setExpirationTime(now.getTime()); + claimsSet.setJWTID(UUID.randomUUID().toString()); + + SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet); + + try { + signedJWT.sign(signer); + } + catch (JOSEException e) { + throw new PoyntSdkException("Failed to sign self issued JWT."); + } + return signedJWT.serialize(); + } + + /** + * decode decodes given JWT and returns claims + * @param jwtString + * @return claims + * { + * "sub": "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f", + * "aud": "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f", + * "poynt.sct": "J", + * "poynt.org": "6dc5a48d-8f99-41e9-b716-b3c564f0711c", + * "iss": "https:\/\/services.poynt.net", + * "poynt.kid": 6155246152827141777, + * "poynt.aty": "S", + * "exp": 1534773013, + * "iat": 1534686613, + * "jti": "533b9d4e-03e0-40de-9b27-bc2c4d4d8c6a" + * } + */ + public Map decode(String jwtString) { + try { + + SignedJWT signedJWT = SignedJWT.parse(jwtString); + + JWTClaimsSet claimsSet = (JWTClaimsSet)signedJWT.getJWTClaimsSet(); + return claimsSet.getAllClaims(); + + } + catch (ParseException e) { + throw new PoyntSdkException("Failed to parse given JWT."); + } + + } + +} diff --git a/src/main/java/co/poynt/api/sdk/Main2.java b/src/main/java/co/poynt/api/sdk/Main2.java new file mode 100644 index 0000000..35dc9c2 --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/Main2.java @@ -0,0 +1,65 @@ +package co.poynt.api.sdk; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import co.poynt.api.model.Business; +import co.poynt.api.model.BusinessUser; +import co.poynt.api.model.Hook; + +public class Main2 { + public static void main(String[] args) throws FileNotFoundException { + + final String businessId = "feb2ea1a-d05b-4fa2-bc93-dfb9fdd4cb8f"; //geneva + //"891b396d-fe26-4339-a810-ff2af2e277ba"; opinion + PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); + + PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); + Reader reader = new InputStreamReader(Main2.class.getClassLoader().getResourceAsStream("urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem")); + builder2.configure("urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f", reader); + builder2.rebuild(sdk); + + Map claims = ((JsonWebTokenService)builder2.jwt).decode(sdk.getAccessToken()); + System.out.println("============= claims = " + claims.toString()); + //String businessId = (String)claims.get(PoyntSdkBuilder.POYNT_JWT_CLAIM_ORG); + System.out.println("============= BUSINESS id=" + businessId); + + Business business = sdk.business().get(businessId); + System.out.println("============= BUSINESS =" + business); + + System.out.println("============= BUSINESS USER"); + List users = sdk.businessUser().getAll(businessId); + System.out.println(users); + + // System.out.println("=============CATALOG"); + // CatalogWithProduct catalog = sdk.catalog().get(businessId, "675f0c80-6db8-4584-a444-6b213d0f4f66"); + // System.out.println(catalog); + // + // System.out.println("=============PRODUCT"); + // Product product = sdk.product().get(businessId, "675f0c80-6db8-4584-a444-6b213d0f4f66"); + // System.out.println(product); + + System.out.println("=============Webhooks"); + Hook hook = new Hook(); + hook.setApplicationId(sdk.getConfig().getAppId()); + hook.setBusinessId(UUID.fromString(businessId)); + hook.setDeliveryUrl("https://engage.colligso.com/poynt"); + hook.setEventTypes(Arrays.asList(new String[] { "ORDER_COMPLETED", "TRANSACTION_AUTHORIZED" })); + + // Poynt will use the secret below to generate a signature using + // HmacSHA1 of the webhook payload + // The signature will be send as an http header called + // "poynt-webhook-signature". + hook.setSecret("my-shared-secret-with-poynt"); + sdk.webhook().register(hook); + + System.out.println("=============Done!"); + } +} diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java b/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java new file mode 100644 index 0000000..9b61a3b --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java @@ -0,0 +1,135 @@ +package co.poynt.api.sdk; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.NameValuePair; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.message.BasicNameValuePair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PoyntSdkBuilder extends PoyntSdk.Builder { + private static final Logger logger = LoggerFactory.getLogger(PoyntSdkBuilder.class); + public static final String POYNT_MERCHANT_ID = "poynt.biz"; + public static final String POYNT_ACCESS_TOKEN = "accessToken"; + public static final String POYNT_REFRESH_TOKEN = "refreshToken"; + public static final String POYNT_TOKEN_EXPIRY = "expiresIn"; + + + private PoyntSdk sdk; + private JsonWebTokenService jwt2; + + /** + * getJwt2 gives access to JSONToken util providing sign and verify functions + * @return + */ + public JsonWebTokenService getJwt2() { + return jwt2; + } + + public PoyntSdkBuilder configure(String appId, Reader keyPairReader) throws PoyntSdkException { + try { + PoyntSdkConfig config = new PoyntSdkConfig(); + config.load("config.properties"); + config.setAppId(appId); + config.setKeyPair(keyPairReader); + + this.cfg = config; + + //create jwt util + jwt2 = new JsonWebTokenService(null); + jwt2.init(cfg.getAppId(), config.getKeyPair()); + //set in parent so it could be used to set in sdk + this.jwt = jwt2; + + } + catch (IOException e) { + throw new PoyntSdkException("Failed to initialize JWT2."); + } + + //set httpclient if needed + + return this; + } + + public void rebuild(PoyntSdk sdk) { + sdk.jsonWebToken(this.jwt); + sdk.setConfig(this.cfg); + this.sdk = sdk; + } + + /** + * getAccessToken gets access token after merchant authorizes our app + * @param code + * @param redirectUri + * @return + */ + public Map getAccessToken(String code, String redirectUri) { + + if (code == null) { + throw new IllegalArgumentException("code is required!"); + } + if(redirectUri == null) { + throw new IllegalArgumentException("redirectUri is required!"); + } + /** + * From your server make a HTTP POST request to https://services.poynt.net/token and include the following headers and arguments: + Header: Accept: application/json + Header: Authorization: Bearer {self-signed-JWT} + HTTP param: grant_type=authorization_code + HTTP param: redirect_uri={redirect_uri} + HTTP param: client_id={appId} + HTTP param: code={code} + */ + HttpPost post = new HttpPost(Constants.POYNT_API_HOST + Constants.API_TOKEN); + + post.setHeader("Accept", "application/json"); + post.setHeader("Authorization", "Bearer " + jwt.selfIssue()); + + List urlParameters = new ArrayList(); + + urlParameters.add(new BasicNameValuePair("grant_type", "authorization_code")); + urlParameters.add(new BasicNameValuePair("redirect_uri", redirectUri)); + urlParameters.add(new BasicNameValuePair("client_id", sdk.getConfig().getAppId())); + urlParameters.add(new BasicNameValuePair("code", code)); + + + try { + post.setEntity(new UrlEncodedFormEntity(urlParameters)); + + HttpResponse response = sdk.getHttpClient().execute(post); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); + StringBuffer result = new StringBuffer(); + String line = ""; + while ((line = reader.readLine()) != null) { + result.append(line); + } + + @SuppressWarnings("unchecked") + Map tokenProperties = om.readValue(result.toString(), HashMap.class); + return tokenProperties; + } + else { + throw new PoyntSdkException( + response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase()); + } + } + catch (Exception e) { + throw new PoyntSdkException("Failed to obtain access token."); + } + finally { + post.releaseConnection(); + } + } +} diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdkConfig.java b/src/main/java/co/poynt/api/sdk/PoyntSdkConfig.java new file mode 100644 index 0000000..4735eba --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/PoyntSdkConfig.java @@ -0,0 +1,23 @@ +package co.poynt.api.sdk; + +import java.io.Reader; + +public class PoyntSdkConfig extends Config { + + private Reader keyPairReader; + + public void setAppId(String appId) { + prop.setProperty(Constants.PROP_APP_ID, appId); + } + + public Reader getKeyPair() { + return keyPairReader; + } + + public void setKeyPair(Reader keyPairReader) { + this.keyPairReader = keyPairReader; + } + + + +} diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml new file mode 100644 index 0000000..7c1c4a8 --- /dev/null +++ b/src/main/resources/log4j.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem b/src/main/resources/urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem new file mode 100644 index 0000000..4fbba14 --- /dev/null +++ b/src/main/resources/urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem @@ -0,0 +1,36 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAkx4cJxPdJ1UNmQTBv6gJBNP98fNkrkwnn0W2/KarEu9ADwc1 +wqvm+eeQQ7N7k0508EcX/QusVhVp8s/ud/x16IjKheyBON2DIN8RXV8Lo1WhndN3 +Bz1Z2T+bJehbaPvwV21y92f/zgWtmOfdTDugaoWxqK9PEltHQter63oTSHzgMiNg +X0b/qG1936seZIsfLeKy5V5FXGnHK7fP+403Y3Lht0Mx4DsKcFXGKINpdDgeHavK +2EFe2bync19dXDZGu31nlDmpEr/1yFWIGUwBCf2t8P9vgmBtLmHbjNFieUFUX9fI +PmPCttWb8nikTmwxPiHF05RyRAMqeujXY43xCwIDAQABAoIBADe5TnGQyRJGWY2t +qxOEutHM2GHmTqrkZpeiCOMe4CqeW7W1hev0P9tFljPGjpanv4xpaVEsND0xBD33 ++3wQMLsA4TEj+XhIEwyG4aVrxFU8MKi+udWQq/EpcgNERSd5UjpTVxoWFuL67Ju/ +q2deKG9gr3/U008BKvdLCK/7P8WTEAy7TAWTxOmvgDFGw1quawVl4SceSmI4saO8 +eEsmqreQWif3hKWXRI8YvJbU9+BiH4CNU6vqMPoN4C47GsnSsvEIQyWsg2pwUlHr +QzW3A8d56FlpOeAadCcjwE0xPfho9ZdTR5EDbTPx2R7FM29sPNAqMDK8dy6kDHOP +iwlpxtECgYEAy2h86D+3BIOytGjnzOCSsOoVoIRsMkdj0TszI9lPlMA9k3QrszVp +A03H64MsR3/SFt5MbjDRiwePuWG9YSt+NqzK/FiOsrIXCBsL1G2b/9eN6SrtphB6 +zIwDTRaigxeh81eIugbk8xryvKKrczi5REpE1nKDCh4ADIisgmiQWLsCgYEAuSfF +jfjm4Hma3WvnbrokC/HGJW5/Sa2RzcbqTgiFYgPdQ1PECtkgNS2LZdEGWvxtVLnS +ynet+9z0M7HYLcEhHynNVAueaSovZ5+WI5iGJSHQycb8jhYNiRA47knyI4bc48fM +Yg/iST1RNqpHE6Kgd+iLcdZEJt9aAbAhcLeZK/ECgYAuYPmx/u0dA2ZYyl6oEUCB +RC6ANhFxeWOiDmx/rQn/McIYf/GC4Be8oByIb5VGDDf77N3idhEhMS0tKMMEh+U0 +VDvIQ+ztg7vKplgRLJjYQe7ijl43ciR9xSLvjcyqNVZA5OGRAQdtAuT7699J21Iq +5wBBIUUNpn9+XB9xcKQRBwKBgQCXarIBb6qHqor+Rs8F2029QuRzGhEYVMxnByP3 +2roRtO1OsQMih/vx4SQdiLn00HgskKaUkxkCXuiKGgebK1SF4q6a68GJaUlJKdYj +mAkj9qqDSKqjG9/H1i9ol6pgaVrdIDjBfRHmKTHwTYJAyX8HcHIRD1O+oms99Cb0 +wgCOUQKBgQDIyzZ52CS0q89yKA99YbzP+fV9peey9zZJ6lzJ7OOkdCrNQhGm0DE/ +lf5LQUG8Hj+xdeXYsXWocDZmZFN/YowGr4QqORXTzbBQOCHL1FE4qAGB+Aiqc4nh +f/o9mNOfKtbiPR0I2b5qzf9eV5C3viLJKOlMeMCHhFuRwaEq/POSng== +-----END RSA PRIVATE KEY----- +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkx4cJxPdJ1UNmQTBv6gJ +BNP98fNkrkwnn0W2/KarEu9ADwc1wqvm+eeQQ7N7k0508EcX/QusVhVp8s/ud/x1 +6IjKheyBON2DIN8RXV8Lo1WhndN3Bz1Z2T+bJehbaPvwV21y92f/zgWtmOfdTDug +aoWxqK9PEltHQter63oTSHzgMiNgX0b/qG1936seZIsfLeKy5V5FXGnHK7fP+403 +Y3Lht0Mx4DsKcFXGKINpdDgeHavK2EFe2bync19dXDZGu31nlDmpEr/1yFWIGUwB +Cf2t8P9vgmBtLmHbjNFieUFUX9fIPmPCttWb8nikTmwxPiHF05RyRAMqeujXY43x +CwIDAQAB +-----END PUBLIC KEY----- From 52599f1c8432e2b249f6dde3064fee61d688fe68 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Fri, 24 Aug 2018 07:48:37 -0700 Subject: [PATCH 02/26] Tested sdkbuilder and sdkconfig locally from tomcat --- .../java/co/poynt/api/sdk/ApiCustomer.java | 2 ++ .../co/poynt/api/sdk/JsonWebTokenService.java | 1 + src/main/java/co/poynt/api/sdk/PoyntSdk.java | 17 +++++++++----- .../co/poynt/api/sdk/PoyntSdkBuilder.java | 23 +++++++++++-------- .../java/co/poynt/api/sdk/PoyntSdkConfig.java | 1 + 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index ecc4c2c..af42cc5 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -4,6 +4,8 @@ import co.poynt.api.model.Customer; + +//by Wavelety, Inc. public class ApiCustomer extends Api { public static final String API_CUSTOMERS = "/businesses/{businessId}/customers"; diff --git a/src/main/java/co/poynt/api/sdk/JsonWebTokenService.java b/src/main/java/co/poynt/api/sdk/JsonWebTokenService.java index 2fede3f..604f9d4 100644 --- a/src/main/java/co/poynt/api/sdk/JsonWebTokenService.java +++ b/src/main/java/co/poynt/api/sdk/JsonWebTokenService.java @@ -28,6 +28,7 @@ import com.nimbusds.jwt.JWTClaimsSet; import com.nimbusds.jwt.SignedJWT; +//by Wavelety, Inc. public class JsonWebTokenService extends JsonWebToken { private String appId; private KeyPair keyPair; diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdk.java b/src/main/java/co/poynt/api/sdk/PoyntSdk.java index 1fd3ce9..485aef9 100644 --- a/src/main/java/co/poynt/api/sdk/PoyntSdk.java +++ b/src/main/java/co/poynt/api/sdk/PoyntSdk.java @@ -128,12 +128,17 @@ public Builder configure(String configFile) throws PoyntSdkException { cm.setMaxTotal(cfg.getHttpMaxConnection()); cm.setDefaultMaxPerRoute(cfg.getHttpMaxConnPerRoute()); - SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build(); - - this.client = HttpClientBuilder.create().setSSLContext(sslContext).setDefaultRequestConfig(httpCfg) - .setConnectionManager(cm).build(); - - } catch (KeyManagementException | NoSuchAlgorithmException e) { + //to run using cli, uncomment the following +// SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build(); +// +// this.client = HttpClientBuilder.create().setSSLContext(sslContext).setDefaultRequestConfig(httpCfg) +// .setConnectionManager(cm).build(); + + this.client = HttpClientBuilder.create().setDefaultRequestConfig(httpCfg) + .setConnectionManager(cm).build(); + +// } catch (KeyManagementException | NoSuchAlgorithmException e) { + } catch (Exception e) { throw new PoyntSdkException("Failed to create http client"); } diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java b/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java index 9b61a3b..63e6a79 100644 --- a/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java +++ b/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java @@ -18,13 +18,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// by Wavelety, Inc. public class PoyntSdkBuilder extends PoyntSdk.Builder { private static final Logger logger = LoggerFactory.getLogger(PoyntSdkBuilder.class); public static final String POYNT_MERCHANT_ID = "poynt.biz"; public static final String POYNT_ACCESS_TOKEN = "accessToken"; public static final String POYNT_REFRESH_TOKEN = "refreshToken"; public static final String POYNT_TOKEN_EXPIRY = "expiresIn"; - private PoyntSdk sdk; private JsonWebTokenService jwt2; @@ -54,6 +54,7 @@ public PoyntSdkBuilder configure(String appId, Reader keyPairReader) throws Poyn } catch (IOException e) { + logger.error("Failed to configure ", e); throw new PoyntSdkException("Failed to initialize JWT2."); } @@ -79,7 +80,7 @@ public Map getAccessToken(String code, String redirectUri) { if (code == null) { throw new IllegalArgumentException("code is required!"); } - if(redirectUri == null) { + if (redirectUri == null) { throw new IllegalArgumentException("redirectUri is required!"); } /** @@ -98,11 +99,10 @@ public Map getAccessToken(String code, String redirectUri) { List urlParameters = new ArrayList(); - urlParameters.add(new BasicNameValuePair("grant_type", "authorization_code")); - urlParameters.add(new BasicNameValuePair("redirect_uri", redirectUri)); - urlParameters.add(new BasicNameValuePair("client_id", sdk.getConfig().getAppId())); - urlParameters.add(new BasicNameValuePair("code", code)); - + urlParameters.add(new BasicNameValuePair("grant_type", "authorization_code")); + urlParameters.add(new BasicNameValuePair("redirect_uri", redirectUri)); + urlParameters.add(new BasicNameValuePair("client_id", sdk.getConfig().getAppId())); + urlParameters.add(new BasicNameValuePair("code", code)); try { post.setEntity(new UrlEncodedFormEntity(urlParameters)); @@ -121,11 +121,16 @@ public Map getAccessToken(String code, String redirectUri) { return tokenProperties; } else { - throw new PoyntSdkException( - response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase()); + String emsg = String.format("Failed to get access token for authz code=%s response status=%d message=%s", code, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); + logger.error(emsg); + throw new PoyntSdkException(emsg); } } catch (Exception e) { + if(e instanceof PoyntSdkException) { + throw (PoyntSdkException)e; + } + logger.error("Failed to get access token for authz code={}", code, e); throw new PoyntSdkException("Failed to obtain access token."); } finally { diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdkConfig.java b/src/main/java/co/poynt/api/sdk/PoyntSdkConfig.java index 4735eba..093a014 100644 --- a/src/main/java/co/poynt/api/sdk/PoyntSdkConfig.java +++ b/src/main/java/co/poynt/api/sdk/PoyntSdkConfig.java @@ -2,6 +2,7 @@ import java.io.Reader; +//by Wavelety, Inc. public class PoyntSdkConfig extends Config { private Reader keyPairReader; From de53303f84124a86242bebbc1d72c1c9679c6f8e Mon Sep 17 00:00:00 2001 From: sdatgit Date: Sat, 25 Aug 2018 09:24:11 -0700 Subject: [PATCH 03/26] sslcontext initialization on jdk1.7 --- .../java/co/poynt/api/sdk/ApiCustomer.java | 1 + src/main/java/co/poynt/api/sdk/PoyntSdk.java | 465 +++++++++--------- 2 files changed, 240 insertions(+), 226 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index af42cc5..876cd59 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -16,6 +16,7 @@ public ApiCustomer(PoyntSdk sdk) { public List getAll(String businessId) { Customer customer = new Customer(); + createAtBusiness(customer, "businessId"); return getAllFromBusiness(Customer.class, businessId); } diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdk.java b/src/main/java/co/poynt/api/sdk/PoyntSdk.java index 485aef9..3ef3055 100644 --- a/src/main/java/co/poynt/api/sdk/PoyntSdk.java +++ b/src/main/java/co/poynt/api/sdk/PoyntSdk.java @@ -35,233 +35,246 @@ import co.poynt.api.model.TokenResponse; public class PoyntSdk implements Closeable { - private static final Logger logger = LoggerFactory.getLogger(PoyntSdk.class); - private Config config; - private ObjectMapper om; - - private JsonWebToken jsonWebToken; - private CloseableHttpClient httpClient; - - private String accessToken; - private String refreshToken; - - private PoyntSdk() { - // private on purpose - } - - @Override - public void close() { - if (httpClient != null) { - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - // ignore - } - } - } - - public void setConfig(Config config) { - this.config = config; - } - - public void jsonWebToken(JsonWebToken jwt) { - this.jsonWebToken = jwt; - } - - public void setHttpClient(CloseableHttpClient client) { - this.httpClient = client; - } - - public void setObjectMapper(ObjectMapper om) { - this.om = om; - } - - public static class Builder { - Config cfg; - JsonWebToken jwt; - CloseableHttpClient client; - ObjectMapper om; - - public Builder config(Config cfg) { - this.cfg = cfg; - return this; - } - - public Builder jwtGenerator(JsonWebToken jwtGen) { - this.jwt = jwtGen; - return this; - } - - public Builder httpClient(CloseableHttpClient client) { - this.client = client; - return this; - } - - public Builder jackson(ObjectMapper om) { - this.om = om; - return this; - } - - public Builder configure(String configFile) throws PoyntSdkException { - - this.cfg = new Config(); - try { - cfg.load(configFile); - } catch (IOException e) { - throw new PoyntSdkException("Failed to load configuration"); - } - - this.jwt = new JsonWebToken(cfg); - try { - jwt.init(); - } catch (IOException e) { - throw new PoyntSdkException("Failed to load keys for JWT generator."); - } - - RequestConfig httpCfg = RequestConfig.custom().setSocketTimeout(cfg.getHttpSocketTimeout()) - .setConnectTimeout(cfg.getHttpConnectTimeout()) - .setConnectionRequestTimeout(cfg.getHttpRequestTimeout()).build(); - - try { - PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); - cm.setMaxTotal(cfg.getHttpMaxConnection()); - cm.setDefaultMaxPerRoute(cfg.getHttpMaxConnPerRoute()); - - //to run using cli, uncomment the following -// SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build(); -// -// this.client = HttpClientBuilder.create().setSSLContext(sslContext).setDefaultRequestConfig(httpCfg) -// .setConnectionManager(cm).build(); - + private static final Logger logger = LoggerFactory.getLogger(PoyntSdk.class); + private Config config; + private ObjectMapper om; + + private JsonWebToken jsonWebToken; + private CloseableHttpClient httpClient; + + private String accessToken; + private String refreshToken; + + private PoyntSdk() { + // private on purpose + } + + @Override + public void close() { + if (httpClient != null) { + try { + httpClient.close(); + } + catch (IOException e) { + e.printStackTrace(); + // ignore + } + } + } + + public void setConfig(Config config) { + this.config = config; + } + + public void jsonWebToken(JsonWebToken jwt) { + this.jsonWebToken = jwt; + } + + public void setHttpClient(CloseableHttpClient client) { + this.httpClient = client; + } + + public void setObjectMapper(ObjectMapper om) { + this.om = om; + } + + public static class Builder { + Config cfg; + JsonWebToken jwt; + CloseableHttpClient client; + ObjectMapper om; + + public Builder config(Config cfg) { + this.cfg = cfg; + return this; + } + + public Builder jwtGenerator(JsonWebToken jwtGen) { + this.jwt = jwtGen; + return this; + } + + public Builder httpClient(CloseableHttpClient client) { + this.client = client; + return this; + } + + public Builder jackson(ObjectMapper om) { + this.om = om; + return this; + } + + public Builder configure(String configFile) throws PoyntSdkException { + + this.cfg = new Config(); + try { + cfg.load(configFile); + } + catch (IOException e) { + throw new PoyntSdkException("Failed to load configuration"); + } + + this.jwt = new JsonWebToken(cfg); + try { + jwt.init(); + } + catch (IOException e) { + throw new PoyntSdkException("Failed to load keys for JWT generator."); + } + + RequestConfig httpCfg = RequestConfig.custom().setSocketTimeout(cfg.getHttpSocketTimeout()) + .setConnectTimeout(cfg.getHttpConnectTimeout()) + .setConnectionRequestTimeout(cfg.getHttpRequestTimeout()).build(); + + try { + PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); + cm.setMaxTotal(cfg.getHttpMaxConnection()); + cm.setDefaultMaxPerRoute(cfg.getHttpMaxConnPerRoute()); + + SSLContext sslContext = null; + + //SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build(); + + sslContext = SSLContext.getInstance("TLSv1.2"); + sslContext.init(null, null, null); + SSLContext.setDefault(sslContext); + + this.client = HttpClientBuilder.create().setSSLContext(sslContext).setDefaultRequestConfig(httpCfg) + .setConnectionManager(cm).build(); + this.client = HttpClientBuilder.create().setDefaultRequestConfig(httpCfg) .setConnectionManager(cm).build(); -// } catch (KeyManagementException | NoSuchAlgorithmException e) { - } catch (Exception e) { - throw new PoyntSdkException("Failed to create http client"); - } - - this.om = new ObjectMapper(); - this.om.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - - this.om.setDateFormat(new ISO8601DateFormat()); - this.om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - this.om.configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, false); - this.om.setSerializationInclusion(JsonInclude.Include.NON_NULL); - - return this; - } - - public PoyntSdk build() { - PoyntSdk sdk = new PoyntSdk(); - sdk.setConfig(cfg); - sdk.setHttpClient(client); - sdk.jsonWebToken(jwt); - sdk.setObjectMapper(this.om); - return sdk; - } - } - - public static Builder builder() { - return new Builder(); - } - - public void clearAccessToken() { - this.accessToken = null; - } - - public void clearRefreshToken() { - this.accessToken = null; - this.refreshToken = null; - } - - public String getAccessToken() { - if (this.accessToken != null) { - return this.accessToken; - } - HttpPost post = new HttpPost(Constants.POYNT_API_HOST + Constants.API_TOKEN); - post.setHeader("User-Agent", Constants.SDK_AGENT + ": " + this.config.getAppId()); - post.setHeader("api-version", Constants.POYNT_API_VERSION); - String requestId = UUID.randomUUID().toString(); - logger.debug("Poynt-Request-Id: " + requestId); - post.setHeader("Poynt-Request-Id", requestId); - - List urlParameters = new ArrayList(); - - if (this.refreshToken == null) { - String selfIssuedJwt = this.jsonWebToken.selfIssue(); - urlParameters.add(new BasicNameValuePair("grantType", "urn:ietf:params:oauth:grant-type:jwt-bearer")); - urlParameters.add(new BasicNameValuePair("assertion", selfIssuedJwt)); - } else { - urlParameters.add(new BasicNameValuePair("grantType", "REFRESH_TOKEN")); - urlParameters.add(new BasicNameValuePair("refreshToken", this.refreshToken)); - } - - try { - post.setEntity(new UrlEncodedFormEntity(urlParameters)); - - HttpResponse response = httpClient.execute(post); - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); - StringBuffer result = new StringBuffer(); - String line = ""; - while ((line = reader.readLine()) != null) { - result.append(line); - } - - TokenResponse tokenResponse = om.readValue(result.toString(), TokenResponse.class); - this.accessToken = tokenResponse.getAccessToken(); - this.refreshToken = tokenResponse.getRefreshToken(); - return this.accessToken; - } else { - throw new PoyntSdkException( - response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase()); - } - } catch (Exception e) { - throw new PoyntSdkException("Failed to obtain access token."); - } finally { - post.releaseConnection(); - } - } - - public Config getConfig() { - return config; - } - - public ObjectMapper getOm() { - return om; - } - - public CloseableHttpClient getHttpClient() { - return httpClient; - } - - public ApiBusiness business() { - return new ApiBusiness(this); - } - - public ApiBusinessUser businessUser() { - return new ApiBusinessUser(this); - } - - public ApiCatalog catalog() { - return new ApiCatalog(this); - } - - public ApiProduct product() { - return new ApiProduct(this); - } - - public ApiTransaction transaction() { - return new ApiTransaction(this); - } - - public ApiOrder order() { - return new ApiOrder(this); - } - - public ApiWebhook webhook() { - return new ApiWebhook(this); - } + // } catch (KeyManagementException | NoSuchAlgorithmException e) { + } + catch (Exception e) { + throw new PoyntSdkException("Failed to create http client"); + } + + this.om = new ObjectMapper(); + this.om.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + + this.om.setDateFormat(new ISO8601DateFormat()); + this.om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + this.om.configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, false); + this.om.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + return this; + } + + public PoyntSdk build() { + PoyntSdk sdk = new PoyntSdk(); + sdk.setConfig(cfg); + sdk.setHttpClient(client); + sdk.jsonWebToken(jwt); + sdk.setObjectMapper(this.om); + return sdk; + } + } + + public static Builder builder() { + return new Builder(); + } + + public void clearAccessToken() { + this.accessToken = null; + } + + public void clearRefreshToken() { + this.accessToken = null; + this.refreshToken = null; + } + + public String getAccessToken() { + if (this.accessToken != null) { + return this.accessToken; + } + HttpPost post = new HttpPost(Constants.POYNT_API_HOST + Constants.API_TOKEN); + post.setHeader("User-Agent", Constants.SDK_AGENT + ": " + this.config.getAppId()); + post.setHeader("api-version", Constants.POYNT_API_VERSION); + String requestId = UUID.randomUUID().toString(); + logger.debug("Poynt-Request-Id: " + requestId); + post.setHeader("Poynt-Request-Id", requestId); + + List urlParameters = new ArrayList(); + + if (this.refreshToken == null) { + String selfIssuedJwt = this.jsonWebToken.selfIssue(); + urlParameters.add(new BasicNameValuePair("grantType", "urn:ietf:params:oauth:grant-type:jwt-bearer")); + urlParameters.add(new BasicNameValuePair("assertion", selfIssuedJwt)); + } + else { + urlParameters.add(new BasicNameValuePair("grantType", "REFRESH_TOKEN")); + urlParameters.add(new BasicNameValuePair("refreshToken", this.refreshToken)); + } + + try { + post.setEntity(new UrlEncodedFormEntity(urlParameters)); + + HttpResponse response = httpClient.execute(post); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); + StringBuffer result = new StringBuffer(); + String line = ""; + while ((line = reader.readLine()) != null) { + result.append(line); + } + + TokenResponse tokenResponse = om.readValue(result.toString(), TokenResponse.class); + this.accessToken = tokenResponse.getAccessToken(); + this.refreshToken = tokenResponse.getRefreshToken(); + return this.accessToken; + } + else { + throw new PoyntSdkException( + response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase()); + } + } + catch (Exception e) { + throw new PoyntSdkException("Failed to obtain access token."); + } + finally { + post.releaseConnection(); + } + } + + public Config getConfig() { + return config; + } + + public ObjectMapper getOm() { + return om; + } + + public CloseableHttpClient getHttpClient() { + return httpClient; + } + + public ApiBusiness business() { + return new ApiBusiness(this); + } + + public ApiBusinessUser businessUser() { + return new ApiBusinessUser(this); + } + + public ApiCatalog catalog() { + return new ApiCatalog(this); + } + + public ApiProduct product() { + return new ApiProduct(this); + } + + public ApiTransaction transaction() { + return new ApiTransaction(this); + } + + public ApiOrder order() { + return new ApiOrder(this); + } + + public ApiWebhook webhook() { + return new ApiWebhook(this); + } } From b79e5281ccd572433a6ec3fc64a6dd93a4664006 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Sat, 25 Aug 2018 10:57:55 -0700 Subject: [PATCH 04/26] sslcontext initialization on jdk1.7 --- src/main/java/co/poynt/api/sdk/PoyntSdk.java | 34 +++++++++---------- .../co/poynt/api/sdk/PoyntSdkBuilder.java | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdk.java b/src/main/java/co/poynt/api/sdk/PoyntSdk.java index 3ef3055..a0a9c13 100644 --- a/src/main/java/co/poynt/api/sdk/PoyntSdk.java +++ b/src/main/java/co/poynt/api/sdk/PoyntSdk.java @@ -18,8 +18,10 @@ import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.message.BasicNameValuePair; import org.apache.http.ssl.SSLContexts; @@ -131,23 +133,21 @@ public Builder configure(String configFile) throws PoyntSdkException { cm.setMaxTotal(cfg.getHttpMaxConnection()); cm.setDefaultMaxPerRoute(cfg.getHttpMaxConnPerRoute()); - SSLContext sslContext = null; - - //SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build(); - - sslContext = SSLContext.getInstance("TLSv1.2"); - sslContext.init(null, null, null); - SSLContext.setDefault(sslContext); - - this.client = HttpClientBuilder.create().setSSLContext(sslContext).setDefaultRequestConfig(httpCfg) - .setConnectionManager(cm).build(); - - this.client = HttpClientBuilder.create().setDefaultRequestConfig(httpCfg) - .setConnectionManager(cm).build(); - - // } catch (KeyManagementException | NoSuchAlgorithmException e) { - } - catch (Exception e) { + SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build(); + //following works with jdk 1.7 + SSLConnectionSocketFactory sslCSFactory = new SSLConnectionSocketFactory( + sslContext, + new String[] { "TLSv1.2" }, + null, + SSLConnectionSocketFactory.getDefaultHostnameVerifier()); + this.client = HttpClients.custom() + .setSSLSocketFactory(sslCSFactory) + .build(); + + //setting cm and httpcfg overrides tls1.2 setting + //.setConnectionManager(cm).setDefaultRequestConfig(httpCfg) + + } catch (KeyManagementException | NoSuchAlgorithmException e) { throw new PoyntSdkException("Failed to create http client"); } diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java b/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java index 63e6a79..70402dc 100644 --- a/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java +++ b/src/main/java/co/poynt/api/sdk/PoyntSdkBuilder.java @@ -117,7 +117,7 @@ public Map getAccessToken(String code, String redirectUri) { } @SuppressWarnings("unchecked") - Map tokenProperties = om.readValue(result.toString(), HashMap.class); + Map tokenProperties = sdk.getOm().readValue(result.toString(), HashMap.class); return tokenProperties; } else { From 1e668da84c592007c6c10b2b1a226312a3e90dad Mon Sep 17 00:00:00 2001 From: sdatgit Date: Thu, 6 Sep 2018 08:43:32 -0700 Subject: [PATCH 05/26] Added support for biling --- .../java/co/poynt/api/model/ResourceList.java | 51 ++ .../java/co/poynt/api/model/Subscription.java | 160 +++++++ src/main/java/co/poynt/api/sdk/Api.java | 448 ++++++++++-------- .../co/poynt/api/sdk/ApiSubscription.java | 78 +++ src/main/java/co/poynt/api/sdk/Constants.java | 1 + src/main/java/co/poynt/api/sdk/Main2.java | 13 +- 6 files changed, 543 insertions(+), 208 deletions(-) create mode 100644 src/main/java/co/poynt/api/model/ResourceList.java create mode 100644 src/main/java/co/poynt/api/model/Subscription.java create mode 100644 src/main/java/co/poynt/api/sdk/ApiSubscription.java diff --git a/src/main/java/co/poynt/api/model/ResourceList.java b/src/main/java/co/poynt/api/model/ResourceList.java new file mode 100644 index 0000000..440c4ac --- /dev/null +++ b/src/main/java/co/poynt/api/model/ResourceList.java @@ -0,0 +1,51 @@ +package co.poynt.api.model; + +import java.util.List; + +public class ResourceList { + + private List list; + private int start; + private int total; + private int count; + public List getList() { + return list; + } + public void setList(List list) { + this.list = list; + } + public int getStart() { + return start; + } + public void setStart(int start) { + this.start = start; + } + public int getTotal() { + return total; + } + public void setTotal(int total) { + this.total = total; + } + public int getCount() { + return count; + } + public void setCount(int count) { + this.count = count; + } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ResourceList [list="); + builder.append(list); + builder.append(", start="); + builder.append(start); + builder.append(", total="); + builder.append(total); + builder.append(", count="); + builder.append(count); + builder.append("]"); + return builder.toString(); + } + + +} diff --git a/src/main/java/co/poynt/api/model/Subscription.java b/src/main/java/co/poynt/api/model/Subscription.java new file mode 100644 index 0000000..3ef0b30 --- /dev/null +++ b/src/main/java/co/poynt/api/model/Subscription.java @@ -0,0 +1,160 @@ +package co.poynt.api.model; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "createdAt", + "updatedAt", + "startAt", + "businessId", + "appId", + "subscriptionId", + "phase", + "planId", + "bundleId", + "status" +}) +public class Subscription { + + @JsonProperty("createdAt") + private String createdAt; + @JsonProperty("updatedAt") + private String updatedAt; + @JsonProperty("startAt") + private String startAt; + @JsonProperty("businessId") + private String businessId; + @JsonProperty("appId") + private String appId; + @JsonProperty("subscriptionId") + private String subscriptionId; + @JsonProperty("phase") + private String phase; + @JsonProperty("planId") + private String planId; + @JsonProperty("bundleId") + private String bundleId; + @JsonProperty("status") + private String status; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + @JsonProperty("createdAt") + public String getCreatedAt() { + return createdAt; + } + + @JsonProperty("createdAt") + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + @JsonProperty("updatedAt") + public String getUpdatedAt() { + return updatedAt; + } + + @JsonProperty("updatedAt") + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + @JsonProperty("startAt") + public String getStartAt() { + return startAt; + } + + @JsonProperty("startAt") + public void setStartAt(String startAt) { + this.startAt = startAt; + } + + @JsonProperty("businessId") + public String getBusinessId() { + return businessId; + } + + @JsonProperty("businessId") + public void setBusinessId(String businessId) { + this.businessId = businessId; + } + + @JsonProperty("appId") + public String getAppId() { + return appId; + } + + @JsonProperty("appId") + public void setAppId(String appId) { + this.appId = appId; + } + + @JsonProperty("subscriptionId") + public String getSubscriptionId() { + return subscriptionId; + } + + @JsonProperty("subscriptionId") + public void setSubscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + } + + @JsonProperty("phase") + public String getPhase() { + return phase; + } + + @JsonProperty("phase") + public void setPhase(String phase) { + this.phase = phase; + } + + @JsonProperty("planId") + public String getPlanId() { + return planId; + } + + @JsonProperty("planId") + public void setPlanId(String planId) { + this.planId = planId; + } + + @JsonProperty("bundleId") + public String getBundleId() { + return bundleId; + } + + @JsonProperty("bundleId") + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + @JsonProperty("status") + public String getStatus() { + return status; + } + + @JsonProperty("status") + public void setStatus(String status) { + this.status = status; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + +} \ No newline at end of file diff --git a/src/main/java/co/poynt/api/sdk/Api.java b/src/main/java/co/poynt/api/sdk/Api.java index 690bffb..f544232 100644 --- a/src/main/java/co/poynt/api/sdk/Api.java +++ b/src/main/java/co/poynt/api/sdk/Api.java @@ -13,215 +13,251 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import co.poynt.api.model.Code; import co.poynt.api.model.ErrorInfo; public abstract class Api { - protected PoyntSdk sdk; - protected String endPoint; - - public Api(PoyntSdk sdk, String endPoint) { - this.sdk = sdk; - this.endPoint = endPoint; - } - - public HttpGet createGetRequest(String url) { - HttpGet get = new HttpGet(url); - get.setHeader(HttpHeaders.USER_AGENT, Constants.SDK_AGENT + ": " + this.sdk.getConfig().getAppId()); - get.setHeader("api-version", Constants.POYNT_API_VERSION); - return get; - } - - public HttpPost createPostRequest(String url) { - HttpPost post = new HttpPost(url); - post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); - post.setHeader(HttpHeaders.USER_AGENT, Constants.SDK_AGENT + ": " + this.sdk.getConfig().getAppId()); - post.setHeader("api-version", Constants.POYNT_API_VERSION); - return post; - } - - public void handleError(HttpResponse response) { - try { - ErrorInfo error = this.readResponse(response, ErrorInfo.class); - - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { - if (error.getCode() == Code.INVALID_ACCESS_TOKEN) { - this.sdk.clearAccessToken(); - } else if (error.getCode() == Code.INVALID_REFRESH_TOKEN) { - this.sdk.clearRefreshToken(); - } - } - - throw new PoyntSdkException(error.getDeveloperMessage(), error); - } catch (IOException e) { - throw new PoyntSdkException("Failed to handle error for response."); - } - } - - private String readResponse(HttpResponse response) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); - StringBuffer sb = new StringBuffer(); - String line = ""; - while ((line = reader.readLine()) != null) { - sb.append(line); - } - - return sb.toString(); - } - - public T readResponse(HttpResponse response, Class resourceType) throws IOException { - String responseContent = readResponse(response); - - T result = (T) this.sdk.getOm().readValue(responseContent, resourceType); - return result; - } - - public List readListResponse(HttpResponse response, Class resourceType) throws IOException { - String responseContent = readResponse(response); - - List> tmp = this.sdk.getOm().readValue(responseContent, List.class); - List result = new ArrayList(tmp.size()); - for (Map obj : tmp) { - T item = this.sdk.getOm().convertValue(obj, resourceType); - result.add(item); - } - - return result; - } - - public T get(Class resourceType, String itemId) { - String accessToken = sdk.getAccessToken(); - - String baseUrl = this.endPoint + "/" + itemId; - HttpGet get = this.createGetRequest(baseUrl); - - get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); - T result = null; - try { - HttpResponse response = this.sdk.getHttpClient().execute(get); - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - result = (T) this.readResponse(response, resourceType); - } else { - handleError(response); - } - } catch (IOException e) { - throw new PoyntSdkException("Failed to get resource."); - } finally { - get.releaseConnection(); - } - - return result; - } - - public T getFromBusiness(Class resourceType, String businessId, String resourceId) { - String accessToken = sdk.getAccessToken(); - - String baseUrl = this.endPoint.replace("{businessId}", businessId) + "/" + resourceId; - HttpGet get = this.createGetRequest(baseUrl); - - get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); - T result = null; - try { - HttpResponse response = this.sdk.getHttpClient().execute(get); - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - result = (T) this.readResponse(response, resourceType); - } else { - handleError(response); - } - } catch (IOException e) { - throw new PoyntSdkException("Failed to get resource."); - } finally { - get.releaseConnection(); - } - - return result; - } - - public List getAllFromBusiness(Class resourceType, String businessId) { - List result = null; - String accessToken = sdk.getAccessToken(); - - String baseUrl = this.endPoint.replace("{businessId}", businessId); - HttpGet get = this.createGetRequest(baseUrl); - - get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); - try { - HttpResponse response = this.sdk.getHttpClient().execute(get); - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - result = this.readListResponse(response, resourceType); - } else { - handleError(response); - } - } catch (IOException e) { - throw new PoyntSdkException("Failed to get business"); - } finally { - get.releaseConnection(); - } - - return result; - } - - public T create(T resource) { - String accessToken = sdk.getAccessToken(); - - String baseUrl = this.endPoint; - HttpPost post = this.createPostRequest(baseUrl); - - post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); - T result = null; - try { - String payload = this.sdk.getOm().writeValueAsString(resource); - StringEntity entity = new StringEntity(payload); - post.setEntity(entity); - - HttpResponse response = this.sdk.getHttpClient().execute(post); - int httpCode = response.getStatusLine().getStatusCode(); - if (httpCode == HttpStatus.SC_ACCEPTED || httpCode == HttpStatus.SC_NO_CONTENT) { - // no result - result = null; - } else if (httpCode == HttpStatus.SC_CREATED || httpCode == HttpStatus.SC_OK) { - result = (T) this.readResponse(response, resource.getClass()); - } else { - handleError(response); - } - } catch (IOException e) { - throw new PoyntSdkException("Failed to create resource."); - } finally { - post.releaseConnection(); - } - - return result; - } - - public T createAtBusiness(T resource, String businessId) { - String accessToken = sdk.getAccessToken(); - - String baseUrl = this.endPoint.replace("{businessId}", businessId); - HttpPost post = this.createPostRequest(baseUrl); - - post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); - T result = null; - try { - String payload = this.sdk.getOm().writeValueAsString(resource); - StringEntity entity = new StringEntity(payload); - post.setEntity(entity); - - HttpResponse response = this.sdk.getHttpClient().execute(post); - int httpCode = response.getStatusLine().getStatusCode(); - if (httpCode == HttpStatus.SC_ACCEPTED || httpCode == HttpStatus.SC_NO_CONTENT) { - result = null; - } else if (httpCode == HttpStatus.SC_CREATED || httpCode == HttpStatus.SC_OK) { - result = (T) this.readResponse(response, resource.getClass()); - } else { - handleError(response); - } - } catch (IOException e) { - throw new PoyntSdkException("Failed to create resource at business."); - } finally { - post.releaseConnection(); - } - - return result; - } + + private static final Logger logger = LoggerFactory.getLogger(Api.class); + protected PoyntSdk sdk; + protected String endPoint; + + public Api(PoyntSdk sdk, String endPoint) { + this.sdk = sdk; + this.endPoint = endPoint; + } + + public HttpGet createGetRequest(String url) { + HttpGet get = new HttpGet(url); + get.setHeader(HttpHeaders.USER_AGENT, Constants.SDK_AGENT + ": " + this.sdk.getConfig().getAppId()); + get.setHeader("api-version", Constants.POYNT_API_VERSION); + return get; + } + + public HttpPost createPostRequest(String url) { + HttpPost post = new HttpPost(url); + post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); + post.setHeader(HttpHeaders.USER_AGENT, Constants.SDK_AGENT + ": " + this.sdk.getConfig().getAppId()); + post.setHeader("api-version", Constants.POYNT_API_VERSION); + return post; + } + + public void handleError(HttpResponse response) { + try { + ErrorInfo error = this.readResponse(response, ErrorInfo.class); + + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { + if (error.getCode() == Code.INVALID_ACCESS_TOKEN) { + this.sdk.clearAccessToken(); + } + else if (error.getCode() == Code.INVALID_REFRESH_TOKEN) { + this.sdk.clearRefreshToken(); + } + } + + throw new PoyntSdkException(error.getDeveloperMessage(), error); + } + catch (IOException e) { + throw new PoyntSdkException("Failed to handle error for response."); + } + } + + private String readResponse(HttpResponse response) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); + StringBuffer sb = new StringBuffer(); + String line = ""; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + + return sb.toString(); + } + + public T readResponse(HttpResponse response, Class resourceType) throws IOException { + String responseContent = readResponse(response); + + T result = (T)this.sdk.getOm().readValue(responseContent, resourceType); + return result; + } + + public List readListResponse(HttpResponse response, Class resourceType) throws IOException { + String responseContent = readResponse(response); + + List> tmp = this.sdk.getOm().readValue(responseContent, List.class); + List result = new ArrayList(tmp.size()); + for (Map obj : tmp) { + T item = this.sdk.getOm().convertValue(obj, resourceType); + result.add(item); + } + + return result; + } + + public T get(Class resourceType, String itemId) { + String accessToken = sdk.getAccessToken(); + + String baseUrl = this.endPoint + "/" + itemId; + HttpGet get = this.createGetRequest(baseUrl); + + get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + T result = null; + try { + HttpResponse response = this.sdk.getHttpClient().execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + result = (T)this.readResponse(response, resourceType); + } + else { + handleError(response); + } + } + catch (IOException e) { + + logger.error("Failed to get resource.", e); + + throw new PoyntSdkException("Failed to get resource."); + } + finally { + get.releaseConnection(); + } + + return result; + } + + public T getFromBusiness(Class resourceType, String businessId, String resourceId) { + String accessToken = sdk.getAccessToken(); + + String baseUrl = this.endPoint.replace("{businessId}", businessId) + "/" + resourceId; + HttpGet get = this.createGetRequest(baseUrl); + + get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + T result = null; + try { + HttpResponse response = this.sdk.getHttpClient().execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + result = (T)this.readResponse(response, resourceType); + } + else { + handleError(response); + } + } + catch (IOException e) { + + logger.error("Failed to get resource.", e); + + throw new PoyntSdkException("Failed to get resource."); + } + finally { + get.releaseConnection(); + } + + return result; + } + + public List getAllFromBusiness(Class resourceType, String businessId) { + List result = null; + String accessToken = sdk.getAccessToken(); + + String baseUrl = this.endPoint.replace("{businessId}", businessId); + HttpGet get = this.createGetRequest(baseUrl); + + get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + try { + HttpResponse response = this.sdk.getHttpClient().execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + result = this.readListResponse(response, resourceType); + } + else { + handleError(response); + } + } + catch (IOException e) { + + logger.error("Failed to get business", e); + + throw new PoyntSdkException("Failed to get business"); + } + finally { + get.releaseConnection(); + } + + return result; + } + + public T create(T resource) { + String accessToken = sdk.getAccessToken(); + + String baseUrl = this.endPoint; + HttpPost post = this.createPostRequest(baseUrl); + + post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + T result = null; + try { + String payload = this.sdk.getOm().writeValueAsString(resource); + StringEntity entity = new StringEntity(payload); + post.setEntity(entity); + + HttpResponse response = this.sdk.getHttpClient().execute(post); + int httpCode = response.getStatusLine().getStatusCode(); + if (httpCode == HttpStatus.SC_ACCEPTED || httpCode == HttpStatus.SC_NO_CONTENT) { + // no result + result = null; + } + else if (httpCode == HttpStatus.SC_CREATED || httpCode == HttpStatus.SC_OK) { + result = (T)this.readResponse(response, resource.getClass()); + } + else { + handleError(response); + } + } + catch (IOException e) { + + logger.error("Failed to create resource.", e); + + throw new PoyntSdkException("Failed to create resource."); + } + finally { + post.releaseConnection(); + } + + return result; + } + + public T createAtBusiness(T resource, String businessId) { + String accessToken = sdk.getAccessToken(); + + String baseUrl = this.endPoint.replace("{businessId}", businessId); + HttpPost post = this.createPostRequest(baseUrl); + + post.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + T result = null; + try { + String payload = this.sdk.getOm().writeValueAsString(resource); + StringEntity entity = new StringEntity(payload); + post.setEntity(entity); + + HttpResponse response = this.sdk.getHttpClient().execute(post); + int httpCode = response.getStatusLine().getStatusCode(); + if (httpCode == HttpStatus.SC_ACCEPTED || httpCode == HttpStatus.SC_NO_CONTENT) { + result = null; + } + else if (httpCode == HttpStatus.SC_CREATED || httpCode == HttpStatus.SC_OK) { + result = (T)this.readResponse(response, resource.getClass()); + } + else { + handleError(response); + } + } + catch (IOException e) { + logger.error("Failed to create resource at business.", e); + throw new PoyntSdkException("Failed to create resource at business."); + } + finally { + post.releaseConnection(); + } + + return result; + } } diff --git a/src/main/java/co/poynt/api/sdk/ApiSubscription.java b/src/main/java/co/poynt/api/sdk/ApiSubscription.java new file mode 100644 index 0000000..3320fc7 --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/ApiSubscription.java @@ -0,0 +1,78 @@ +package co.poynt.api.sdk; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.apache.http.HttpHeaders; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpGet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.core.type.TypeReference; + +import co.poynt.api.model.ResourceList; + +public class ApiSubscription extends Api { + + private static final Logger logger = LoggerFactory.getLogger(ApiSubscription.class); + + public static final String API_SUBSCRIPTIONS = "/apps/{appId}/subscriptions?businessId={businessId}"; + + public ApiSubscription(PoyntSdk sdk, String appId) { + + super(sdk, Constants.POYNT_BILLING_API_HOST + API_SUBSCRIPTIONS.replace("{appId}", appId)); + + } + + public ResourceList getAllFromBusiness2(Class resourceType, String businessId) { + ResourceList result = null; + String accessToken = sdk.getAccessToken(); + + String baseUrl = this.endPoint.replace("{businessId}", businessId); + HttpGet get = this.createGetRequest(baseUrl); + + get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + try { + HttpResponse response = this.sdk.getHttpClient().execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + result = this.readResourceListResponse(response); + } + else { + handleError(response); + } + } + catch (IOException e) { + + logger.error("Failed to get business", e); + + throw new PoyntSdkException("Failed to get business"); + } + finally { + get.releaseConnection(); + } + + return result; + } + + public ResourceList readResourceListResponse(HttpResponse response) throws IOException { + String responseContent = readResponse(response); + + ResourceList responseList = this.sdk.getOm().readValue(responseContent, new TypeReference>() {}); + return responseList; + } + + private String readResponse(HttpResponse response) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); + StringBuffer sb = new StringBuffer(); + String line = ""; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + + return sb.toString(); + } + +} diff --git a/src/main/java/co/poynt/api/sdk/Constants.java b/src/main/java/co/poynt/api/sdk/Constants.java index aadcddc..d8ef05a 100644 --- a/src/main/java/co/poynt/api/sdk/Constants.java +++ b/src/main/java/co/poynt/api/sdk/Constants.java @@ -14,6 +14,7 @@ public class Constants { public static final String POYNT_API_VERSION = "1.2"; public static final String POYNT_API_HOST = "https://services.poynt.net"; + public static final String POYNT_BILLING_API_HOST = "https://billing.poynt.net"; public static final String API_TOKEN = "/token"; public static final String API_BUSINESSES = "/businesses"; public static final String API_BUSINESS_USERS = "/businesses/{businessId}/businessUsers"; diff --git a/src/main/java/co/poynt/api/sdk/Main2.java b/src/main/java/co/poynt/api/sdk/Main2.java index 35dc9c2..3f3fe3c 100644 --- a/src/main/java/co/poynt/api/sdk/Main2.java +++ b/src/main/java/co/poynt/api/sdk/Main2.java @@ -13,17 +13,20 @@ import co.poynt.api.model.Business; import co.poynt.api.model.BusinessUser; import co.poynt.api.model.Hook; +import co.poynt.api.model.ResourceList; +import co.poynt.api.model.Subscription; public class Main2 { public static void main(String[] args) throws FileNotFoundException { final String businessId = "feb2ea1a-d05b-4fa2-bc93-dfb9fdd4cb8f"; //geneva + final String appId = "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; //"891b396d-fe26-4339-a810-ff2af2e277ba"; opinion PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); Reader reader = new InputStreamReader(Main2.class.getClassLoader().getResourceAsStream("urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem")); - builder2.configure("urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f", reader); + builder2.configure(appId, reader); builder2.rebuild(sdk); Map claims = ((JsonWebTokenService)builder2.jwt).decode(sdk.getAccessToken()); @@ -34,9 +37,15 @@ public static void main(String[] args) throws FileNotFoundException { Business business = sdk.business().get(businessId); System.out.println("============= BUSINESS =" + business); - System.out.println("============= BUSINESS USER"); + System.out.println("============= BUSINESS USERS"); List users = sdk.businessUser().getAll(businessId); System.out.println(users); + + + System.out.println("============= SUBSCRIPTIONS"); + ApiSubscription apiSubscription = new ApiSubscription(sdk, appId); + ResourceList subscriptions = apiSubscription.getAllFromBusiness2(Subscription.class, businessId); + System.out.println(subscriptions); // System.out.println("=============CATALOG"); // CatalogWithProduct catalog = sdk.catalog().get(businessId, "675f0c80-6db8-4584-a444-6b213d0f4f66"); From 987571d30e5a5effbf173beaae26b19c0d34a8c0 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Mon, 29 Oct 2018 19:26:43 -0700 Subject: [PATCH 06/26] TAPS-1369 added billing --- src/main/java/co/poynt/api/model/Amount.java | 88 ++++++ src/main/java/co/poynt/api/model/Plan.java | 253 ++++++++++++++++++ .../java/co/poynt/api/sdk/ApiBilling.java | 85 ++++++ src/main/java/co/poynt/api/sdk/ApiPlan.java | 62 +++++ .../co/poynt/api/sdk/ApiSubscription.java | 35 +-- src/main/java/co/poynt/api/sdk/Main.java | 2 +- src/main/java/co/poynt/api/sdk/Main2.java | 29 +- 7 files changed, 518 insertions(+), 36 deletions(-) create mode 100644 src/main/java/co/poynt/api/model/Amount.java create mode 100644 src/main/java/co/poynt/api/model/Plan.java create mode 100644 src/main/java/co/poynt/api/sdk/ApiBilling.java create mode 100644 src/main/java/co/poynt/api/sdk/ApiPlan.java diff --git a/src/main/java/co/poynt/api/model/Amount.java b/src/main/java/co/poynt/api/model/Amount.java new file mode 100644 index 0000000..c062720 --- /dev/null +++ b/src/main/java/co/poynt/api/model/Amount.java @@ -0,0 +1,88 @@ +package co.poynt.api.model; + +import java.util.HashMap; +import java.util.Map; +import javax.validation.Valid; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "country", + "currency", + "value" +}) +public class Amount { + + @JsonProperty("country") + private String country; + @JsonProperty("currency") + private String currency; + @JsonProperty("value") + private Integer value; + @JsonIgnore + @Valid + private Map additionalProperties = new HashMap(); + + @JsonProperty("country") + public String getCountry() { + return country; + } + + @JsonProperty("country") + public void setCountry(String country) { + this.country = country; + } + + @JsonProperty("currency") + public String getCurrency() { + return currency; + } + + @JsonProperty("currency") + public void setCurrency(String currency) { + this.currency = currency; + } + + @JsonProperty("value") + public Integer getValue() { + return value; + } + + @JsonProperty("value") + public void setValue(Integer value) { + this.value = value; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Amount [country="); + builder.append(country); + builder.append(", currency="); + builder.append(currency); + builder.append(", value="); + builder.append(value); + builder.append(", additionalProperties="); + builder.append(additionalProperties); + builder.append("]"); + return builder.toString(); + } + + + +} \ No newline at end of file diff --git a/src/main/java/co/poynt/api/model/Plan.java b/src/main/java/co/poynt/api/model/Plan.java new file mode 100644 index 0000000..244f00c --- /dev/null +++ b/src/main/java/co/poynt/api/model/Plan.java @@ -0,0 +1,253 @@ +package co.poynt.api.model; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.validation.Valid; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "createdAt", + "updatedAt", + "amounts", + "interval", + "trialPeriodDays", + "startPolicy", + "cancelPolicy", + "appId", + "amount", + "planId", + "scope", + "description", + "status", + "name" +}) +public class Plan { + + @JsonProperty("createdAt") + private String createdAt; + @JsonProperty("updatedAt") + private String updatedAt; + @JsonProperty("amounts") + @Valid + private List amounts = null; + @JsonProperty("interval") + private String interval; + @JsonProperty("trialPeriodDays") + private Integer trialPeriodDays; + @JsonProperty("startPolicy") + private String startPolicy; + @JsonProperty("cancelPolicy") + private String cancelPolicy; + @JsonProperty("appId") + private String appId; + @JsonProperty("amount") + private Integer amount; + @JsonProperty("planId") + private String planId; + @JsonProperty("scope") + private String scope; + @JsonProperty("description") + private String description; + @JsonProperty("status") + private String status; + @JsonProperty("name") + private String name; + @JsonIgnore + @Valid + private Map additionalProperties = new HashMap(); + + @JsonProperty("createdAt") + public String getCreatedAt() { + return createdAt; + } + + @JsonProperty("createdAt") + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + @JsonProperty("updatedAt") + public String getUpdatedAt() { + return updatedAt; + } + + @JsonProperty("updatedAt") + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + @JsonProperty("amounts") + public List getAmounts() { + return amounts; + } + + @JsonProperty("amounts") + public void setAmounts(List amounts) { + this.amounts = amounts; + } + + @JsonProperty("interval") + public String getInterval() { + return interval; + } + + @JsonProperty("interval") + public void setInterval(String interval) { + this.interval = interval; + } + + @JsonProperty("trialPeriodDays") + public Integer getTrialPeriodDays() { + return trialPeriodDays; + } + + @JsonProperty("trialPeriodDays") + public void setTrialPeriodDays(Integer trialPeriodDays) { + this.trialPeriodDays = trialPeriodDays; + } + + @JsonProperty("startPolicy") + public String getStartPolicy() { + return startPolicy; + } + + @JsonProperty("startPolicy") + public void setStartPolicy(String startPolicy) { + this.startPolicy = startPolicy; + } + + @JsonProperty("cancelPolicy") + public String getCancelPolicy() { + return cancelPolicy; + } + + @JsonProperty("cancelPolicy") + public void setCancelPolicy(String cancelPolicy) { + this.cancelPolicy = cancelPolicy; + } + + @JsonProperty("appId") + public String getAppId() { + return appId; + } + + @JsonProperty("appId") + public void setAppId(String appId) { + this.appId = appId; + } + + @JsonProperty("amount") + public Integer getAmount() { + return amount; + } + + @JsonProperty("amount") + public void setAmount(Integer amount) { + this.amount = amount; + } + + @JsonProperty("planId") + public String getPlanId() { + return planId; + } + + @JsonProperty("planId") + public void setPlanId(String planId) { + this.planId = planId; + } + + @JsonProperty("scope") + public String getScope() { + return scope; + } + + @JsonProperty("scope") + public void setScope(String scope) { + this.scope = scope; + } + + @JsonProperty("description") + public String getDescription() { + return description; + } + + @JsonProperty("description") + public void setDescription(String description) { + this.description = description; + } + + @JsonProperty("status") + public String getStatus() { + return status; + } + + @JsonProperty("status") + public void setStatus(String status) { + this.status = status; + } + + @JsonProperty("name") + public String getName() { + return name; + } + + @JsonProperty("name") + public void setName(String name) { + this.name = name; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Plan [createdAt="); + builder.append(createdAt); + builder.append(", updatedAt="); + builder.append(updatedAt); + builder.append(", amounts="); + builder.append(amounts); + builder.append(", interval="); + builder.append(interval); + builder.append(", trialPeriodDays="); + builder.append(trialPeriodDays); + builder.append(", startPolicy="); + builder.append(startPolicy); + builder.append(", cancelPolicy="); + builder.append(cancelPolicy); + builder.append(", appId="); + builder.append(appId); + builder.append(", amount="); + builder.append(amount); + builder.append(", planId="); + builder.append(planId); + builder.append(", scope="); + builder.append(scope); + builder.append(", description="); + builder.append(description); + builder.append(", status="); + builder.append(status); + builder.append(", name="); + builder.append(name); + builder.append(", additionalProperties="); + builder.append(additionalProperties); + builder.append("]"); + return builder.toString(); + } + +} \ No newline at end of file diff --git a/src/main/java/co/poynt/api/sdk/ApiBilling.java b/src/main/java/co/poynt/api/sdk/ApiBilling.java new file mode 100644 index 0000000..f5cb161 --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/ApiBilling.java @@ -0,0 +1,85 @@ +package co.poynt.api.sdk; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.apache.http.HttpHeaders; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpGet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.core.type.TypeReference; + +import co.poynt.api.model.ResourceList; + +/** + * ApiBilling provides methods to manage Poynt Billing + * @author sanjay + * + */ +public class ApiBilling extends Api { + + static final Logger logger = LoggerFactory.getLogger(ApiBilling.class); + + public ApiBilling(PoyntSdk sdk, String endPoint) { + super(sdk, endPoint); + // TODO Auto-generated constructor stub + } + + public ResourceList readResourceListResponse(HttpResponse response) throws IOException { + String responseContent = readResponse(response); + + ResourceList responseList = this.sdk.getOm().readValue(responseContent, new TypeReference>() {}); + return responseList; + } + + private String readResponse(HttpResponse response) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); + StringBuffer sb = new StringBuffer(); + String line = ""; + while ((line = reader.readLine()) != null) { + sb.append(line); + } + + return sb.toString(); + } + + /** + * getAll + * @param resourceType + * @return + */ + public ResourceList getAll() { + ResourceList result = null; + String accessToken = sdk.getAccessToken(); + + String baseUrl = this.endPoint; + HttpGet get = this.createGetRequest(baseUrl); + + get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + try { + HttpResponse response = this.sdk.getHttpClient().execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + result = this.readResourceListResponse(response); + } + else { + handleError(response); + } + } + catch (IOException e) { + + logger.error("Failed to get resource", e); + + throw new PoyntSdkException("Failed to get resource " + e.getMessage()); + } + finally { + get.releaseConnection(); + } + + return result; + } + +} diff --git a/src/main/java/co/poynt/api/sdk/ApiPlan.java b/src/main/java/co/poynt/api/sdk/ApiPlan.java new file mode 100644 index 0000000..c4ef16e --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/ApiPlan.java @@ -0,0 +1,62 @@ +package co.poynt.api.sdk; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ApiPlan extends ApiBilling { + + static final Logger logger = LoggerFactory.getLogger(ApiPlan.class); + + public static final String API_PLANS = "/apps/{appId}/plans"; + + public ApiPlan(PoyntSdk sdk, String appId) { + + super(sdk, Constants.POYNT_BILLING_API_HOST + API_PLANS.replace("{appId}", appId)); + + } + /** + * { + "list": [{ + "description": "Wifi plan", + "scope": "STORE", + "createdAt": "2018-10-23T19:18:25Z", + "updatedAt": "2018-10-23T19:18:25Z", + "amounts": [{ + "country": "US", + "currency": "USD", + "value": 100 + }], + "interval": "MONTH", + "trialPeriodDays": 0, + "startPolicy": "IMMEDIATE", + "cancelPolicy": "BILLING", + "appId": "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f", + "amount": 100, + "planId": "21e8ad2b-0fde-43b6-bcd9-276855ed092c", + "status": "ACTIVE", + "name": "Test WiFi" + }, { + "description": "Use this test plan for testing", + "scope": "STORE", + "createdAt": "2018-10-23T19:18:21Z", + "updatedAt": "2018-10-23T19:18:21Z", + "amounts": [{ + "country": "US", + "currency": "USD", + "value": 100 + }], + "interval": "MONTH", + "trialPeriodDays": 0, + "startPolicy": "IMMEDIATE", + "cancelPolicy": "BILLING", + "appId": "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f", + "amount": 100, + "planId": "9f89bac6-732d-4fdf-b8f5-9f255e246489", + "status": "ACTIVE", + "name": "Test Email" + }], + "start": 0, + "total": 2, + "count": 2 + */ +} diff --git a/src/main/java/co/poynt/api/sdk/ApiSubscription.java b/src/main/java/co/poynt/api/sdk/ApiSubscription.java index 3320fc7..f3e9b3e 100644 --- a/src/main/java/co/poynt/api/sdk/ApiSubscription.java +++ b/src/main/java/co/poynt/api/sdk/ApiSubscription.java @@ -1,8 +1,6 @@ package co.poynt.api.sdk; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; @@ -11,11 +9,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.core.type.TypeReference; - import co.poynt.api.model.ResourceList; +import co.poynt.api.model.Subscription; -public class ApiSubscription extends Api { +public class ApiSubscription extends ApiBilling { private static final Logger logger = LoggerFactory.getLogger(ApiSubscription.class); @@ -27,8 +24,8 @@ public ApiSubscription(PoyntSdk sdk, String appId) { } - public ResourceList getAllFromBusiness2(Class resourceType, String businessId) { - ResourceList result = null; + public ResourceList getAllFromBusiness(String businessId) { + ResourceList result = null; String accessToken = sdk.getAccessToken(); String baseUrl = this.endPoint.replace("{businessId}", businessId); @@ -40,15 +37,18 @@ public ResourceList getAllFromBusiness2(Class resourceType, String bus if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { result = this.readResourceListResponse(response); } + else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { + logger.error("No subscription found for businessId={} error={}", businessId, response.toString()); + } else { handleError(response); } } catch (IOException e) { - logger.error("Failed to get business", e); + logger.error("Failed to get subscriptions", e); - throw new PoyntSdkException("Failed to get business"); + throw new PoyntSdkException("Failed to get subscriptions"); } finally { get.releaseConnection(); @@ -57,22 +57,5 @@ public ResourceList getAllFromBusiness2(Class resourceType, String bus return result; } - public ResourceList readResourceListResponse(HttpResponse response) throws IOException { - String responseContent = readResponse(response); - - ResourceList responseList = this.sdk.getOm().readValue(responseContent, new TypeReference>() {}); - return responseList; - } - - private String readResponse(HttpResponse response) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); - StringBuffer sb = new StringBuffer(); - String line = ""; - while ((line = reader.readLine()) != null) { - sb.append(line); - } - - return sb.toString(); - } } diff --git a/src/main/java/co/poynt/api/sdk/Main.java b/src/main/java/co/poynt/api/sdk/Main.java index 5394337..2706c8e 100644 --- a/src/main/java/co/poynt/api/sdk/Main.java +++ b/src/main/java/co/poynt/api/sdk/Main.java @@ -34,7 +34,7 @@ public static void main(String[] args) { System.out.println("=============Webhooks"); Hook hook = new Hook(); hook.setApplicationId(sdk.getConfig().getAppId()); - hook.setBusinessId(UUID.fromString(businessId)); + //hook.setBusinessId(UUID.fromString(businessId)); hook.setDeliveryUrl("https://my-webhook-recipient.com/somewhere"); hook.setEventTypes(Arrays.asList(new String[] { "ORDER_OPENED", "PRODUCT_CREATED" })); diff --git a/src/main/java/co/poynt/api/sdk/Main2.java b/src/main/java/co/poynt/api/sdk/Main2.java index 3f3fe3c..8bd1629 100644 --- a/src/main/java/co/poynt/api/sdk/Main2.java +++ b/src/main/java/co/poynt/api/sdk/Main2.java @@ -6,6 +6,8 @@ import java.io.InputStreamReader; import java.io.Reader; import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -13,6 +15,7 @@ import co.poynt.api.model.Business; import co.poynt.api.model.BusinessUser; import co.poynt.api.model.Hook; +import co.poynt.api.model.Plan; import co.poynt.api.model.ResourceList; import co.poynt.api.model.Subscription; @@ -33,18 +36,26 @@ public static void main(String[] args) throws FileNotFoundException { System.out.println("============= claims = " + claims.toString()); //String businessId = (String)claims.get(PoyntSdkBuilder.POYNT_JWT_CLAIM_ORG); System.out.println("============= BUSINESS id=" + businessId); - + Business business = sdk.business().get(businessId); System.out.println("============= BUSINESS =" + business); System.out.println("============= BUSINESS USERS"); List users = sdk.businessUser().getAll(businessId); System.out.println(users); - - + + System.out.println("============= Plans"); + ApiBilling apiPlan = new ApiPlan(sdk, appId); + ResourceList plans = apiPlan.getAll(); + System.out.println(plans); + Map ps = new HashMap(); + for (int i=0; i subscriptions = apiSubscription.getAllFromBusiness2(Subscription.class, businessId); + ResourceList subscriptions = apiSubscription.getAllFromBusiness(businessId); System.out.println(subscriptions); // System.out.println("=============CATALOG"); @@ -58,17 +69,17 @@ public static void main(String[] args) throws FileNotFoundException { System.out.println("=============Webhooks"); Hook hook = new Hook(); hook.setApplicationId(sdk.getConfig().getAppId()); - hook.setBusinessId(UUID.fromString(businessId)); - hook.setDeliveryUrl("https://engage.colligso.com/poynt"); - hook.setEventTypes(Arrays.asList(new String[] { "ORDER_COMPLETED", "TRANSACTION_AUTHORIZED" })); + hook.setBusinessId(UUID.fromString("6dc5a48d-8f99-41e9-b716-b3c564f0711c")); //orgid of Colligso + hook.setDeliveryUrl("https://stage.colligso.com/poynt/webhook"); + hook.setEventTypes(Arrays.asList(new String[] { "APPLICATION_SUBSCRIPTION_START", "APPLICATION_SUBSCRIPTION_END" })); // Poynt will use the secret below to generate a signature using // HmacSHA1 of the webhook payload // The signature will be send as an http header called // "poynt-webhook-signature". hook.setSecret("my-shared-secret-with-poynt"); - sdk.webhook().register(hook); - + Hook resHook = sdk.webhook().register(hook); + System.out.println("Hook response=" + resHook.toString()); System.out.println("=============Done!"); } } From 16b0044921c4e225fa854097868256d28b80b905 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Tue, 30 Oct 2018 21:23:49 -0700 Subject: [PATCH 07/26] TAPS-1369 separated webhook and plan from main2 --- src/main/java/co/poynt/api/sdk/Main2.java | 27 ++------- .../co/poynt/api/sdk/RegisterWebhook.java | 57 +++++++++++++++++++ 2 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 src/main/java/co/poynt/api/sdk/RegisterWebhook.java diff --git a/src/main/java/co/poynt/api/sdk/Main2.java b/src/main/java/co/poynt/api/sdk/Main2.java index 8bd1629..0358e12 100644 --- a/src/main/java/co/poynt/api/sdk/Main2.java +++ b/src/main/java/co/poynt/api/sdk/Main2.java @@ -22,7 +22,7 @@ public class Main2 { public static void main(String[] args) throws FileNotFoundException { - final String businessId = "feb2ea1a-d05b-4fa2-bc93-dfb9fdd4cb8f"; //geneva + final String businessId = "11616893-4a93-4f1a-b81a-8762abf1d8c6"; //cafe cafe //"feb2ea1a-d05b-4fa2-bc93-dfb9fdd4cb8f"; //geneva final String appId = "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; //"891b396d-fe26-4339-a810-ff2af2e277ba"; opinion PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); @@ -44,19 +44,15 @@ public static void main(String[] args) throws FileNotFoundException { List users = sdk.businessUser().getAll(businessId); System.out.println(users); - System.out.println("============= Plans"); - ApiBilling apiPlan = new ApiPlan(sdk, appId); - ResourceList plans = apiPlan.getAll(); - System.out.println(plans); - Map ps = new HashMap(); - for (int i=0; i subscriptions = apiSubscription.getAllFromBusiness(businessId); System.out.println(subscriptions); + for(Object subscription: subscriptions.getList()) { + System.out.println("subscription=" + ((Map)subscription).toString()); + } + // System.out.println("=============CATALOG"); // CatalogWithProduct catalog = sdk.catalog().get(businessId, "675f0c80-6db8-4584-a444-6b213d0f4f66"); @@ -66,20 +62,7 @@ public static void main(String[] args) throws FileNotFoundException { // Product product = sdk.product().get(businessId, "675f0c80-6db8-4584-a444-6b213d0f4f66"); // System.out.println(product); - System.out.println("=============Webhooks"); - Hook hook = new Hook(); - hook.setApplicationId(sdk.getConfig().getAppId()); - hook.setBusinessId(UUID.fromString("6dc5a48d-8f99-41e9-b716-b3c564f0711c")); //orgid of Colligso - hook.setDeliveryUrl("https://stage.colligso.com/poynt/webhook"); - hook.setEventTypes(Arrays.asList(new String[] { "APPLICATION_SUBSCRIPTION_START", "APPLICATION_SUBSCRIPTION_END" })); - // Poynt will use the secret below to generate a signature using - // HmacSHA1 of the webhook payload - // The signature will be send as an http header called - // "poynt-webhook-signature". - hook.setSecret("my-shared-secret-with-poynt"); - Hook resHook = sdk.webhook().register(hook); - System.out.println("Hook response=" + resHook.toString()); System.out.println("=============Done!"); } } diff --git a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java new file mode 100644 index 0000000..07b44be --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java @@ -0,0 +1,57 @@ +package co.poynt.api.sdk; + +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Arrays; +import java.util.UUID; + +import co.poynt.api.model.Hook; +import co.poynt.api.model.Plan; +import co.poynt.api.model.ResourceList; + +/** + * Utility to register webhook for givne app + * @author sanjay + * + */ +public class RegisterWebhook { + public static void main(String[] args) throws FileNotFoundException { + + final String businessId = "6dc5a48d-8f99-41e9-b716-b3c564f0711c"; //colligso + final String appId = "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; //spotinstage + final String webhookUrl = "https://stage.colligso.com/poynt/webhook"; + + PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); + + PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); + Reader reader = new InputStreamReader(RegisterWebhook.class.getClassLoader().getResourceAsStream("urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem")); + builder2.configure(appId, reader); + builder2.rebuild(sdk); + + System.out.println("============= Plans"); + ApiBilling apiPlan = new ApiPlan(sdk, appId); + ResourceList plans = apiPlan.getAll(); + System.out.println(plans); + for (Object plan: plans.getList()) { + System.out.println("plan=" + plan.toString()); + } + + + System.out.println("=============Webhooks"); + Hook hook = new Hook(); + hook.setApplicationId(sdk.getConfig().getAppId()); + hook.setBusinessId(UUID.fromString(businessId)); //orgid of Colligso + hook.setDeliveryUrl(webhookUrl); + hook.setEventTypes(Arrays.asList(new String[] { "APPLICATION_SUBSCRIPTION_START", "APPLICATION_SUBSCRIPTION_END" })); + + // Poynt will use the secret below to generate a signature using + // HmacSHA1 of the webhook payload + // The signature will be send as an http header called + // "poynt-webhook-signature". + hook.setSecret("my-shared-secret-with-poynt"); + Hook resHook = sdk.webhook().register(hook); + System.out.println("Hook response=" + resHook.toString()); + System.out.println("=============Done!"); + } +} From 6c37374acb380e4f6076a6370b259e366f38edd5 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Wed, 31 Oct 2018 22:55:58 -0700 Subject: [PATCH 08/26] subscription path change --- src/main/java/co/poynt/api/sdk/ApiSubscription.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiSubscription.java b/src/main/java/co/poynt/api/sdk/ApiSubscription.java index f3e9b3e..9449afb 100644 --- a/src/main/java/co/poynt/api/sdk/ApiSubscription.java +++ b/src/main/java/co/poynt/api/sdk/ApiSubscription.java @@ -16,7 +16,7 @@ public class ApiSubscription extends ApiBilling { private static final Logger logger = LoggerFactory.getLogger(ApiSubscription.class); - public static final String API_SUBSCRIPTIONS = "/apps/{appId}/subscriptions?businessId={businessId}"; + public static final String API_SUBSCRIPTIONS = "/apps/{appId}/subscriptions"; public ApiSubscription(PoyntSdk sdk, String appId) { @@ -27,8 +27,9 @@ public ApiSubscription(PoyntSdk sdk, String appId) { public ResourceList getAllFromBusiness(String businessId) { ResourceList result = null; String accessToken = sdk.getAccessToken(); + String baseUrl = this.endPoint + "?businessId={businessId}"; - String baseUrl = this.endPoint.replace("{businessId}", businessId); + baseUrl = baseUrl.replace("{businessId}", businessId); HttpGet get = this.createGetRequest(baseUrl); get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); @@ -57,5 +58,4 @@ else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { return result; } - } From fbab3886a3a926413c30d5858a490358e83f9498 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Fri, 2 Nov 2018 07:35:20 -0700 Subject: [PATCH 09/26] added webhook registration test for both an app and app for business --- .../java/co/poynt/api/sdk/RegisterWebhook.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java index 07b44be..0a2ed6f 100644 --- a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java +++ b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java @@ -41,9 +41,9 @@ public static void main(String[] args) throws FileNotFoundException { System.out.println("=============Webhooks"); Hook hook = new Hook(); hook.setApplicationId(sdk.getConfig().getAppId()); - hook.setBusinessId(UUID.fromString(businessId)); //orgid of Colligso + hook.setBusinessId(UUID.fromString("11616893-4a93-4f1a-b81a-8762abf1d8c6")); //cafe cafe hook.setDeliveryUrl(webhookUrl); - hook.setEventTypes(Arrays.asList(new String[] { "APPLICATION_SUBSCRIPTION_START", "APPLICATION_SUBSCRIPTION_END" })); + hook.setEventTypes(Arrays.asList(new String[] { "ORDER_COMPLETED"})); // Poynt will use the secret below to generate a signature using // HmacSHA1 of the webhook payload @@ -52,6 +52,20 @@ public static void main(String[] args) throws FileNotFoundException { hook.setSecret("my-shared-secret-with-poynt"); Hook resHook = sdk.webhook().register(hook); System.out.println("Hook response=" + resHook.toString()); + + + hook = new Hook(); + hook.setApplicationId(sdk.getConfig().getAppId()); + hook.setBusinessId(UUID.fromString(businessId)); //orgid of Colligso + hook.setDeliveryUrl(webhookUrl); + hook.setEventTypes(Arrays.asList(new String[] { "APPLICATION_SUBSCRIPTION_START", "APPLICATION_SUBSCRIPTION_END"})); + + // Poynt will use the secret below to generate a signature using + // HmacSHA1 of the webhook payload + // The signature will be send as an http header called + // "poynt-webhook-signature". + hook.setSecret("my-shared-secret-with-poynt"); + resHook = sdk.webhook().register(hook); System.out.println("=============Done!"); } } From 18d7c9479a734ef51cba520cce5337aeeb6bf5f5 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Sat, 3 Nov 2018 08:55:55 -0700 Subject: [PATCH 10/26] Added store calls --- .../java/co/poynt/api/model/Subscription.java | 13 +++++- src/main/java/co/poynt/api/sdk/ApiStore.java | 21 ++++++++++ src/main/java/co/poynt/api/sdk/Constants.java | 41 ++++++++++--------- src/main/java/co/poynt/api/sdk/Main2.java | 10 ++++- 4 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 src/main/java/co/poynt/api/sdk/ApiStore.java diff --git a/src/main/java/co/poynt/api/model/Subscription.java b/src/main/java/co/poynt/api/model/Subscription.java index 3ef0b30..7fbbf24 100644 --- a/src/main/java/co/poynt/api/model/Subscription.java +++ b/src/main/java/co/poynt/api/model/Subscription.java @@ -20,7 +20,8 @@ "phase", "planId", "bundleId", - "status" + "status", + "storeId" }) public class Subscription { @@ -44,6 +45,8 @@ public class Subscription { private String bundleId; @JsonProperty("status") private String status; + @JsonProperty("storeId") + private String storeId; @JsonIgnore private Map additionalProperties = new HashMap(); @@ -146,7 +149,15 @@ public String getStatus() { public void setStatus(String status) { this.status = status; } + @JsonProperty("storeId") + public String getStoreId() { + return storeId; + } + @JsonProperty("storeId") + public void setStoreId(String storeId) { + this.storeId = storeId; + } @JsonAnyGetter public Map getAdditionalProperties() { return this.additionalProperties; diff --git a/src/main/java/co/poynt/api/sdk/ApiStore.java b/src/main/java/co/poynt/api/sdk/ApiStore.java new file mode 100644 index 0000000..1ecd3fd --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/ApiStore.java @@ -0,0 +1,21 @@ +package co.poynt.api.sdk; + +import java.util.List; + + +import co.poynt.api.model.Store; + +public class ApiStore extends Api { + + public ApiStore(PoyntSdk sdk) { + super(sdk, Constants.POYNT_API_HOST + Constants.API_STORES); + } + + public List getAll(String businessId) { + return this.getAllFromBusiness(Store.class, businessId); + } + + public Store get(String businessId, String storeId) { + return this.getFromBusiness(Store.class, businessId, storeId); + } +} diff --git a/src/main/java/co/poynt/api/sdk/Constants.java b/src/main/java/co/poynt/api/sdk/Constants.java index d8ef05a..125e7a0 100644 --- a/src/main/java/co/poynt/api/sdk/Constants.java +++ b/src/main/java/co/poynt/api/sdk/Constants.java @@ -1,27 +1,28 @@ package co.poynt.api.sdk; public class Constants { - public static final String SDK_AGENT = "PoyntJavaSDK 1.0"; + public static final String SDK_AGENT = "PoyntJavaSDK 1.0"; - public static final String PROP_APP_ID = "appId"; - public static final String PROP_APP_KEY_FILE = "appKeyFile"; + public static final String PROP_APP_ID = "appId"; + public static final String PROP_APP_KEY_FILE = "appKeyFile"; - public static final String PROP_API_SOCKET_TIMEOUT = "httpSocketTimeout"; - public static final String PROP_API_CONNECT_TIMEOUT = "httpConnectTimeout"; - public static final String PROP_API_REQUEST_TIMEOUT = "httpRequestTimeout"; - public static final String PROP_API_MAX_CONNECTION = "httpMaxConnection"; - public static final String PROP_API_MAX_CONN_PER_ROUTE = "httpMaxConnectionPerRoute"; + public static final String PROP_API_SOCKET_TIMEOUT = "httpSocketTimeout"; + public static final String PROP_API_CONNECT_TIMEOUT = "httpConnectTimeout"; + public static final String PROP_API_REQUEST_TIMEOUT = "httpRequestTimeout"; + public static final String PROP_API_MAX_CONNECTION = "httpMaxConnection"; + public static final String PROP_API_MAX_CONN_PER_ROUTE = "httpMaxConnectionPerRoute"; - public static final String POYNT_API_VERSION = "1.2"; - public static final String POYNT_API_HOST = "https://services.poynt.net"; - public static final String POYNT_BILLING_API_HOST = "https://billing.poynt.net"; - public static final String API_TOKEN = "/token"; - public static final String API_BUSINESSES = "/businesses"; - public static final String API_BUSINESS_USERS = "/businesses/{businessId}/businessUsers"; - public static final String API_CATALOGS = "/businesses/{businessId}/catalogs"; - public static final String API_PRODUCTS = "/businesses/{businessId}/products"; - public static final String API_TRANSACTIONS = "/businesses/{businessId}/transactions"; - public static final String API_ORDERS = "/businesses/{businessId}/orders"; - public static final String API_CLOUD_MESSAGES = "/cloudMessages"; - public static final String API_WEBHOOKS = "/hooks"; + public static final String POYNT_API_VERSION = "1.2"; + public static final String POYNT_API_HOST = "https://services.poynt.net"; + public static final String POYNT_BILLING_API_HOST = "https://billing.poynt.net"; + public static final String API_TOKEN = "/token"; + public static final String API_BUSINESSES = "/businesses"; + public static final String API_BUSINESS_USERS = "/businesses/{businessId}/businessUsers"; + public static final String API_CATALOGS = "/businesses/{businessId}/catalogs"; + public static final String API_PRODUCTS = "/businesses/{businessId}/products"; + public static final String API_TRANSACTIONS = "/businesses/{businessId}/transactions"; + public static final String API_ORDERS = "/businesses/{businessId}/orders"; + public static final String API_STORES = "/businesses/{businessId}/stores"; + public static final String API_CLOUD_MESSAGES = "/cloudMessages"; + public static final String API_WEBHOOKS = "/hooks"; } diff --git a/src/main/java/co/poynt/api/sdk/Main2.java b/src/main/java/co/poynt/api/sdk/Main2.java index 0358e12..96f2480 100644 --- a/src/main/java/co/poynt/api/sdk/Main2.java +++ b/src/main/java/co/poynt/api/sdk/Main2.java @@ -17,6 +17,7 @@ import co.poynt.api.model.Hook; import co.poynt.api.model.Plan; import co.poynt.api.model.ResourceList; +import co.poynt.api.model.Store; import co.poynt.api.model.Subscription; public class Main2 { @@ -44,7 +45,14 @@ public static void main(String[] args) throws FileNotFoundException { List users = sdk.businessUser().getAll(businessId); System.out.println(users); - + System.out.println("============= STORES"); + ApiStore apiStore = new ApiStore(sdk); + List stores = apiStore.getAll(businessId); + System.out.println(stores); + + Store store = apiStore.get(businessId, "fb436567-f8e0-46c4-9309-348c4278745b"); + System.out.println(store); + System.out.println("============= SUBSCRIPTIONS"); ApiSubscription apiSubscription = new ApiSubscription(sdk, appId); ResourceList subscriptions = apiSubscription.getAllFromBusiness(businessId); From 04556a8953678e3072dd07c5c41d8a13d7743d40 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Tue, 13 Nov 2018 05:50:06 -0800 Subject: [PATCH 11/26] no checkin for pem in public repo --- ...b97-a84c-348ba0f21c3f_publicprivatekey.pem | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 src/main/resources/urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem diff --git a/src/main/resources/urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem b/src/main/resources/urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem deleted file mode 100644 index 4fbba14..0000000 --- a/src/main/resources/urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem +++ /dev/null @@ -1,36 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAkx4cJxPdJ1UNmQTBv6gJBNP98fNkrkwnn0W2/KarEu9ADwc1 -wqvm+eeQQ7N7k0508EcX/QusVhVp8s/ud/x16IjKheyBON2DIN8RXV8Lo1WhndN3 -Bz1Z2T+bJehbaPvwV21y92f/zgWtmOfdTDugaoWxqK9PEltHQter63oTSHzgMiNg -X0b/qG1936seZIsfLeKy5V5FXGnHK7fP+403Y3Lht0Mx4DsKcFXGKINpdDgeHavK -2EFe2bync19dXDZGu31nlDmpEr/1yFWIGUwBCf2t8P9vgmBtLmHbjNFieUFUX9fI -PmPCttWb8nikTmwxPiHF05RyRAMqeujXY43xCwIDAQABAoIBADe5TnGQyRJGWY2t -qxOEutHM2GHmTqrkZpeiCOMe4CqeW7W1hev0P9tFljPGjpanv4xpaVEsND0xBD33 -+3wQMLsA4TEj+XhIEwyG4aVrxFU8MKi+udWQq/EpcgNERSd5UjpTVxoWFuL67Ju/ -q2deKG9gr3/U008BKvdLCK/7P8WTEAy7TAWTxOmvgDFGw1quawVl4SceSmI4saO8 -eEsmqreQWif3hKWXRI8YvJbU9+BiH4CNU6vqMPoN4C47GsnSsvEIQyWsg2pwUlHr -QzW3A8d56FlpOeAadCcjwE0xPfho9ZdTR5EDbTPx2R7FM29sPNAqMDK8dy6kDHOP -iwlpxtECgYEAy2h86D+3BIOytGjnzOCSsOoVoIRsMkdj0TszI9lPlMA9k3QrszVp -A03H64MsR3/SFt5MbjDRiwePuWG9YSt+NqzK/FiOsrIXCBsL1G2b/9eN6SrtphB6 -zIwDTRaigxeh81eIugbk8xryvKKrczi5REpE1nKDCh4ADIisgmiQWLsCgYEAuSfF -jfjm4Hma3WvnbrokC/HGJW5/Sa2RzcbqTgiFYgPdQ1PECtkgNS2LZdEGWvxtVLnS -ynet+9z0M7HYLcEhHynNVAueaSovZ5+WI5iGJSHQycb8jhYNiRA47knyI4bc48fM -Yg/iST1RNqpHE6Kgd+iLcdZEJt9aAbAhcLeZK/ECgYAuYPmx/u0dA2ZYyl6oEUCB -RC6ANhFxeWOiDmx/rQn/McIYf/GC4Be8oByIb5VGDDf77N3idhEhMS0tKMMEh+U0 -VDvIQ+ztg7vKplgRLJjYQe7ijl43ciR9xSLvjcyqNVZA5OGRAQdtAuT7699J21Iq -5wBBIUUNpn9+XB9xcKQRBwKBgQCXarIBb6qHqor+Rs8F2029QuRzGhEYVMxnByP3 -2roRtO1OsQMih/vx4SQdiLn00HgskKaUkxkCXuiKGgebK1SF4q6a68GJaUlJKdYj -mAkj9qqDSKqjG9/H1i9ol6pgaVrdIDjBfRHmKTHwTYJAyX8HcHIRD1O+oms99Cb0 -wgCOUQKBgQDIyzZ52CS0q89yKA99YbzP+fV9peey9zZJ6lzJ7OOkdCrNQhGm0DE/ -lf5LQUG8Hj+xdeXYsXWocDZmZFN/YowGr4QqORXTzbBQOCHL1FE4qAGB+Aiqc4nh -f/o9mNOfKtbiPR0I2b5qzf9eV5C3viLJKOlMeMCHhFuRwaEq/POSng== ------END RSA PRIVATE KEY----- ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkx4cJxPdJ1UNmQTBv6gJ -BNP98fNkrkwnn0W2/KarEu9ADwc1wqvm+eeQQ7N7k0508EcX/QusVhVp8s/ud/x1 -6IjKheyBON2DIN8RXV8Lo1WhndN3Bz1Z2T+bJehbaPvwV21y92f/zgWtmOfdTDug -aoWxqK9PEltHQter63oTSHzgMiNgX0b/qG1936seZIsfLeKy5V5FXGnHK7fP+403 -Y3Lht0Mx4DsKcFXGKINpdDgeHavK2EFe2bync19dXDZGu31nlDmpEr/1yFWIGUwB -Cf2t8P9vgmBtLmHbjNFieUFUX9fIPmPCttWb8nikTmwxPiHF05RyRAMqeujXY43x -CwIDAQAB ------END PUBLIC KEY----- From d2f61d54c625dd6e4b6a6472c872fc949fec0aaa Mon Sep 17 00:00:00 2001 From: sdatgit Date: Wed, 14 Nov 2018 18:15:07 -0800 Subject: [PATCH 12/26] added tostring to Subscription, changed app for testing --- .../java/co/poynt/api/model/Subscription.java | 31 +++++++++++++++++++ .../java/co/poynt/api/sdk/ApiCustomer.java | 4 +++ .../co/poynt/api/sdk/RegisterWebhook.java | 6 ++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/poynt/api/model/Subscription.java b/src/main/java/co/poynt/api/model/Subscription.java index 7fbbf24..81b6bc1 100644 --- a/src/main/java/co/poynt/api/model/Subscription.java +++ b/src/main/java/co/poynt/api/model/Subscription.java @@ -168,4 +168,35 @@ public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Subscription [createdAt="); + builder.append(createdAt); + builder.append(", updatedAt="); + builder.append(updatedAt); + builder.append(", startAt="); + builder.append(startAt); + builder.append(", businessId="); + builder.append(businessId); + builder.append(", appId="); + builder.append(appId); + builder.append(", subscriptionId="); + builder.append(subscriptionId); + builder.append(", phase="); + builder.append(phase); + builder.append(", planId="); + builder.append(planId); + builder.append(", bundleId="); + builder.append(bundleId); + builder.append(", status="); + builder.append(status); + builder.append(", storeId="); + builder.append(storeId); + builder.append(", additionalProperties="); + builder.append(additionalProperties); + builder.append("]"); + return builder.toString(); + } + } \ No newline at end of file diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index 876cd59..04d83f5 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -20,4 +20,8 @@ public List getAll(String businessId) { createAtBusiness(customer, "businessId"); return getAllFromBusiness(Customer.class, businessId); } + + public Customer get(String businessId, String customerId) { + return this.getFromBusiness(Customer.class, businessId, customerId); + } } diff --git a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java index 0a2ed6f..f91e6b9 100644 --- a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java +++ b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java @@ -19,13 +19,15 @@ public class RegisterWebhook { public static void main(String[] args) throws FileNotFoundException { final String businessId = "6dc5a48d-8f99-41e9-b716-b3c564f0711c"; //colligso - final String appId = "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; //spotinstage + final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; //"urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; //spotinstage final String webhookUrl = "https://stage.colligso.com/poynt/webhook"; PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); - Reader reader = new InputStreamReader(RegisterWebhook.class.getClassLoader().getResourceAsStream("urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem")); + //Reader reader = new InputStreamReader(RegisterWebhook.class.getClassLoader().getResourceAsStream("urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem")); + Reader reader = new InputStreamReader(RegisterWebhook.class.getClassLoader().getResourceAsStream("urn_aid_f3bb639a-2073-4928-9d2d-6ebf34a80f04_publicprivatekey.pem")); + builder2.configure(appId, reader); builder2.rebuild(sdk); From 3c9eafda22445f053f02b0a8f8e3f363fe971700 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Sun, 18 Nov 2018 17:05:51 -0800 Subject: [PATCH 13/26] added getcustomers test --- src/main/java/co/poynt/api/sdk/Api.java | 4 +- .../java/co/poynt/api/sdk/ApiCustomer.java | 9 +++-- .../java/co/poynt/api/sdk/GetCustomers.java | 37 +++++++++++++++++++ src/main/java/co/poynt/api/sdk/PoyntSdk.java | 6 ++- .../co/poynt/api/sdk/RegisterWebhook.java | 3 +- 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/main/java/co/poynt/api/sdk/GetCustomers.java diff --git a/src/main/java/co/poynt/api/sdk/Api.java b/src/main/java/co/poynt/api/sdk/Api.java index f544232..fb2b18a 100644 --- a/src/main/java/co/poynt/api/sdk/Api.java +++ b/src/main/java/co/poynt/api/sdk/Api.java @@ -174,8 +174,8 @@ public List getAllFromBusiness(Class resourceType, String businessId) } } catch (IOException e) { - - logger.error("Failed to get business", e); + e.printStackTrace(); + logger.error("Failed to get from business {}", businessId, e); throw new PoyntSdkException("Failed to get business"); } diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index 04d83f5..e1df7ad 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -3,6 +3,7 @@ import java.util.List; import co.poynt.api.model.Customer; +import co.poynt.api.model.CustomerList; //by Wavelety, Inc. @@ -14,14 +15,16 @@ public ApiCustomer(PoyntSdk sdk) { } public List getAll(String businessId) { - - Customer customer = new Customer(); - createAtBusiness(customer, "businessId"); return getAllFromBusiness(Customer.class, businessId); } public Customer get(String businessId, String customerId) { return this.getFromBusiness(Customer.class, businessId, customerId); } + + public List getAllCustomers(String businessId) { + CustomerList list = (CustomerList)getAllFromBusiness(CustomerList.class, businessId); + return list.getCustomers(); + } } diff --git a/src/main/java/co/poynt/api/sdk/GetCustomers.java b/src/main/java/co/poynt/api/sdk/GetCustomers.java new file mode 100644 index 0000000..f84fa7a --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/GetCustomers.java @@ -0,0 +1,37 @@ +package co.poynt.api.sdk; + +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.List; + +import co.poynt.api.model.Customer; +import co.poynt.api.model.CustomerList; + +/** + * Utility to get customers for givne app + * @author sanjay + * + */ +public class GetCustomers { + public static void main(String[] args) throws FileNotFoundException { + + final String businessId = "11616893-4a93-4f1a-b81a-8762abf1d8c6"; //cafe cafe + final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; //spotindev + + PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); + + PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); + Reader reader = new InputStreamReader(GetCustomers.class.getClassLoader().getResourceAsStream("urn_aid_f3bb639a-2073-4928-9d2d-6ebf34a80f04_publicprivatekey.pem")); + + builder2.configure(appId, reader); + builder2.rebuild(sdk); + + ApiCustomer apiCustomer = new ApiCustomer(sdk); + List customers = apiCustomer.getAllCustomers(businessId); + for (Customer customer : customers) { + System.out.println("Customer=" + customer.toString()); + } + System.out.println("=============Done!"); + } +} diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdk.java b/src/main/java/co/poynt/api/sdk/PoyntSdk.java index a0a9c13..57cd5d4 100644 --- a/src/main/java/co/poynt/api/sdk/PoyntSdk.java +++ b/src/main/java/co/poynt/api/sdk/PoyntSdk.java @@ -134,7 +134,7 @@ public Builder configure(String configFile) throws PoyntSdkException { cm.setDefaultMaxPerRoute(cfg.getHttpMaxConnPerRoute()); SSLContext sslContext = SSLContexts.custom().useProtocol("TLSv1.2").build(); - //following works with jdk 1.7 + //following works with jdk 1.7 -sd SSLConnectionSocketFactory sslCSFactory = new SSLConnectionSocketFactory( sslContext, new String[] { "TLSv1.2" }, @@ -156,7 +156,9 @@ public Builder configure(String configFile) throws PoyntSdkException { this.om.setDateFormat(new ISO8601DateFormat()); this.om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - this.om.configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, false); + //not compatible with jdk 7 -sd + //this.om.configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, false); + this.om.disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT); this.om.setSerializationInclusion(JsonInclude.Include.NON_NULL); return this; diff --git a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java index f91e6b9..b44c7b9 100644 --- a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java +++ b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java @@ -19,13 +19,12 @@ public class RegisterWebhook { public static void main(String[] args) throws FileNotFoundException { final String businessId = "6dc5a48d-8f99-41e9-b716-b3c564f0711c"; //colligso - final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; //"urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; //spotinstage + final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; final String webhookUrl = "https://stage.colligso.com/poynt/webhook"; PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); - //Reader reader = new InputStreamReader(RegisterWebhook.class.getClassLoader().getResourceAsStream("urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem")); Reader reader = new InputStreamReader(RegisterWebhook.class.getClassLoader().getResourceAsStream("urn_aid_f3bb639a-2073-4928-9d2d-6ebf34a80f04_publicprivatekey.pem")); builder2.configure(appId, reader); From 6889d16a9341cad4c386f4c4aab19fcde03281cf Mon Sep 17 00:00:00 2001 From: sdatgit Date: Mon, 19 Nov 2018 21:40:20 -0800 Subject: [PATCH 14/26] JDK7 workaround, still fails to retrieve customers --- src/main/java/co/poynt/api/sdk/PoyntSdk.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/co/poynt/api/sdk/PoyntSdk.java b/src/main/java/co/poynt/api/sdk/PoyntSdk.java index 57cd5d4..65f5f0d 100644 --- a/src/main/java/co/poynt/api/sdk/PoyntSdk.java +++ b/src/main/java/co/poynt/api/sdk/PoyntSdk.java @@ -158,7 +158,6 @@ public Builder configure(String configFile) throws PoyntSdkException { this.om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); //not compatible with jdk 7 -sd //this.om.configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, false); - this.om.disable(DeserializationFeature.ACCEPT_FLOAT_AS_INT); this.om.setSerializationInclusion(JsonInclude.Include.NON_NULL); return this; From 5dc907b7b5001797797b0fb01f9e971ac32fa25f Mon Sep 17 00:00:00 2001 From: sdatgit Date: Tue, 20 Nov 2018 08:22:38 -0800 Subject: [PATCH 15/26] tested for customer --- .../java/co/poynt/api/sdk/GetCustomer.java | 43 +++++++++++++++++++ .../java/co/poynt/api/sdk/GetCustomers.java | 37 ---------------- src/main/java/co/poynt/api/sdk/Main2.java | 13 ++---- .../co/poynt/api/sdk/RegisterWebhook.java | 4 +- 4 files changed, 48 insertions(+), 49 deletions(-) create mode 100644 src/main/java/co/poynt/api/sdk/GetCustomer.java delete mode 100644 src/main/java/co/poynt/api/sdk/GetCustomers.java diff --git a/src/main/java/co/poynt/api/sdk/GetCustomer.java b/src/main/java/co/poynt/api/sdk/GetCustomer.java new file mode 100644 index 0000000..f714353 --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/GetCustomer.java @@ -0,0 +1,43 @@ +package co.poynt.api.sdk; + +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Map; + +import co.poynt.api.model.Customer; + +/** + * Utility to get customer for given app + * + */ +public class GetCustomer { + public static void main(String[] args) throws FileNotFoundException { + + final String businessId = "11616893-4a93-4f1a-b81a-8762abf1d8c6"; //cafe cafe + final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; //spotindev + + PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); + + PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); + Reader reader = new InputStreamReader(GetCustomer.class.getClassLoader().getResourceAsStream("urn_aid_f3bb639a-2073-4928-9d2d-6ebf34a80f04_publicprivatekey.pem")); + + builder2.configure(appId, reader); + builder2.rebuild(sdk); + + ApiCustomer apiCustomer = new ApiCustomer(sdk); + + //getAllCustomers has parsing problems +// List customers = apiCustomer.getAllCustomers(businessId); +// for (Customer customer : customers) { +// System.out.println("Customer=" + customer.toString()); +// } + Customer customer = apiCustomer.getFromBusiness(Customer.class, businessId, "" + 77416525); + System.out.println("retrieve customer=" + customer.toString()); + Map atts = customer.getAttributes(); + for(Map.Entry entry: atts.entrySet()) { + System.out.println("k=" + entry.getKey() + " val=" + entry.getValue()); + } + System.out.println("=============Done!"); + } +} diff --git a/src/main/java/co/poynt/api/sdk/GetCustomers.java b/src/main/java/co/poynt/api/sdk/GetCustomers.java deleted file mode 100644 index f84fa7a..0000000 --- a/src/main/java/co/poynt/api/sdk/GetCustomers.java +++ /dev/null @@ -1,37 +0,0 @@ -package co.poynt.api.sdk; - -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.List; - -import co.poynt.api.model.Customer; -import co.poynt.api.model.CustomerList; - -/** - * Utility to get customers for givne app - * @author sanjay - * - */ -public class GetCustomers { - public static void main(String[] args) throws FileNotFoundException { - - final String businessId = "11616893-4a93-4f1a-b81a-8762abf1d8c6"; //cafe cafe - final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; //spotindev - - PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); - - PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); - Reader reader = new InputStreamReader(GetCustomers.class.getClassLoader().getResourceAsStream("urn_aid_f3bb639a-2073-4928-9d2d-6ebf34a80f04_publicprivatekey.pem")); - - builder2.configure(appId, reader); - builder2.rebuild(sdk); - - ApiCustomer apiCustomer = new ApiCustomer(sdk); - List customers = apiCustomer.getAllCustomers(businessId); - for (Customer customer : customers) { - System.out.println("Customer=" + customer.toString()); - } - System.out.println("=============Done!"); - } -} diff --git a/src/main/java/co/poynt/api/sdk/Main2.java b/src/main/java/co/poynt/api/sdk/Main2.java index 96f2480..c10b69e 100644 --- a/src/main/java/co/poynt/api/sdk/Main2.java +++ b/src/main/java/co/poynt/api/sdk/Main2.java @@ -1,21 +1,13 @@ package co.poynt.api.sdk; -import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.InputStreamReader; import java.io.Reader; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.UUID; import co.poynt.api.model.Business; import co.poynt.api.model.BusinessUser; -import co.poynt.api.model.Hook; -import co.poynt.api.model.Plan; import co.poynt.api.model.ResourceList; import co.poynt.api.model.Store; import co.poynt.api.model.Subscription; @@ -24,12 +16,13 @@ public class Main2 { public static void main(String[] args) throws FileNotFoundException { final String businessId = "11616893-4a93-4f1a-b81a-8762abf1d8c6"; //cafe cafe //"feb2ea1a-d05b-4fa2-bc93-dfb9fdd4cb8f"; //geneva - final String appId = "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; + //final String appId = "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; + final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; //"891b396d-fe26-4339-a810-ff2af2e277ba"; opinion PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); - Reader reader = new InputStreamReader(Main2.class.getClassLoader().getResourceAsStream("urn_aid_08bc7784-a262-4b97-a84c-348ba0f21c3f_publicprivatekey.pem")); + Reader reader = new InputStreamReader(Main2.class.getClassLoader().getResourceAsStream("urn_aid_f3bb639a-2073-4928-9d2d-6ebf34a80f04_publicprivatekey.pem")); builder2.configure(appId, reader); builder2.rebuild(sdk); diff --git a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java index b44c7b9..c2d0c84 100644 --- a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java +++ b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java @@ -11,8 +11,8 @@ import co.poynt.api.model.ResourceList; /** - * Utility to register webhook for givne app - * @author sanjay + * Utility to register webhook for given app + * */ public class RegisterWebhook { From 05c5c572005868200efcf2e6e3288ac9b64744a4 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Sun, 17 Mar 2019 06:49:27 -0700 Subject: [PATCH 16/26] moved out wavelety tests/code --- src/main/java/co/poynt/api/sdk/Main2.java | 69 ------------------ .../co/poynt/api/sdk/RegisterWebhook.java | 72 ------------------- 2 files changed, 141 deletions(-) delete mode 100644 src/main/java/co/poynt/api/sdk/Main2.java delete mode 100644 src/main/java/co/poynt/api/sdk/RegisterWebhook.java diff --git a/src/main/java/co/poynt/api/sdk/Main2.java b/src/main/java/co/poynt/api/sdk/Main2.java deleted file mode 100644 index c10b69e..0000000 --- a/src/main/java/co/poynt/api/sdk/Main2.java +++ /dev/null @@ -1,69 +0,0 @@ -package co.poynt.api.sdk; - -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.List; -import java.util.Map; - -import co.poynt.api.model.Business; -import co.poynt.api.model.BusinessUser; -import co.poynt.api.model.ResourceList; -import co.poynt.api.model.Store; -import co.poynt.api.model.Subscription; - -public class Main2 { - public static void main(String[] args) throws FileNotFoundException { - - final String businessId = "11616893-4a93-4f1a-b81a-8762abf1d8c6"; //cafe cafe //"feb2ea1a-d05b-4fa2-bc93-dfb9fdd4cb8f"; //geneva - //final String appId = "urn:aid:08bc7784-a262-4b97-a84c-348ba0f21c3f"; - final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; - //"891b396d-fe26-4339-a810-ff2af2e277ba"; opinion - PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); - - PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); - Reader reader = new InputStreamReader(Main2.class.getClassLoader().getResourceAsStream("urn_aid_f3bb639a-2073-4928-9d2d-6ebf34a80f04_publicprivatekey.pem")); - builder2.configure(appId, reader); - builder2.rebuild(sdk); - - Map claims = ((JsonWebTokenService)builder2.jwt).decode(sdk.getAccessToken()); - System.out.println("============= claims = " + claims.toString()); - //String businessId = (String)claims.get(PoyntSdkBuilder.POYNT_JWT_CLAIM_ORG); - System.out.println("============= BUSINESS id=" + businessId); - - Business business = sdk.business().get(businessId); - System.out.println("============= BUSINESS =" + business); - - System.out.println("============= BUSINESS USERS"); - List users = sdk.businessUser().getAll(businessId); - System.out.println(users); - - System.out.println("============= STORES"); - ApiStore apiStore = new ApiStore(sdk); - List stores = apiStore.getAll(businessId); - System.out.println(stores); - - Store store = apiStore.get(businessId, "fb436567-f8e0-46c4-9309-348c4278745b"); - System.out.println(store); - - System.out.println("============= SUBSCRIPTIONS"); - ApiSubscription apiSubscription = new ApiSubscription(sdk, appId); - ResourceList subscriptions = apiSubscription.getAllFromBusiness(businessId); - System.out.println(subscriptions); - for(Object subscription: subscriptions.getList()) { - System.out.println("subscription=" + ((Map)subscription).toString()); - } - - - // System.out.println("=============CATALOG"); - // CatalogWithProduct catalog = sdk.catalog().get(businessId, "675f0c80-6db8-4584-a444-6b213d0f4f66"); - // System.out.println(catalog); - // - // System.out.println("=============PRODUCT"); - // Product product = sdk.product().get(businessId, "675f0c80-6db8-4584-a444-6b213d0f4f66"); - // System.out.println(product); - - - System.out.println("=============Done!"); - } -} diff --git a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java b/src/main/java/co/poynt/api/sdk/RegisterWebhook.java deleted file mode 100644 index c2d0c84..0000000 --- a/src/main/java/co/poynt/api/sdk/RegisterWebhook.java +++ /dev/null @@ -1,72 +0,0 @@ -package co.poynt.api.sdk; - -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.Arrays; -import java.util.UUID; - -import co.poynt.api.model.Hook; -import co.poynt.api.model.Plan; -import co.poynt.api.model.ResourceList; - -/** - * Utility to register webhook for given app - - * - */ -public class RegisterWebhook { - public static void main(String[] args) throws FileNotFoundException { - - final String businessId = "6dc5a48d-8f99-41e9-b716-b3c564f0711c"; //colligso - final String appId = "urn:aid:f3bb639a-2073-4928-9d2d-6ebf34a80f04"; - final String webhookUrl = "https://stage.colligso.com/poynt/webhook"; - - PoyntSdk sdk = PoyntSdk.builder().configure("config.properties").build(); - - PoyntSdkBuilder builder2 = new PoyntSdkBuilder(); - Reader reader = new InputStreamReader(RegisterWebhook.class.getClassLoader().getResourceAsStream("urn_aid_f3bb639a-2073-4928-9d2d-6ebf34a80f04_publicprivatekey.pem")); - - builder2.configure(appId, reader); - builder2.rebuild(sdk); - - System.out.println("============= Plans"); - ApiBilling apiPlan = new ApiPlan(sdk, appId); - ResourceList plans = apiPlan.getAll(); - System.out.println(plans); - for (Object plan: plans.getList()) { - System.out.println("plan=" + plan.toString()); - } - - - System.out.println("=============Webhooks"); - Hook hook = new Hook(); - hook.setApplicationId(sdk.getConfig().getAppId()); - hook.setBusinessId(UUID.fromString("11616893-4a93-4f1a-b81a-8762abf1d8c6")); //cafe cafe - hook.setDeliveryUrl(webhookUrl); - hook.setEventTypes(Arrays.asList(new String[] { "ORDER_COMPLETED"})); - - // Poynt will use the secret below to generate a signature using - // HmacSHA1 of the webhook payload - // The signature will be send as an http header called - // "poynt-webhook-signature". - hook.setSecret("my-shared-secret-with-poynt"); - Hook resHook = sdk.webhook().register(hook); - System.out.println("Hook response=" + resHook.toString()); - - - hook = new Hook(); - hook.setApplicationId(sdk.getConfig().getAppId()); - hook.setBusinessId(UUID.fromString(businessId)); //orgid of Colligso - hook.setDeliveryUrl(webhookUrl); - hook.setEventTypes(Arrays.asList(new String[] { "APPLICATION_SUBSCRIPTION_START", "APPLICATION_SUBSCRIPTION_END"})); - - // Poynt will use the secret below to generate a signature using - // HmacSHA1 of the webhook payload - // The signature will be send as an http header called - // "poynt-webhook-signature". - hook.setSecret("my-shared-secret-with-poynt"); - resHook = sdk.webhook().register(hook); - System.out.println("=============Done!"); - } -} From e463f2d328a73d13220fa9eec02a019311d285e2 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Wed, 20 Mar 2019 06:07:58 -0700 Subject: [PATCH 17/26] Renamed class to differentiate --- src/main/java/co/poynt/api/sdk/Api.java | 2 ++ src/main/java/co/poynt/api/sdk/ApiPlan.java | 2 +- src/main/java/co/poynt/api/sdk/ApiSubscription.java | 2 +- .../co/poynt/api/sdk/{ApiBilling.java => CustomApi.java} | 8 ++++---- 4 files changed, 8 insertions(+), 6 deletions(-) rename src/main/java/co/poynt/api/sdk/{ApiBilling.java => CustomApi.java} (90%) diff --git a/src/main/java/co/poynt/api/sdk/Api.java b/src/main/java/co/poynt/api/sdk/Api.java index fb2b18a..445eae8 100644 --- a/src/main/java/co/poynt/api/sdk/Api.java +++ b/src/main/java/co/poynt/api/sdk/Api.java @@ -47,6 +47,7 @@ public HttpPost createPostRequest(String url) { public void handleError(HttpResponse response) { try { + logger.debug("response={}", response.toString()); ErrorInfo error = this.readResponse(response, ErrorInfo.class); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { @@ -166,6 +167,7 @@ public List getAllFromBusiness(Class resourceType, String businessId) get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); try { HttpResponse response = this.sdk.getHttpClient().execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { result = this.readListResponse(response, resourceType); } diff --git a/src/main/java/co/poynt/api/sdk/ApiPlan.java b/src/main/java/co/poynt/api/sdk/ApiPlan.java index c4ef16e..10c641c 100644 --- a/src/main/java/co/poynt/api/sdk/ApiPlan.java +++ b/src/main/java/co/poynt/api/sdk/ApiPlan.java @@ -3,7 +3,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ApiPlan extends ApiBilling { +public class ApiPlan extends CustomApi { static final Logger logger = LoggerFactory.getLogger(ApiPlan.class); diff --git a/src/main/java/co/poynt/api/sdk/ApiSubscription.java b/src/main/java/co/poynt/api/sdk/ApiSubscription.java index 9449afb..de6a787 100644 --- a/src/main/java/co/poynt/api/sdk/ApiSubscription.java +++ b/src/main/java/co/poynt/api/sdk/ApiSubscription.java @@ -12,7 +12,7 @@ import co.poynt.api.model.ResourceList; import co.poynt.api.model.Subscription; -public class ApiSubscription extends ApiBilling { +public class ApiSubscription extends CustomApi { private static final Logger logger = LoggerFactory.getLogger(ApiSubscription.class); diff --git a/src/main/java/co/poynt/api/sdk/ApiBilling.java b/src/main/java/co/poynt/api/sdk/CustomApi.java similarity index 90% rename from src/main/java/co/poynt/api/sdk/ApiBilling.java rename to src/main/java/co/poynt/api/sdk/CustomApi.java index f5cb161..e411fc0 100644 --- a/src/main/java/co/poynt/api/sdk/ApiBilling.java +++ b/src/main/java/co/poynt/api/sdk/CustomApi.java @@ -16,15 +16,15 @@ import co.poynt.api.model.ResourceList; /** - * ApiBilling provides methods to manage Poynt Billing + * ColigsoApi provides methods to manage Poynt Billing, WebHooks, etc. * @author sanjay * */ -public class ApiBilling extends Api { +public class CustomApi extends Api { - static final Logger logger = LoggerFactory.getLogger(ApiBilling.class); + static final Logger logger = LoggerFactory.getLogger(CustomApi.class); - public ApiBilling(PoyntSdk sdk, String endPoint) { + public CustomApi(PoyntSdk sdk, String endPoint) { super(sdk, endPoint); // TODO Auto-generated constructor stub } From 01458c473edc0cde6ed87c9a671bbe0fb6ec38eb Mon Sep 17 00:00:00 2001 From: sdatgit Date: Wed, 3 Apr 2019 16:29:32 -0700 Subject: [PATCH 18/26] adding apiwebhooks (incomplete) --- .../java/co/poynt/api/sdk/ApiWebhooks.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/co/poynt/api/sdk/ApiWebhooks.java diff --git a/src/main/java/co/poynt/api/sdk/ApiWebhooks.java b/src/main/java/co/poynt/api/sdk/ApiWebhooks.java new file mode 100644 index 0000000..e4a6b86 --- /dev/null +++ b/src/main/java/co/poynt/api/sdk/ApiWebhooks.java @@ -0,0 +1,59 @@ +package co.poynt.api.sdk; + + +import java.io.IOException; + +import org.apache.http.HttpHeaders; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpGet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import co.poynt.api.model.ResourceList; +import co.poynt.api.model.Hook; + +public class ApiWebhooks extends CustomApi { + + private static final Logger logger = LoggerFactory.getLogger(ApiWebhooks.class); + public ApiWebhooks(PoyntSdk sdk) { + + super(sdk, Constants.POYNT_API_HOST + Constants.API_WEBHOOKS); + + } + + public ResourceList getAllFromBusiness(String businessId) { + ResourceList result = null; + String accessToken = sdk.getAccessToken(); + String baseUrl = this.endPoint + "?businessId={businessId}"; + + baseUrl = baseUrl.replace("{businessId}", businessId); + HttpGet get = this.createGetRequest(baseUrl); + + get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + try { + HttpResponse response = this.sdk.getHttpClient().execute(get); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + result = this.readResourceListResponse(response); + } + else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { + logger.error("No Hook found for businessId={} error={}", businessId, response.toString()); + } + else { + handleError(response); + } + } + catch (IOException e) { + + logger.error("Failed to get Hooks", e); + + throw new PoyntSdkException("Failed to get Hooks"); + } + finally { + get.releaseConnection(); + } + + return result; + } + +} From 607ec177ebfb613cda99e7dfd68d356e3327a486 Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Wed, 13 Jan 2021 18:44:32 -0800 Subject: [PATCH 19/26] added pagination with get customers --- .../java/co/poynt/api/sdk/ApiCustomer.java | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index e1df7ad..506d819 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -1,14 +1,23 @@ package co.poynt.api.sdk; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.methods.HttpGet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import co.poynt.api.model.Customer; import co.poynt.api.model.CustomerList; - //by Wavelety, Inc. public class ApiCustomer extends Api { - public static final String API_CUSTOMERS = "/businesses/{businessId}/customers"; + public static final String API_CUSTOMERS = "/businesses/{businessId}/customers?limit=100&startAt={startAt}&endAt={endAt}"; + private static final Logger logger = LoggerFactory.getLogger(ApiCustomer.class); public ApiCustomer(PoyntSdk sdk) { super(sdk, Constants.POYNT_API_HOST + API_CUSTOMERS); @@ -18,13 +27,49 @@ public List getAll(String businessId) { return getAllFromBusiness(Customer.class, businessId); } - + public Customer get(String businessId, String customerId) { return this.getFromBusiness(Customer.class, businessId, customerId); } - + public List getAllCustomers(String businessId) { - CustomerList list = (CustomerList)getAllFromBusiness(CustomerList.class, businessId); + CustomerList list = (CustomerList) getAllFromBusiness(CustomerList.class, businessId); return list.getCustomers(); } + + public List getAll(String businessId, String startAt, String endAt, int offset) { + List result = new ArrayList(); + String accessToken = sdk.getAccessToken(); + + String baseUrl = this.endPoint.replace("{businessId}", businessId) + .replace("startAt", startAt) + .replace("endAt", endAt) + .replace("startOffset", "" + offset); + HttpGet get = this.createGetRequest(baseUrl); + + get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + try { + HttpResponse response = this.sdk.getHttpClient().execute(get); + + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + result = this.readListResponse(response, CustomerList.class); + } + else { + handleError(response); + } + } + catch (IOException e) { + e.printStackTrace(); + logger.error("Failed to get customers from business {}", businessId, e); + throw new PoyntSdkException("Failed to get customers from business=" + businessId); + } + finally { + get.releaseConnection(); + } + if(result.size() > 0) { + return result.get(0).getCustomers(); + } + return new ArrayList(); + + } } From d7b56712fe4669a90c3bee41fbec90d4dee87d46 Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Wed, 13 Jan 2021 19:15:07 -0800 Subject: [PATCH 20/26] SOL-385 added CUSTOMER_FETCH webhook, todo fetch all customers at onboarding time --- .../java/co/poynt/api/sdk/ApiCustomer.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index 506d819..d324888 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -16,7 +16,7 @@ //by Wavelety, Inc. public class ApiCustomer extends Api { - public static final String API_CUSTOMERS = "/businesses/{businessId}/customers?limit=100&startAt={startAt}&endAt={endAt}"; + public static final String API_CUSTOMERS = "/businesses/{businessId}/customers?limit=100&startOffset={startOffset}&startAt={startAt}&endAt={endAt}"; private static final Logger logger = LoggerFactory.getLogger(ApiCustomer.class); public ApiCustomer(PoyntSdk sdk) { @@ -41,10 +41,10 @@ public List getAll(String businessId, String startAt, String endAt, in List result = new ArrayList(); String accessToken = sdk.getAccessToken(); - String baseUrl = this.endPoint.replace("{businessId}", businessId) - .replace("startAt", startAt) - .replace("endAt", endAt) - .replace("startOffset", "" + offset); + String baseUrl = this.endPoint.replace("{businessId}", businessId); + baseUrl.replace("{startAt}", startAt); + baseUrl.replace("{endAt}", endAt); + baseUrl.replace("{startOffset}", "" + offset); HttpGet get = this.createGetRequest(baseUrl); get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); @@ -53,22 +53,19 @@ public List getAll(String businessId, String startAt, String endAt, in if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { result = this.readListResponse(response, CustomerList.class); - } - else { + } else { handleError(response); } - } - catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); logger.error("Failed to get customers from business {}", businessId, e); throw new PoyntSdkException("Failed to get customers from business=" + businessId); - } - finally { + } finally { get.releaseConnection(); } - if(result.size() > 0) { + if (result.size() > 0) { return result.get(0).getCustomers(); - } + } return new ArrayList(); } From f19923a4d5303b36156b976c5ab601a7f20acb8d Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Wed, 13 Jan 2021 19:38:56 -0800 Subject: [PATCH 21/26] SOL-385 added CUSTOMER_FETCH webhook, todo fetch all customers at onboarding time --- src/main/java/co/poynt/api/sdk/ApiCustomer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index d324888..bacc088 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -42,9 +42,9 @@ public List getAll(String businessId, String startAt, String endAt, in String accessToken = sdk.getAccessToken(); String baseUrl = this.endPoint.replace("{businessId}", businessId); - baseUrl.replace("{startAt}", startAt); - baseUrl.replace("{endAt}", endAt); - baseUrl.replace("{startOffset}", "" + offset); + baseUrl = baseUrl.replace("{startAt}", startAt); + baseUrl = baseUrl.replace("{endAt}", endAt); + baseUrl = baseUrl.replace("{startOffset}", "" + offset); HttpGet get = this.createGetRequest(baseUrl); get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); From f99bcd9cf7d9810da60748f6250c37cc00d215be Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Wed, 13 Jan 2021 22:05:42 -0800 Subject: [PATCH 22/26] SOL-385 removed timerange due to formatting issues --- src/main/java/co/poynt/api/sdk/ApiCustomer.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index bacc088..097e3b3 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -16,7 +16,7 @@ //by Wavelety, Inc. public class ApiCustomer extends Api { - public static final String API_CUSTOMERS = "/businesses/{businessId}/customers?limit=100&startOffset={startOffset}&startAt={startAt}&endAt={endAt}"; + public static final String API_CUSTOMERS = "/businesses/{businessId}/customers?limit=100&startOffset={startOffset}";//&startAt={startAt}&endAt={endAt}"; private static final Logger logger = LoggerFactory.getLogger(ApiCustomer.class); public ApiCustomer(PoyntSdk sdk) { @@ -38,13 +38,15 @@ public List getAllCustomers(String businessId) { } public List getAll(String businessId, String startAt, String endAt, int offset) { - List result = new ArrayList(); + CustomerList result = null; String accessToken = sdk.getAccessToken(); String baseUrl = this.endPoint.replace("{businessId}", businessId); - baseUrl = baseUrl.replace("{startAt}", startAt); - baseUrl = baseUrl.replace("{endAt}", endAt); +// baseUrl = baseUrl.replace("{startAt}", startAt); +// baseUrl = baseUrl.replace("{endAt}", endAt); baseUrl = baseUrl.replace("{startOffset}", "" + offset); + + logger.info("getAll: url={}", baseUrl); HttpGet get = this.createGetRequest(baseUrl); get.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); @@ -52,7 +54,7 @@ public List getAll(String businessId, String startAt, String endAt, in HttpResponse response = this.sdk.getHttpClient().execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - result = this.readListResponse(response, CustomerList.class); + result = this.readResponse(response, CustomerList.class); } else { handleError(response); } @@ -63,8 +65,8 @@ public List getAll(String businessId, String startAt, String endAt, in } finally { get.releaseConnection(); } - if (result.size() > 0) { - return result.get(0).getCustomers(); + if (result != null && result.getCount() > 0) { + return result.getCustomers(); } return new ArrayList(); From ba6eb04c0e4fdf151e676b88d55d7f21e4833e58 Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Wed, 13 Jan 2021 23:03:10 -0800 Subject: [PATCH 23/26] SOL-385 uses next link instead of creating url --- .../java/co/poynt/api/sdk/ApiCustomer.java | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index 097e3b3..a141e9f 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -16,35 +16,27 @@ //by Wavelety, Inc. public class ApiCustomer extends Api { - public static final String API_CUSTOMERS = "/businesses/{businessId}/customers?limit=100&startOffset={startOffset}";//&startAt={startAt}&endAt={endAt}"; + public static final String API_CUSTOMERS = "/businesses/{businessId}/customers?limit=100"; private static final Logger logger = LoggerFactory.getLogger(ApiCustomer.class); public ApiCustomer(PoyntSdk sdk) { super(sdk, Constants.POYNT_API_HOST + API_CUSTOMERS); } - public List getAll(String businessId) { - - return getAllFromBusiness(Customer.class, businessId); - } public Customer get(String businessId, String customerId) { return this.getFromBusiness(Customer.class, businessId, customerId); } - public List getAllCustomers(String businessId) { - CustomerList list = (CustomerList) getAllFromBusiness(CustomerList.class, businessId); - return list.getCustomers(); - } - public List getAll(String businessId, String startAt, String endAt, int offset) { + public CustomerList getAll(String businessId, String next) { CustomerList result = null; String accessToken = sdk.getAccessToken(); String baseUrl = this.endPoint.replace("{businessId}", businessId); -// baseUrl = baseUrl.replace("{startAt}", startAt); -// baseUrl = baseUrl.replace("{endAt}", endAt); - baseUrl = baseUrl.replace("{startOffset}", "" + offset); + if(next != null) { + baseUrl = Constants.POYNT_API_HOST + next; + } logger.info("getAll: url={}", baseUrl); HttpGet get = this.createGetRequest(baseUrl); @@ -65,10 +57,7 @@ public List getAll(String businessId, String startAt, String endAt, in } finally { get.releaseConnection(); } - if (result != null && result.getCount() > 0) { - return result.getCustomers(); - } - return new ArrayList(); + return result; } } From 34daf1d4ff9615c129bf4987b5d3915acd7c506d Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Tue, 19 Jan 2021 06:54:19 -0800 Subject: [PATCH 24/26] SOL-385 url fix for get customer id --- src/main/java/co/poynt/api/sdk/ApiCustomer.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/co/poynt/api/sdk/ApiCustomer.java b/src/main/java/co/poynt/api/sdk/ApiCustomer.java index a141e9f..9416984 100644 --- a/src/main/java/co/poynt/api/sdk/ApiCustomer.java +++ b/src/main/java/co/poynt/api/sdk/ApiCustomer.java @@ -1,8 +1,6 @@ package co.poynt.api.sdk; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; @@ -16,7 +14,7 @@ //by Wavelety, Inc. public class ApiCustomer extends Api { - public static final String API_CUSTOMERS = "/businesses/{businessId}/customers?limit=100"; + public static final String API_CUSTOMERS = "/businesses/{businessId}/customers"; private static final Logger logger = LoggerFactory.getLogger(ApiCustomer.class); public ApiCustomer(PoyntSdk sdk) { @@ -34,6 +32,7 @@ public CustomerList getAll(String businessId, String next) { String accessToken = sdk.getAccessToken(); String baseUrl = this.endPoint.replace("{businessId}", businessId); + baseUrl += "?limit=100"; if(next != null) { baseUrl = Constants.POYNT_API_HOST + next; } From e4209be5b3ca6357e458bc0aba9691b9e118f896 Mon Sep 17 00:00:00 2001 From: sdatgit Date: Mon, 1 Feb 2021 22:07:35 -0800 Subject: [PATCH 25/26] SOL-386 upgrade to 1.2.132 to support POYTN as acquirer --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c797e65..3201f2c 100755 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ co.poynt.api api-model - 1.2.116 + 1.2.132 com.fasterxml.jackson.core From 2d4a942482e7faf73d257c1b061e262c1e1e5c72 Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Tue, 4 Jan 2022 13:06:20 -0600 Subject: [PATCH 26/26] avoids different version of slf4j binding --- pom.xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3201f2c..ac1e2f9 100755 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - co.poynt.api poynt-java-cloud-sdk @@ -70,10 +71,16 @@ httpclient 4.5 + org.slf4j slf4j-api - 1.7.12 + ${slf4j.version} + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} log4j