-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 3 | ||
|
||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Java | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'temurin' # See 'Supported distributions' for available options | ||
java-version: '17' | ||
|
||
- name: Install dependencies & run tests | ||
env: | ||
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} | ||
run: mvn install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
*.class | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
# exclude jar for gradle wrapper | ||
!gradle/wrapper/*.jar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# build files | ||
**/target | ||
target | ||
.gradle | ||
build | ||
.settings/ | ||
*.pem | ||
.classpath | ||
.travis.yml | ||
build.* | ||
gradle* | ||
settings.gradle | ||
git_push.sh | ||
|
||
#ide files | ||
*.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"apiPackage": "com.gr4vy.api.openapi", | ||
"modelPackage": "com.gr4vy.api.model", | ||
"artifactId": "openapi", | ||
"apiDocs": false, | ||
"modelDocs": false, | ||
"apiTests": false, | ||
"modelTests": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
# As an example, the C# client generator defines ApiClient.cs. | ||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: | ||
#ApiClient.cs | ||
|
||
# You can match any string of characters against a directory, file or extension with a single asterisk (*): | ||
#foo/*/qux | ||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux | ||
|
||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**): | ||
#foo/**/qux | ||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux | ||
|
||
# You can also negate patterns with an exclamation (!). | ||
# For example, you can ignore all files in a docs folder with the file extension .md: | ||
#docs/*.md | ||
# Then explicitly reverse the ignore rule for a single file: | ||
#!docs/README.md | ||
|
||
README.md | ||
src/main/java/com/gr4vy/sdk/* | ||
src/test/* | ||
docs/ | ||
pom.xml | ||
.gitignore |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>gr4vy</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
<filteredResources> | ||
<filter> | ||
<id>1686096087411</id> | ||
<name></name> | ||
<type>30</type> | ||
<matcher> | ||
<id>org.eclipse.core.resources.regexFilterMatcher</id> | ||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> | ||
</matcher> | ||
</filter> | ||
</filteredResources> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License Copyright (c) 2020 Gr4vy | ||
|
||
Permission is hereby granted, | ||
free of charge, to any person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, copy, modify, merge, | ||
publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to the | ||
following conditions: | ||
|
||
The above copyright notice and this permission notice | ||
(including the next paragraph) shall be included in all copies or substantial | ||
portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO | ||
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
# Gr4vy SDK for Java | ||
|
||
Gr4vy provides any of your payment integrations through one unified API. For | ||
more details, visit [gr4vy.com](https://gr4vy.com). | ||
|
||
## Installation | ||
|
||
Add the jitpack.io repository to your pom.xml: | ||
```java | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
``` | ||
Add the `gr4vy-java` dependency to your pom.xml: | ||
```java | ||
<dependency> | ||
<groupId>com.github.gr4vy</groupId> | ||
<artifactId>gr4vy-java</artifactId> | ||
<version>0.13.0</version> | ||
</dependency> | ||
``` | ||
|
||
## Getting Started | ||
|
||
To make your first API call, you will need to [request](https://gr4vy.com) a | ||
Gr4vy instance to be set up. Please contact our sales team for a demo. Please ensure | ||
that you have the latest version of com.squareup.okhttp3 | ||
|
||
Once you have been set up with a Gr4vy account you will need to head over to the | ||
**Integrations** panel and generate a private key. We recommend storing this key | ||
in a secure location but in this code sample we simply read the file from disk. | ||
|
||
Import Gr4vy: | ||
```java | ||
import com.gr4vy.sdk.*; | ||
import com.gr4vy.api.ApiException; | ||
import com.gr4vy.api.model.*; | ||
import com.gr4vy.api.openapi.BuyersApi; | ||
``` | ||
|
||
Call the API: | ||
```java | ||
Gr4vyClient gr4vyClient = new Gr4vyClient("[YOUR_GR4VY_ID]", "private_key.pem"); | ||
BuyersApi apiInstance = new BuyersApi(gr4vyClient.getClient()); | ||
|
||
try { | ||
Buyers result = apiInstance.listBuyers(null, null, null); | ||
System.out.println(result); | ||
} catch (ApiException e) { | ||
System.err.println("Exception when calling BuyersApi#listBuyers"); | ||
System.err.println("Status code: " + e.getCode()); | ||
System.err.println("Reason: " + e.getResponseBody()); | ||
System.err.println("Response headers: " + e.getResponseHeaders()); | ||
} | ||
``` | ||
|
||
## Environment | ||
|
||
The SDK defaults the environment to "sandbox", to send transactions to production, set the environment in `Gr4vyClient`: | ||
|
||
```java | ||
|
||
Gr4vyClient gr4vyClient = new Gr4vyClient("[YOUR_GR4VY_ID]", "private_key.pem", "sandbox"); | ||
|
||
Gr4vyClient gr4vyClient = new Gr4vyClient("[YOUR_GR4VY_ID]", "private_key.pem", "production"); | ||
|
||
``` | ||
|
||
## Multi merchant | ||
|
||
In a multi-merchant environment, the merchant account ID can be set after the SDK has been initialized. | ||
|
||
```java | ||
gr4vyClient.setMerchantAccountId("my-account-id"); // defaults to `default` | ||
``` | ||
|
||
## Gr4vy Embed | ||
|
||
To create a token for Gr4vy Embed, call the `client.getEmbedToken(embed)` | ||
function with the amount, currency, and optional checkout session and optional buyer information for Gr4vy | ||
Embed. | ||
|
||
```java | ||
Gr4vyClient client = new Gr4vyClient("[YOUR_GR4VY_ID]", "private_key.pem"); | ||
|
||
Map<String, Object> embed = new HashMap<String, Object>(); | ||
embed.put("amount", 1299); | ||
embed.put("currency", "USD"); | ||
|
||
String token = client.getEmbedToken(embed); | ||
``` | ||
|
||
You can now pass this token to your frontend where it can be used to | ||
authenticate Gr4vy Embed. | ||
|
||
The `buyer_id` and/or `buyer_external_identifier` fields can be used to allow | ||
the token to pull in previously stored payment methods for a user. A buyer | ||
needs to be created before it can be used in this way. | ||
|
||
```java | ||
Gr4vyClient gr4vyClient = new Gr4vyClient("[YOUR_GR4VY_ID]", "private_key.pem"); | ||
BuyersApi apiInstance = new BuyersApi(gr4vyClient.getClient()); | ||
BuyerRequest buyer = new BuyerRequest(); | ||
buyer.setDisplayName("Tester T."); | ||
try { | ||
Buyer result = apiInstance.newBuyer(buyer); | ||
System.out.println(result); | ||
} catch (ApiException e) { | ||
|
||
} | ||
``` | ||
|
||
## Initialization | ||
|
||
The client can be initialized with the Gr4vy ID (`gr4vyId`) and the location of your | ||
private key string. | ||
|
||
```java | ||
Gr4vyClient gr4vyClient = new Gr4vyClient("[YOUR_GR4VY_ID]", "private_key.pem"); | ||
``` | ||
|
||
Alternatively, instead of the `gr4vyId` it can be initialized with the `baseUrl` | ||
of the server to use directly. | ||
|
||
```java | ||
Gr4vyClient gr4vyClient = new Gr4vyClient("acme", "private_key.pem"); | ||
gr4vyClient.setHost("https://api.acme.gr4vy.app") | ||
``` | ||
|
||
Your API private key can be created in your admin panel on the **Integrations** | ||
tab. | ||
|
||
|
||
## Making API calls | ||
|
||
This library conveniently maps every API path to a seperate function. For | ||
example, `GET /buyers?limit=100` would be: | ||
|
||
```java | ||
String search = null; | ||
Integer limit = 100; | ||
String cursor = null; | ||
Buyers response = api.listBuyers(search, limit, cursor); | ||
``` | ||
|
||
To create, the API requires a request object for that resource that is conventiently | ||
named `<Resource>Request`. To update, the API requires a request object | ||
for that resource that is named `<Resource>Update`. | ||
|
||
For example, to create a buyer you will need to pass a `BuyerRequest` object to | ||
the `addBuyer` method. | ||
|
||
```java | ||
BuyerRequest buyer = new BuyerRequest(); | ||
buyer.setDisplayName("Tester T."); | ||
Buyer result = apiInstance.addBuyer(buyer); | ||
``` | ||
|
||
So to update a buyer you will need to pass in the `BuyerUpdate` object to the | ||
`updateBuyer` method. | ||
|
||
```java | ||
BuyerUpdate buyer = new BuyerUpdate(); | ||
buyer.setDisplayName("Tester T."); | ||
Buyer result = apiInstance.updateBuyer(buyerId, buyer); | ||
``` | ||
|
||
## Development | ||
|
||
### Adding new APIs | ||
|
||
To add new APIs, run the following command to update the models and APIs based | ||
on the API spec. | ||
|
||
```sh | ||
./openapi-generator-generate.sh | ||
``` | ||
|
||
Next, update `sdk_<object_name>.go` to bind any new APIs or remove any APIs that are no | ||
longer available. | ||
|
||
Run the tests to ensure the changes do not break any existing tests. | ||
|
||
```sh | ||
mvn test | ||
``` | ||
|
||
### Publishing | ||
|
||
This library is published using Maven. | ||
|
||
## License | ||
|
||
This library is released under the [MIT License](LICENSE). |
Oops, something went wrong.