-
Notifications
You must be signed in to change notification settings - Fork 5
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
4 changed files
with
212 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
name: run tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: 'read' | ||
id-token: 'write' | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Authenticate to Google Cloud | ||
id: auth | ||
uses: google-github-actions/auth@v1 | ||
with: | ||
token_format: access_token | ||
workload_identity_provider: projects/949875736540/locations/global/workloadIdentityPools/external-pool/providers/github-provider | ||
service_account: [email protected] | ||
- name: Login to GAR | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: europe-west3-docker.pkg.dev | ||
username: oauth2accesstoken | ||
password: ${{ steps.auth.outputs.access_token }} | ||
- uses: hoverkraft-tech/[email protected] | ||
- name: Set up Java | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '21' | ||
cache: 'gradle' | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get install jq curl | ||
- name: Run example | ||
run: | | ||
echo "running example"; | ||
sleep 5; | ||
docker compose logs; | ||
curl --location "http://localhost:9000/v1/users" | ||
ACCOUNT_RESPONSE=$(curl -s --location "http://localhost:9000/v1/accounts" \ | ||
--header "Content-Type: application/json" \ | ||
--data-raw '{ | ||
"companyName": "demo", | ||
"email": "[email protected]", | ||
"password": "Password1234!" | ||
}'); | ||
export TALON_USER_ID=$(echo $ACCOUNT_RESPONSE | jq ".userId"); | ||
export TALON_USER_TOKEN=$(echo $ACCOUNT_RESPONSE | jq ".token" | tr -d '"'); | ||
USER_RESPONSE=$(curl -s --location "http://localhost:9000/v1/users/$TALON_USER_ID" \ | ||
--header "Authorization: Bearer $TALON_USER_TOKEN"); | ||
export TALON_ACCOUNT_ID=$(echo $USER_RESPONSE | jq ".accountId"); | ||
echo "User with ID $TALON_USER_ID and Token $TALON_USER_TOKEN was created for application $TALON_ACCOUNT_ID"; | ||
APPLICATION_RESPONSE=$(curl -s --location "http://localhost:9000/v1/applications" \ | ||
--header "Content-Type: application/json" \ | ||
--header "Authorization: Bearer $TALON_USER_TOKEN" \ | ||
--data-raw '{ | ||
"name": "demo", | ||
"currency": "EUR", | ||
"timezone": "Europe/Berlin", | ||
"enableFlattenedCartItems": false | ||
}'); | ||
export TALON_APPLICATION_ID=$(echo $USER_RESPONSE | jq ".id"); | ||
echo "Application with ID $TALON_APPLICATION_ID was created" | ||
API_KEY_RESPONSE=$(curl -s -v --location "http://localhost:9000/v1/applications/$TALON_APPLICATION_ID/apikeys" \ | ||
--header "Content-Type: application/json" \ | ||
--header "Authorization: Bearer $TALON_USER_TOKEN" \ | ||
--data-raw '{ | ||
"title": "Application HIT KEY", | ||
"expires": "2099-01-01T0:00:00Z" | ||
}'); | ||
echo "Api-Key-Response: $API_KEY_RESPONSE"; | ||
export TALON_API_KEY=$(echo $API_KEY_RESPONSE | jq ".key" | tr -d '"'); | ||
echo "Api-Key $TALON_API_KEY created"; | ||
echo "maven install"; | ||
mvn clean install; | ||
export CLASSPATH=.:./target/lib/gson-2.8.9.jar:./target/talon-one-client-9.1.0.jar:./target/lib/okio-1.17.2.jar:./target/lib/okhttp-3.14.7.jar:./target/lib/threetenbp-1.4.3.jar:./target/lib/gson-fire-1.8.4.jar; | ||
echo "java compile"; | ||
javac -d . Example.java; | ||
echo "java execute"; | ||
java com.example.consumer.Example; |
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,76 @@ | ||
package com.example.consumer; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import one.talon.ApiClient; | ||
import one.talon.api.IntegrationApi; | ||
import one.talon.api.ManagementApi; | ||
import one.talon.model.*; | ||
|
||
import java.util.*; | ||
|
||
public class Example { | ||
public static void main(String[] args) throws Exception { | ||
Gson gson = new Gson(); | ||
IntegrationApi iApi = new IntegrationApi(new ApiClient("api_key_v1")); | ||
|
||
// Setup: basePath | ||
iApi.getApiClient().setBasePath("http://localhost:9000"); | ||
// Setup: when using 'api_key_v1', set apiKey & apiKeyPrefix must be provided | ||
iApi.getApiClient().setApiKeyPrefix("ApiKey-v1"); | ||
iApi.getApiClient().setApiKey(System.getenv("TALON_API_KEY")); | ||
|
||
// Creating a cart item object | ||
CartItem cartItem = new CartItem(); | ||
cartItem.setName("Hawaiian Pizza"); | ||
cartItem.setSku("pizza-x"); | ||
cartItem.setQuantity(1); | ||
cartItem.setPrice(new java.math.BigDecimal("5.5")); | ||
|
||
// Creating a customer session of V2 | ||
NewCustomerSessionV2 customerSession = new NewCustomerSessionV2(); | ||
customerSession.setProfileId("Cool_Dude"); | ||
customerSession.addCouponCodesItem("Cool-Summer!"); | ||
customerSession.addCartItemsItem(cartItem); | ||
|
||
// Initiating integration request wrapping the customer session update | ||
IntegrationRequest request = new IntegrationRequest() | ||
.customerSession(customerSession) | ||
// Optional parameter of requested information to be present on the response related to the customer session update | ||
.responseContent(Arrays.asList( | ||
IntegrationRequest.ResponseContentEnum.CUSTOMERSESSION, | ||
IntegrationRequest.ResponseContentEnum.CUSTOMERPROFILE | ||
)); | ||
|
||
// Flag to communicate whether the request is a "dry run" | ||
Boolean dryRun = false; | ||
|
||
// Create/update a customer session using `updateCustomerSessionV2` function | ||
IntegrationStateV2 is = iApi.updateCustomerSessionV2("deetdoot", request, dryRun, null); | ||
System.out.println(is.toString()); | ||
|
||
// Parsing the returned effects list, please consult https://developers.talon.one/Integration-API/handling-effects-v2 for the full list of effects and their corresponding properties | ||
for (Effect eff : is.getEffects()) { | ||
if (eff.getEffectType().equals("addLoyaltyPoints")) { | ||
// Typecasting according to the specific effect type | ||
AddLoyaltyPointsEffectProps props = gson.fromJson( | ||
gson.toJson(eff.getProps()), | ||
AddLoyaltyPointsEffectProps.class | ||
); | ||
// Access the specific effect's properties | ||
System.out.println(props.getName()); | ||
System.out.println(props.getProgramId()); | ||
System.out.println(props.getValue()); | ||
} | ||
if (eff.getEffectType().equals("acceptCoupon")) { | ||
// Typecasting according to the specific effect type | ||
AcceptCouponEffectProps props = gson.fromJson( | ||
gson.toJson(eff.getProps()), | ||
AcceptCouponEffectProps.class | ||
); | ||
// work with AcceptCouponEffectProps' properties | ||
// ... | ||
} | ||
} | ||
} | ||
} |
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,48 @@ | ||
services: | ||
api-service: | ||
image: europe-west3-docker.pkg.dev/talon-artifacts/talon-images/talon-service:master | ||
depends_on: | ||
- database-service | ||
ports: | ||
- "9000:9000" | ||
environment: | ||
- TALON_DB_NAME=talon | ||
- TALON_DB_USER=talon | ||
- TALON_DB_PASSWORD=talon.one.9000 | ||
- TALON_DB_HOST=database-service | ||
- TALON_DB_PORT=5432 | ||
- TALON_ENABLE_WEBHOOK_WORKER_POOL=false | ||
- TZ=UTC | ||
- RELEASE_STAGE=ci | ||
- TALON_CH_ENABLED=false | ||
- TALON_DISABLE_PROFILER=true | ||
- USE_REPLICA_DB=false | ||
command: | ||
- /talon/talon | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://localhost:9000/v1/status/health"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 10 | ||
restart: "on-failure:10" | ||
|
||
database-service: | ||
image: docker.io/bitnami/postgresql:15 | ||
volumes: | ||
- 'postgresql_master_data:/bitnami/postgresql' | ||
ports: | ||
- "5433:5432" | ||
environment: | ||
- POSTGRESQL_DATABASE=talon | ||
- POSTGRESQL_USERNAME=talon | ||
- POSTGRESQL_PASSWORD=talon.one.9000 | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -U talon -d talon"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
restart: "on-failure:10" | ||
|
||
volumes: | ||
postgresql_master_data: | ||
|
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