Skip to content

Commit

Permalink
v6.0.5
Browse files Browse the repository at this point in the history
* Adjust application to work with Commercetools Connect platform:
- add connect.yaml config file
- add `post-deploy` and `pre-undeploy` scripts
- support `CONNECT_SERVICE_URL` environment variable as alternative for `APP_URL`

Fixes:
- fix `api-extension-*` cli scripts
- use `VOUCHERIFY_APP_ID` environment variable inside `VoucherifyConnectorService`

* update depends

* adjust application structure to be compliant with commercetools Connect platform

* in progress

* added some tests

* in progress

* another tests

* few more tests

* some tests

* Update getSimpleMetadataForOrder.ts

* minor changes

* Delete cart-paid-actions.spec.ts

* npm packages

* fix for new commander

* in progress

* Update cart-service.factory.ts

* in progress

* making functions simpler

* added some tests

* some tests

* some tests

* some tests

* another test

* requested changes

* fixes for some tests

* commercetools tests

* some tests

* some new tests

* removed

* Create .gitignore

* Update order-paid-actions.ts

* fixes

* Update fixedPrice.ts

* Update integration.service.ts

* some test fixes

* Update package.json

* Update connect.yaml

* Add support for partial redeem

* Fix api extension registration for Commercetools Connect
- remove traling slash from APP_URL and CONNECT_SERVICE_URL environment variables
- update "endpoint" attribute in connect.yaml file

* test fix

* Update integration.service.ts

* Update integration.service.ts

* paths fix

* fix, displaying `apply` info

* Update setCustomFields.ts

* Update couponsOperationFunctions.ts

* package and package lock

* refactoring

* moving files around, package json

* removing test result files

* Update .gitignore

* Update .gitignore

* coverage folder

* moved mocks

* dictionary

* getOrderMetadata test

* Update getOrderMetadata.spec.ts

* Update package-lock.json

* Update voucherify-connector.service.ts

* Update package.json

* Update product-import.service.ts

* requested changes

* changelog and version

---------
  • Loading branch information
p-zielinski authored Jan 24, 2024
1 parent 76f0473 commit 85e150e
Show file tree
Hide file tree
Showing 217 changed files with 27,616 additions and 22,272 deletions.
Binary file added .DS_Store
Binary file not shown.
43 changes: 1 addition & 42 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,43 +1,2 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# json requests / responses
json

# OS
.idea/*
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# configuration
.env
.env-local
*.icloud
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 voucherify.io
Copyright (c) 2023 voucherify.io

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Demo store https://sunrise-ct-voucherify.herokuapp.com


<div style="background-color: rgb(0, 18, 70); padding: 50px; border-radius: 50px">
<img src="./public/voucherify-logo.svg" />
<img src="./voucherify-service/public/voucherify-logo.svg" />
</div>

---
Expand Down Expand Up @@ -51,6 +51,7 @@ Demo store https://sunrise-ct-voucherify.herokuapp.com
* [Final words](#final-words)
* [Licence](#licence)


## How does the integration between Voucherify and commercetools work?

The integration between Voucherify and commercetools allows your customers to use Voucherify-generated promotions in a store built on top of commercetools. We support all Voucherify campaigns.
Expand All @@ -73,7 +74,7 @@ If we want to allow customers to use coupons defined in Voucherify, the integrat
1. Watch cart updates on the commercetools’ side. If a customer adds a coupon code, use Voucherify API to validate coupons, get discount details and apply discounts back to the commercetools cart.
2. Record fulfilled orders from commercetools on the Voucherify’s side using Voucherify redeem endpoint.

![commercetools & Voucherify integration flow chart](./public/integration-flow.jpeg)
![commercetools & Voucherify integration flow chart](./voucherify-service/public/integration-flow.jpeg)

In addition, we suggest synchronizing your customer, product, and order data between commercetools and Voucherify, so you can use that data to build more advanced promotion campaigns.

Expand All @@ -91,7 +92,7 @@ Extensions:

## How to work with commercetools API Extensions?

Our integration uses [commercetools API Extensions](https://docs.commercetools.com/api/projects/api-extensions) to monitor cart and order updates. But, before commercetools can send us HTTP requests with cart and order update details, we need to register API Extension and let commercetools know under which public URL our integration is available. There are two scenarios. First, if you run the integration on a publicly available server, you can register or unregister commercetools API Extension using `npm run api-extension-add`, `npm run api-extension-delete` or `npm run api-extension-update` commands. Those commands use the APP_URL environment variable as the public server address where commercetools will send cart and order updates. The second scenario is when you develop or test integration locally, and your PC does not have public IP or domain. In that case, you need to use a reverse proxy (e.g., ngrok) solution to expose your local integration application. To simplify this process, we built a script npm run dev:attach that runs an ngrok reverse proxy service, uses a randomly generated ngrok public URL to register API Extension in commercetools and start our application.
Because we have organized our repository as monorepo to comply with the commercetools Connect platform, all `npm` commands should be executed inside the `/voucherify-service` folder. Our integration uses [commercetools API Extensions](https://docs.commercetools.com/api/projects/api-extensions) to monitor cart and order updates. But, before commercetools can send us HTTP requests with cart and order update details, we need to register API Extension and let commercetools know under which public URL our integration is available. There are two scenarios. First, if you run the integration on a publicly available server, you can register or unregister commercetools API Extension using `npm run api-extension-add`, `npm run api-extension-delete` or `npm run api-extension-update` commands. Those commands use the APP_URL environment variable as the public server address where commercetools will send cart and order updates. The second scenario is when you develop or test integration locally, and your PC does not have public IP or domain. In that case, you need to use a reverse proxy (e.g., ngrok) solution to expose your local integration application. To simplify this process, we built a script npm run dev:attach that runs an ngrok reverse proxy service, uses a randomly generated ngrok public URL to register API Extension in commercetools and start our application.

``` mermaid
graph LR;
Expand Down Expand Up @@ -198,7 +199,7 @@ Integration service just need to get order (integration type) and redeeming shou
### Configuration

Set environment variables with credentials to Voucherify and commercetools APIs. For local development, put the configuration into `.env` file (see `.env.example` configuration template).
- `APP_URL` - a public URL where the application is hosted. commercetools will use this URL to make [API Extension HTTP requests](https://docs.commercetools.com/api/projects/api-extensions). This configuration is ignored for local development servers as ngrok provides a public URL dynamically.
- `APP_URL` (or `CONNECT_SERVICE_URL`) - a public URL where the application is hosted. commercetools will use this URL to make [API Extension HTTP requests](https://docs.commercetools.com/api/projects/api-extensions). This configuration is ignored for local development servers as ngrok provides a public URL dynamically. Please, note that `CONNECT_SERVICE_URL` environment variable is used by Commecetools Connect.
- In Voucherify, go to `Project Dashboard > Project Settings > General Tab > Application Keys`.
- `VOUCHERIFY_APP_ID`
- `VOUCHERIFY_SECRET_KEY`
Expand Down Expand Up @@ -237,8 +238,9 @@ npm run config
#### For production
```bash
npm install
npm run build
npm run start
npm run register
npm run api-extension-add
```

#### For local development (ngrok required)
Expand All @@ -251,7 +253,7 @@ npm run dev:attach
```bash
npm install
npm run dev
npm run register
npm run api-extension-add
```
---

Expand Down Expand Up @@ -318,6 +320,10 @@ We have created integration tests to cover the most important scenarios connecte
1. Create a new application on your Heroku account with a given <application_name>
2. Go to your <application_name> -> Settings -> Reveal Config Vars
3. Configure your commercetools application and set up environment variables [see Configuration](#configuration)
4. Add buildpacks (in order):
- https://github.com/lstoll/heroku-buildpack-monorepo
- heroku/nodejs
5. Set `APP_BASE` environment variable to `voucherify-service`

### Deployment

Expand Down Expand Up @@ -448,9 +454,9 @@ Currently, we support a few cases related to loyalty program. Firstly we provide
3. As the store operator logged into the commercetools panel, I see new orders, including applied coupon codes on the Custom Fields tab and applied coupon discount value in the Order items list.
4. As the store operator logged into the commercetools panel when I update Order Payment Status to Paid, customer, order, and redeemed objects are created in Voucherify.

![Order screen in commercetools](./public/ct-order.png)
![Order custom fields in commercetools](./public/ct-order-custom-fields.png)
![Redemption screen in Voucherify](./public/voucherify-redemption.png)
![Order screen in commercetools](./voucherify-service/public/ct-order.png)
![Order custom fields in commercetools](./voucherify-service/public/ct-order-custom-fields.png)
![Redemption screen in Voucherify](./voucherify-service/public/voucherify-redemption.png)

---

Expand All @@ -459,6 +465,17 @@ Currently, we support a few cases related to loyalty program. Firstly we provide
If you found a bug or want to suggest a new feature, please file a GitHub issue.

## Changelog
- 2024-01-23 `v6.0.5` (versions v6.0.1 - v6.0.4 were not released to the public)
- added more tests, moved all tests to `voucherify-service/test` folder
- updated dependencies
- added `npm run config` to `npm run ct-connect-post-deploy` command
- added `channel` header to V% requests.
- added support for V% `partial` redeem/validation mode.
- code refactoring (lowering cognitive complexity)
- fixed bug in `productsToAdd` function related to CT price selector.
- 2023-05-16 `v6.0.0` adjust application structure to be compliant with commercetools Connect platform
- 2023-05-11 `v5.2.3`
- adjust application to work with Commercetools Connect platform:
- 2023-05-05 `v5.2.2`
- do not make unnecessary, malformed requests to CT for a products
- update tests
Expand Down
30 changes: 30 additions & 0 deletions connect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
deployAs:
- name: voucherify-service
applicationType: service
endpoint: /
scripts:
postDeploy: npm install && npm run ct-connect-post-deploy
preUndeploy: npm install && npm run ct-connect-pre-undeploy
configuration:
standardConfiguration:
- key: COMMERCE_TOOLS_ID
description: CommerceTools Id
- key: COMMERCE_TOOLS_AUTH_URL
description: CommerceTools authentication URL
- key: COMMERCE_TOOLS_API_URL
description: CommerceTools API URL
- key: COMMERCE_TOOLS_PROJECT_KEY
description: CommerceTools Project Key
- key: VOUCHERIFY_APP_ID
description: Voucherify App Id
- key: VOUCHERIFY_API_URL
description: Voucherify API URL
- key: APPLY_CART_DISCOUNT_AS_CT_DIRECT_DISCOUNT
description: Apply cart discount as CommerceTools direct discount
securedConfiguration:
- key: COMMERCE_TOOLS_SECRET
description: CommerceTools secret
- key: VOUCHERIFY_SECRET_KEY
description: Voucherify secret key
- key: API_EXTENSION_BASIC_AUTH_PASSWORD
description: CommerceTools API extension basic auth password
Loading

0 comments on commit 85e150e

Please sign in to comment.