{"id":18577507,"url":"https://github.com/ecomplus/discounts","last_synced_at":"2025-04-10T09:30:51.611Z","repository":{"id":41417405,"uuid":"219598967","full_name":"ecomplus/discounts","owner":"ecomplus","description":"Default E-Com Plus app for complex discount rules","archived":true,"fork":false,"pushed_at":"2023-11-24T00:06:01.000Z","size":424,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-17T15:26:33.158Z","etag":null,"topics":["discount-calculation","discount-coupons","ecomplus","ecomplus-apps"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecomplus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-04T21:21:07.000Z","updated_at":"2023-11-24T00:11:09.000Z","dependencies_parsed_at":"2023-11-07T03:07:35.832Z","dependency_job_id":"5b362731-77b0-466f-95ef-0636599ef946","html_url":"https://github.com/ecomplus/discounts","commit_stats":null,"previous_names":[],"tags_count":82,"template":false,"template_full_name":"ecomplus/express-app-boilerplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fdiscounts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fdiscounts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fdiscounts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomplus%2Fdiscounts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomplus","download_url":"https://codeload.github.com/ecomplus/discounts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248191644,"owners_count":21062544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discount-calculation","discount-coupons","ecomplus","ecomplus-apps"],"created_at":"2024-11-06T23:29:29.495Z","updated_at":"2025-04-10T09:30:51.297Z","avatar_url":"https://github.com/ecomplus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Discounts\n\n[![CodeFactor](https://www.codefactor.io/repository/github/ecomplus/discounts/badge)](https://www.codefactor.io/repository/github/ecomplus/discounts)\n[![License Apache-2.0](https://img.shields.io/badge/License-Apache-orange.svg)](https://opensource.org/licenses/Apache-2.0)\n\nDefault E-Com Plus app for complex discount rules\n\n[CHANGELOG](https://github.com/ecomplus/discounts/blob/master/CHANGELOG.md)\n\n## About\n\nThis application will add discount extra discount to order by integrating\n[Modules API (**Apply discount**)](https://developers.e-com.plus/modules-api/).\n\n[App `hidden_data`](https://developers.e-com.plus/docs/api/#/store/applications/)\nwill store _discount rules_ (promotions) defined by merchant,\nwith filters (optionals) by date range _AND_\ndiscount coupon, UTM campaign _OR_ customer IDs.\n\n`hidden_data` expected object model is defined (JSON Schema) on\n[app `admin_settings`](https://github.com/ecomplus/discounts/blob/master/assets/application.json).\n\nIt's based on\n[E-Com Plus Express App Boilerplate](https://github.com/ecomplus/express-app-boilerplate),\napplication installation and authentication was kept as is\nwith original endpoints from boilerplate source:\n\n- [`/bin/web.js`](https://github.com/ecomplus/discounts/blob/master/bin/web.js):\nExpress web server setup);\n- [`/routes/ecom/auth-callback.js`](https://github.com/ecomplus/discounts/blob/master/routes/ecom/auth-callback.js):\nEndpoint for\n[E-Com Plus Authentication Callback](https://developers.e-com.plus/docs/api/#/store/authenticate-app/authenticate-app);\n\n### Apply discount module endpoint\n\nAdditional endpoint was created to handle `apply_discount`\n([`/ecom/modules/apply-discount.js`](https://github.com/ecomplus/discounts/blob/master/routes/ecom/modules/apply-discount.js))\nmodule, it receives requests from Modules API on stores with this app installed.\n\nIt'll receive _POST_ with body like:\n\n```js\nconst body = {\n  params: {\n    discount_coupon: 'SAMPLE',\n    amount: {\n      total: 100,\n      subtotal: 90,\n      freight: 10,\n      discount: 0\n    },\n    utm: {\n      campaign: 'my_promo'\n    },\n    customer: {\n      _id: 'a12345678901234567891234'\n    }\n    // ...\n  },\n  application: {\n    // configured by merchant\n    data: {},\n    hidden_data: {\n      discount_rules: [\n        // discount rules objects with model defined by `admin_settings`\n        // ...\n      ]\n    }\n  }\n}\n```\n\n- [Full `params` object reference](https://apx-mods.e-com.plus/api/v1/apply_discount/schema.json?store_id=100)\nfrom Modules API docs;\n- `hidden_data.discount_rules` object reference on\n[application.json](https://github.com/ecomplus/discounts/blob/master/assets/application.json)\n`admin_settings.discount_rules.schema` property.\n\nAnd will respond like:\n\n```js\n// no promotion match\n// returns empty JSON object\nconst response = {}\n```\n\n```js\n// discount match but can't apply (generally non-cumulative)\nconst response = {\n  invalid_coupon_message: 'Message to customer'\n}\n```\n\n```js\n// we have a discount to apply \\o/\nconst response = {\n  discount_rule: {\n    label: 'MY_SAMPLE_COUPON',\n    description: 'Maybe we have a description configured by merchant',\n    extra_discount: {\n      value: 20,\n      flags: ['COUPON']\n    }\n  }\n}\n```\n\n- [Full `response` object reference](https://apx-mods.e-com.plus/api/v1/apply_discount/response_schema.json?store_id=100)\nfrom Modules API docs;\n\n## Environment variables sample\n\nVariable              | Value\n---                   | ---\n`LOGGER_OUTPUT`       | `~/app/log/logger.out`\n`LOGGER_ERRORS`       | `~/app/log/logger.err`\n`LOGGER_FATAL_ERRORS` | `~/app/log/_stderr`\n`PORT`                | `3000`\n`APP_BASE_URI`        | `https://discounts.ecomplus.biz`\n`DB_PATH`             | `~/app/db.sqlite`\n`ECOM_AUTH_DB`        | `~/app/db.sqlite`\n`ECOM_AUTH_UPDATE`    | `enabled`\n\n## Production server\n\nPublished at https://discounts.ecomplus.biz\n\n### Continuous deployment\n\nWhen new version is **production ready**,\n[create a new release](https://github.com/ecomplus/discounts/releases)\n(or `npm run release`) to run automatic deploy from _master_ branch\nand (re)publish the app.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomplus%2Fdiscounts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomplus%2Fdiscounts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomplus%2Fdiscounts/lists"}