From b5a1fa4be0a77d88e5e3e0188841c3121f7bbfa2 Mon Sep 17 00:00:00 2001 From: Steve Nester Date: Mon, 4 Dec 2023 09:57:21 +0000 Subject: [PATCH] Allow setting the private key string directly --- README.md | 14 ++++++++++++-- pom.xml | 2 +- src/main/java/com/gr4vy/sdk/Gr4vyClient.java | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 38d7261..a940a89 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Add the `gr4vy-java` dependency to your pom.xml: com.github.gr4vy gr4vy-java - 0.18.0 + 0.20.0 ``` @@ -111,7 +111,7 @@ needs to be created before it can be used in this way. ## Initialization The client can be initialized with the Gr4vy ID (`gr4vyId`) and the location of your -private key string. +private key string (see Setting Private Key below). ```java Gr4vyClient gr4vyClient = new Gr4vyClient("[YOUR_GR4VY_ID]", "private_key.pem"); @@ -125,9 +125,19 @@ of the server to use directly. gr4vyClient.setHost("https://api.acme.gr4vy.app") ``` +## Setting Private Key + Your API private key can be created in your admin panel on the **Integrations** tab. +There are three methods of setting the private key when using the SDK: + +1. Setting the private key location in the Gr4vyClient +2. Calling `client.setPrivateKeyString("");` +3. Setting the environment variable `PRIVATE_KEY` + +NOTE: When options 2 & 3 are used, the private key location in the Initialization +can be null. ## Making API calls diff --git a/pom.xml b/pom.xml index 1a6ea43..79a564c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ gr4vy jar gr4vy - 0.19.0 + 0.20.0 https://gr4vy.com Gr4vy Java SDK diff --git a/src/main/java/com/gr4vy/sdk/Gr4vyClient.java b/src/main/java/com/gr4vy/sdk/Gr4vyClient.java index a6adeb7..18e4800 100644 --- a/src/main/java/com/gr4vy/sdk/Gr4vyClient.java +++ b/src/main/java/com/gr4vy/sdk/Gr4vyClient.java @@ -50,6 +50,7 @@ public class Gr4vyClient { private OkHttpClient okClient; private String privateKeyLocation; + private String privateKeyString = null; private String host; private String environment; private Boolean debug = false; @@ -89,6 +90,10 @@ public Gr4vyClient(String gr4vyId, String privateKeyLocation, Boolean debug, Str this.host = "https://api." + apiPrefix + gr4vyId + ".gr4vy.app"; this.debug = debug; } + + public void setPrivateKeyString(String privateKeyString) { + this.privateKeyString = privateKeyString; + } public void setMerchantAccountId(String merchantAccountId) { this.merchantAccountId = merchantAccountId; @@ -209,6 +214,9 @@ private static ECPublicKey publicFromPrivate(ECPrivateKey key) throws NoSuchAlgo } public String getKey() { + if (this.privateKeyString != null) { + return this.privateKeyString; + } String value = System.getenv("PRIVATE_KEY"); if (value != null) { return value;