cloudcommerce 0.0.126 → 0.0.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +50 -0
- package/action.yml +50 -10
- package/ecomplus-stores/monocard/README.md +0 -15
- package/ecomplus-stores/monocard/README.pt-BR.md +0 -15
- package/ecomplus-stores/monocard/functions/core/package.json +1 -1
- package/ecomplus-stores/monocard/functions/events/package.json +2 -2
- package/ecomplus-stores/monocard/functions/modules/package.json +2 -2
- package/ecomplus-stores/monocard/functions/passport/package.json +2 -2
- package/ecomplus-stores/monocard/functions/ssr/package.json +8 -8
- package/ecomplus-stores/monocard/functions/ssr/tailwind.config.cjs +1 -3
- package/ecomplus-stores/monocard/functions/ssr/{uno.config.ts → uno.config.cjs} +1 -1
- package/ecomplus-stores/monocard/package.json +1 -1
- package/ecomplus-stores/tia-sonia/README.md +0 -15
- package/ecomplus-stores/tia-sonia/README.pt-BR.md +0 -15
- package/ecomplus-stores/tia-sonia/functions/core/package.json +1 -1
- package/ecomplus-stores/tia-sonia/functions/events/package.json +2 -2
- package/ecomplus-stores/tia-sonia/functions/modules/package.json +2 -2
- package/ecomplus-stores/tia-sonia/functions/passport/package.json +2 -2
- package/ecomplus-stores/tia-sonia/functions/ssr/package.json +7 -7
- package/ecomplus-stores/tia-sonia/functions/ssr/tailwind.config.cjs +1 -3
- package/ecomplus-stores/tia-sonia/functions/ssr/{uno.config.ts → uno.config.cjs} +1 -1
- package/ecomplus-stores/tia-sonia/package.json +1 -1
- package/package.json +14 -14
- package/packages/api/lib/api.d.ts +4 -4
- package/packages/api/lib/types.d.ts +41 -41
- package/packages/api/package.json +1 -1
- package/packages/apps/correios/package.json +2 -2
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/discounts/lib-mjs/apply-discount.mjs +94 -20
- package/packages/apps/discounts/package.json +2 -2
- package/packages/apps/emails/CHANGELOG.md +1 -0
- package/packages/apps/emails/README.md +1 -0
- package/packages/apps/emails/lib/events-to-app-emails.js +19 -0
- package/packages/apps/emails/lib/events-to-app-emails.js.map +1 -0
- package/packages/apps/emails/lib/firebase.js +19 -0
- package/packages/apps/emails/lib/firebase.js.map +1 -0
- package/packages/apps/emails/lib/functios-lib/abandoned-carts.js +86 -0
- package/packages/apps/emails/lib/functios-lib/abandoned-carts.js.map +1 -0
- package/packages/apps/emails/lib/functios-lib/handle-orders.js +174 -0
- package/packages/apps/emails/lib/functios-lib/handle-orders.js.map +1 -0
- package/packages/apps/emails/lib/functios-lib/trigger-actions.js +178 -0
- package/packages/apps/emails/lib/functios-lib/trigger-actions.js.map +1 -0
- package/packages/apps/emails/lib/functios-lib/utils.js +33 -0
- package/packages/apps/emails/lib/functios-lib/utils.js.map +1 -0
- package/packages/apps/emails/lib/index.js +2 -0
- package/packages/apps/emails/lib/index.js.map +1 -0
- package/packages/apps/emails/package.json +33 -0
- package/packages/apps/emails/src/events-to-app-emails.ts +27 -0
- package/packages/apps/emails/src/firebase.ts +25 -0
- package/packages/apps/emails/src/functios-lib/abandoned-carts.ts +100 -0
- package/packages/apps/emails/src/functios-lib/handle-orders.ts +232 -0
- package/packages/apps/emails/src/functios-lib/trigger-actions.ts +177 -0
- package/packages/apps/emails/src/functios-lib/utils.ts +44 -0
- package/packages/apps/emails/src/index.ts +1 -0
- package/packages/apps/emails/tsconfig.json +3 -0
- package/packages/apps/frenet/package.json +2 -2
- package/packages/apps/infinitepay/CHANGELOG.md +1 -0
- package/packages/apps/infinitepay/README.md +1 -0
- package/packages/apps/infinitepay/assets/onload-expression.js +57 -0
- package/packages/apps/infinitepay/lib/functions-lib/add-installments.d.ts +55 -0
- package/packages/apps/infinitepay/lib/functions-lib/add-installments.js +63 -0
- package/packages/apps/infinitepay/lib/functions-lib/add-installments.js.map +1 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/create-access.d.ts +14 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/create-access.js +63 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/create-access.js.map +1 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/create-axios.d.ts +2 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/create-axios.js +19 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/create-axios.js.map +1 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/oauth.d.ts +2 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/oauth.js +25 -0
- package/packages/apps/infinitepay/lib/functions-lib/ip-auth/oauth.js.map +1 -0
- package/packages/apps/infinitepay/lib/functions-lib/utils.d.ts +8 -0
- package/packages/apps/infinitepay/lib/functions-lib/utils.js +17 -0
- package/packages/apps/infinitepay/lib/functions-lib/utils.js.map +1 -0
- package/packages/apps/infinitepay/lib/index.d.ts +1 -0
- package/packages/apps/infinitepay/lib/index.js +3 -0
- package/packages/apps/infinitepay/lib/index.js.map +1 -0
- package/packages/apps/infinitepay/lib/infinitepay.d.ts +76 -0
- package/packages/apps/infinitepay/lib/infinitepay.js +13 -0
- package/packages/apps/infinitepay/lib/infinitepay.js.map +1 -0
- package/packages/apps/infinitepay/lib/ip-create-transaction.d.ts +72 -0
- package/packages/apps/infinitepay/lib/ip-create-transaction.js +305 -0
- package/packages/apps/infinitepay/lib/ip-create-transaction.js.map +1 -0
- package/packages/apps/infinitepay/lib/ip-list-payments.d.ts +8 -0
- package/packages/apps/infinitepay/lib/ip-list-payments.js +130 -0
- package/packages/apps/infinitepay/lib/ip-list-payments.js.map +1 -0
- package/packages/apps/infinitepay/lib/ip-webhook.d.ts +5 -0
- package/packages/apps/infinitepay/lib/ip-webhook.js +152 -0
- package/packages/apps/infinitepay/lib/ip-webhook.js.map +1 -0
- package/packages/apps/infinitepay/package.json +38 -0
- package/packages/apps/infinitepay/scripts/build.sh +5 -0
- package/packages/apps/infinitepay/src/functions-lib/add-installments.ts +78 -0
- package/packages/apps/infinitepay/src/functions-lib/ip-auth/create-access.ts +85 -0
- package/packages/apps/infinitepay/src/functions-lib/ip-auth/create-axios.ts +20 -0
- package/packages/apps/infinitepay/src/functions-lib/ip-auth/oauth.ts +30 -0
- package/packages/apps/infinitepay/src/functions-lib/utils.ts +23 -0
- package/packages/apps/infinitepay/src/index.ts +2 -0
- package/packages/apps/infinitepay/src/infinitepay.ts +13 -0
- package/packages/apps/infinitepay/src/ip-create-transaction.ts +418 -0
- package/packages/apps/infinitepay/src/ip-list-payments.ts +158 -0
- package/packages/apps/infinitepay/src/ip-webhook.ts +184 -0
- package/packages/apps/infinitepay/tsconfig.json +6 -0
- package/packages/apps/infinitepay/webhook.js +1 -0
- package/packages/apps/mercadopago/lib/mp-create-transaction.js +1 -1
- package/packages/apps/mercadopago/lib/mp-create-transaction.js.map +1 -1
- package/packages/apps/mercadopago/lib/mp-webhook.js +1 -1
- package/packages/apps/mercadopago/lib/mp-webhook.js.map +1 -1
- package/packages/apps/mercadopago/package.json +4 -4
- package/packages/apps/mercadopago/src/mp-create-transaction.ts +1 -1
- package/packages/apps/mercadopago/src/mp-webhook.ts +1 -1
- package/packages/apps/pagarme/CHANGELOG.md +1 -0
- package/packages/apps/pagarme/README.md +1 -0
- package/packages/apps/pagarme/assets/onload-expression.js +18 -0
- package/packages/apps/pagarme/lib/functions-lib/add-installments.d.ts +55 -0
- package/packages/apps/pagarme/lib/functions-lib/add-installments.js +48 -0
- package/packages/apps/pagarme/lib/functions-lib/add-installments.js.map +1 -0
- package/packages/apps/pagarme/lib/functions-lib/parse-status-to-ecom.d.ts +2 -0
- package/packages/apps/pagarme/lib/functions-lib/parse-status-to-ecom.js +24 -0
- package/packages/apps/pagarme/lib/functions-lib/parse-status-to-ecom.js.map +1 -0
- package/packages/apps/pagarme/lib/index.d.ts +1 -0
- package/packages/apps/pagarme/lib/index.js +3 -0
- package/packages/apps/pagarme/lib/index.js.map +1 -0
- package/packages/apps/pagarme/lib/pagarme-create-transaction.d.ts +82 -0
- package/packages/apps/pagarme/lib/pagarme-create-transaction.js +275 -0
- package/packages/apps/pagarme/lib/pagarme-create-transaction.js.map +1 -0
- package/packages/apps/pagarme/lib/pagarme-list-payments.d.ts +7 -0
- package/packages/apps/pagarme/lib/pagarme-list-payments.js +139 -0
- package/packages/apps/pagarme/lib/pagarme-list-payments.js.map +1 -0
- package/packages/apps/pagarme/lib/pagarme-webhook.d.ts +4 -0
- package/packages/apps/pagarme/lib/pagarme-webhook.js +80 -0
- package/packages/apps/pagarme/lib/pagarme-webhook.js.map +1 -0
- package/packages/apps/pagarme/lib/pagarme.d.ts +86 -0
- package/packages/apps/pagarme/lib/pagarme.js +12 -0
- package/packages/apps/pagarme/lib/pagarme.js.map +1 -0
- package/packages/apps/pagarme/package.json +38 -0
- package/packages/apps/pagarme/scripts/build.sh +5 -0
- package/packages/apps/pagarme/src/functions-lib/add-installments.ts +59 -0
- package/packages/apps/pagarme/src/functions-lib/parse-status-to-ecom.ts +23 -0
- package/packages/apps/pagarme/src/index.ts +2 -0
- package/packages/apps/pagarme/src/pagarme-create-transaction.ts +307 -0
- package/packages/apps/pagarme/src/pagarme-list-payments.ts +158 -0
- package/packages/apps/pagarme/src/pagarme-webhook.ts +88 -0
- package/packages/apps/pagarme/src/pagarme.ts +12 -0
- package/packages/apps/pagarme/tsconfig.json +6 -0
- package/packages/apps/pagarme/webhook.js +1 -0
- package/packages/apps/pix/CHANGELOG.md +1 -0
- package/packages/apps/pix/README.md +1 -0
- package/packages/apps/pix/lib/functions-lib/get-certificate.d.ts +2 -0
- package/packages/apps/pix/lib/functions-lib/get-certificate.js +21 -0
- package/packages/apps/pix/lib/functions-lib/get-certificate.js.map +1 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/construtor.d.ts +15 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/construtor.js +65 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/construtor.js.map +1 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/create-axios.d.ts +6 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/create-axios.js +20 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/create-axios.js.map +1 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/oauth.d.ts +12 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/oauth.js +36 -0
- package/packages/apps/pix/lib/functions-lib/pix-auth/oauth.js.map +1 -0
- package/packages/apps/pix/lib/index.d.ts +1 -0
- package/packages/apps/pix/lib/index.js +3 -0
- package/packages/apps/pix/lib/index.js.map +1 -0
- package/packages/apps/pix/lib/pix-create-transaction.d.ts +73 -0
- package/packages/apps/pix/lib/pix-create-transaction.js +221 -0
- package/packages/apps/pix/lib/pix-create-transaction.js.map +1 -0
- package/packages/apps/pix/lib/pix-list-payments.d.ts +14 -0
- package/packages/apps/pix/lib/pix-list-payments.js +80 -0
- package/packages/apps/pix/lib/pix-list-payments.js.map +1 -0
- package/packages/apps/pix/lib/pix-webhook.d.ts +5 -0
- package/packages/apps/pix/lib/pix-webhook.js +146 -0
- package/packages/apps/pix/lib/pix-webhook.js.map +1 -0
- package/packages/apps/pix/lib/pix.d.ts +77 -0
- package/packages/apps/pix/lib/pix.js +13 -0
- package/packages/apps/pix/lib/pix.js.map +1 -0
- package/packages/apps/pix/package.json +36 -0
- package/packages/apps/pix/src/functions-lib/get-certificate.ts +24 -0
- package/packages/apps/pix/src/functions-lib/pix-auth/construtor.ts +87 -0
- package/packages/apps/pix/src/functions-lib/pix-auth/create-axios.ts +24 -0
- package/packages/apps/pix/src/functions-lib/pix-auth/oauth.ts +50 -0
- package/packages/apps/pix/src/index.ts +2 -0
- package/packages/apps/pix/src/pix-create-transaction.ts +261 -0
- package/packages/apps/pix/src/pix-list-payments.ts +93 -0
- package/packages/apps/pix/src/pix-webhook.ts +171 -0
- package/packages/apps/pix/src/pix.ts +13 -0
- package/packages/apps/pix/tsconfig.json +6 -0
- package/packages/apps/pix/webhook.js +1 -0
- package/packages/apps/tiny-erp/package.json +5 -5
- package/packages/cli/bin/run.mjs +1 -1
- package/packages/cli/lib/build.js +14 -7
- package/packages/cli/lib/{index.js → cli.js} +2 -2
- package/packages/cli/lib/setup-gcloud.js +1 -1
- package/packages/cli/package.json +3 -3
- package/packages/cli/src/build.ts +17 -10
- package/packages/cli/src/{index.ts → cli.ts} +2 -2
- package/packages/cli/src/setup-gcloud.ts +1 -1
- package/packages/config/lib/config.d.ts +4 -2
- package/packages/config/lib/config.js +11 -4
- package/packages/config/lib/config.js.map +1 -1
- package/packages/config/lib/env.d.ts +1 -1
- package/packages/config/package.json +2 -2
- package/packages/config/src/config.ts +14 -5
- package/packages/emails/CHANGELOG.md +1 -0
- package/packages/emails/README.md +1 -0
- package/packages/emails/lib/index.d.ts +56 -0
- package/packages/emails/lib/index.js +83 -0
- package/packages/emails/lib/index.js.map +1 -0
- package/packages/emails/lib/parse-template-to-html.d.ts +3 -0
- package/packages/emails/lib/parse-template-to-html.js +16 -0
- package/packages/emails/lib/parse-template-to-html.js.map +1 -0
- package/packages/emails/lib/providers/sendgrid/index.d.ts +8 -0
- package/packages/emails/lib/providers/sendgrid/index.js +54 -0
- package/packages/emails/lib/providers/sendgrid/index.js.map +1 -0
- package/packages/emails/lib/providers/sendgrid/parse-to-data.d.ts +5 -0
- package/packages/emails/lib/providers/sendgrid/parse-to-data.js +55 -0
- package/packages/emails/lib/providers/sendgrid/parse-to-data.js.map +1 -0
- package/packages/emails/lib/providers/smtp/index.d.ts +13 -0
- package/packages/emails/lib/providers/smtp/index.js +79 -0
- package/packages/emails/lib/providers/smtp/index.js.map +1 -0
- package/packages/emails/package.json +35 -0
- package/packages/emails/src/index.ts +144 -0
- package/packages/emails/src/parse-template-to-html.ts +19 -0
- package/packages/emails/src/providers/sendgrid/index.ts +78 -0
- package/packages/emails/src/providers/sendgrid/parse-to-data.ts +92 -0
- package/packages/emails/src/providers/smtp/index.ts +115 -0
- package/packages/emails/tests/assets/customer.json +68 -0
- package/packages/emails/tests/assets/order.json +190 -0
- package/packages/emails/tests/assets/store.json +25 -0
- package/packages/emails/tests/ex.config-sendgrid.json +19 -0
- package/packages/emails/tests/ex.config-smtp.json +21 -0
- package/packages/emails/tests/sendgrid.test.ts +156 -0
- package/packages/emails/tests/smtp.test.ts +147 -0
- package/packages/emails/tests/templates/new-order.ejs +37 -0
- package/packages/emails/tsconfig.json +6 -0
- package/packages/emails/types/index.d.ts +84 -0
- package/packages/emails/types/sendgrid.d.ts +28 -0
- package/packages/events/lib/firebase.js +8 -0
- package/packages/events/lib/firebase.js.map +1 -1
- package/packages/events/package.json +7 -3
- package/packages/events/src/firebase.ts +8 -0
- package/packages/firebase/lib/config.d.ts +15 -1
- package/packages/firebase/lib/config.js +28 -1
- package/packages/firebase/lib/config.js.map +1 -1
- package/packages/firebase/lib/helpers/pubsub.d.ts +2 -2
- package/packages/firebase/package.json +5 -5
- package/packages/firebase/src/config.ts +31 -1
- package/packages/i18n/package.json +1 -1
- package/packages/modules/lib/firebase/call-app-module.js +36 -0
- package/packages/modules/lib/firebase/call-app-module.js.map +1 -1
- package/packages/modules/package.json +9 -6
- package/packages/modules/schemas/apply_discount.cjs +47 -0
- package/packages/modules/src/firebase/call-app-module.ts +36 -0
- package/packages/passport/lib/firebase/authenticate-customer.js +1 -1
- package/packages/passport/lib/firebase/authenticate-customer.js.map +1 -1
- package/packages/passport/package.json +3 -3
- package/packages/passport/src/firebase/authenticate-customer.ts +2 -2
- package/packages/ssr/package.json +8 -8
- package/packages/storefront/.eslintrc.cjs +4 -0
- package/packages/storefront/astro.config.mjs +12 -6
- package/packages/storefront/dist/client/HeaderButtons.bc4a5c97.js +1 -0
- package/packages/storefront/dist/client/assets/_...slug_.acb18581.css +1 -0
- package/packages/storefront/dist/client/chunks/HeaderButtons.861af799.js +1 -0
- package/packages/storefront/dist/client/chunks/{LoginForm.0c5ba697.js → LoginForm.7e9c481c.js} +4 -4
- package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.1b578f5a.js +1 -0
- package/packages/storefront/dist/client/{client.69fdbd1b.js → client.75c18572.js} +1 -1
- package/packages/storefront/dist/client/manifest.webmanifest +1 -1
- package/packages/storefront/dist/client/page.5a6f3db5.js +1 -0
- package/packages/storefront/dist/client/sw.js +1 -1
- package/packages/storefront/dist/server/{avif → chunks/avif}/avif_node_dec.wasm +0 -0
- package/packages/storefront/dist/server/{avif → chunks/avif}/avif_node_enc.wasm +0 -0
- package/packages/storefront/dist/server/chunks/image-pool.f66f99fb.mjs +10791 -0
- package/packages/storefront/dist/server/{mozjpeg → chunks/mozjpeg}/mozjpeg_node_dec.wasm +0 -0
- package/packages/storefront/dist/server/{mozjpeg → chunks/mozjpeg}/mozjpeg_node_enc.wasm +0 -0
- package/packages/storefront/dist/server/{png → chunks/png}/squoosh_oxipng_bg.wasm +0 -0
- package/packages/storefront/dist/server/{png → chunks/png}/squoosh_png_bg.wasm +0 -0
- package/packages/storefront/dist/server/{resize → chunks/resize}/squoosh_resize_bg.wasm +0 -0
- package/packages/storefront/dist/server/{rotate → chunks/rotate}/rotate.wasm +0 -0
- package/packages/storefront/dist/server/{webp → chunks/webp}/webp_node_dec.wasm +0 -0
- package/packages/storefront/dist/server/{webp → chunks/webp}/webp_node_enc.wasm +0 -0
- package/packages/storefront/dist/server/entry.mjs +10832 -13568
- package/packages/storefront/dist/server/manifest.webmanifest +1 -1
- package/packages/storefront/package.json +22 -18
- package/packages/storefront/src/lib/assets/base.css +110 -0
- package/packages/storefront/src/lib/assets/dark.css +92 -0
- package/packages/storefront/src/lib/assets/forms.css +0 -0
- package/packages/storefront/src/lib/assets/pico.css +29 -130
- package/packages/storefront/src/lib/assets/preflight.css +362 -0
- package/packages/storefront/src/lib/assets/typography.css +15 -0
- package/packages/storefront/src/lib/components/ADrawer.vue +11 -11
- package/packages/storefront/src/lib/components/LoginDrawer.vue +1 -1
- package/packages/storefront/src/lib/layouts/BaseBody.astro +2 -1
- package/packages/storefront/src/lib/layouts/BaseHead.astro +13 -3
- package/packages/storefront/src/lib/layouts/BaseStateJson.astro +3 -12
- package/packages/storefront/src/lib/ssr/image.ts +11 -5
- package/packages/storefront/src/lib/ssr-context.ts +3 -3
- package/packages/storefront/src/lib/state/shopping-cart/add-cart-item.ts +37 -57
- package/packages/storefront/src/lib/state/shopping-cart/parse-product.ts +36 -0
- package/packages/storefront/src/lib/state/shopping-cart.ts +32 -1
- package/packages/storefront/src/lib/types/cms-settings.d.ts +3 -1
- package/packages/storefront/storefront.cms.cjs +41 -0
- package/packages/storefront/storefront.cms.mjs +7 -2
- package/packages/storefront/storefront.config.mjs +1 -0
- package/packages/storefront/tailwind.config.cjs +142 -113
- package/packages/storefront/uno.config.cjs +126 -0
- package/packages/types/index.ts +21 -0
- package/packages/types/modules/apply_discount:response.d.ts +32 -0
- package/packages/types/package.json +1 -1
- package/packages/storefront/dist/client/HeaderButtons.b5b4a939.js +0 -1
- package/packages/storefront/dist/client/assets/_...slug_.8d138f36.css +0 -4
- package/packages/storefront/dist/client/chunks/HeaderButtons.308edb4d.js +0 -1
- package/packages/storefront/dist/client/chunks/runtime-dom.esm-bundler.f00ab3bd.js +0 -1
- package/packages/storefront/dist/client/page.33c44e88.js +0 -1
- package/packages/storefront/uno.config.ts +0 -167
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import type { AppEventsPayload, Orders } from '@cloudcommerce/types';
|
|
2
|
+
import transactionalMails from '@ecomplus/transactional-mails';
|
|
3
|
+
import logger from 'firebase-functions/logger';
|
|
4
|
+
import api from '@cloudcommerce/api';
|
|
5
|
+
import email from '@cloudcommerce/emails';
|
|
6
|
+
import { toCamelCase, updateOrderSubresource, getStore } from './utils';
|
|
7
|
+
import triggerActions from './trigger-actions';
|
|
8
|
+
|
|
9
|
+
const orderStatus = [
|
|
10
|
+
'pending',
|
|
11
|
+
'under_analysis',
|
|
12
|
+
'authorized',
|
|
13
|
+
'unauthorized',
|
|
14
|
+
'partially_paid',
|
|
15
|
+
'paid',
|
|
16
|
+
'in_dispute',
|
|
17
|
+
'partially_refunded',
|
|
18
|
+
'refunded',
|
|
19
|
+
'canceled',
|
|
20
|
+
'voided',
|
|
21
|
+
'invoice_issued',
|
|
22
|
+
'in_production',
|
|
23
|
+
'in_separation',
|
|
24
|
+
'ready_for_shipping',
|
|
25
|
+
'partially_shipped',
|
|
26
|
+
'shipped',
|
|
27
|
+
'partially_delivered',
|
|
28
|
+
'delivered',
|
|
29
|
+
'returned_for_exchange',
|
|
30
|
+
'received_for_exchange',
|
|
31
|
+
'returned',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export default async (
|
|
35
|
+
trigger: AppEventsPayload['apiEvent'],
|
|
36
|
+
application: AppEventsPayload['app'],
|
|
37
|
+
order: Orders,
|
|
38
|
+
) => {
|
|
39
|
+
const appData = {
|
|
40
|
+
...application.data,
|
|
41
|
+
...application.hidden_data,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const store = getStore();
|
|
45
|
+
|
|
46
|
+
// logger.log('# Order');
|
|
47
|
+
const { action } = trigger;
|
|
48
|
+
const modifiedFields: AppEventsPayload['apiEvent']['modified_fields'] = [];
|
|
49
|
+
trigger.modified_fields.forEach((field) => {
|
|
50
|
+
if (field === 'payments_history' || field === 'fulfillment') {
|
|
51
|
+
modifiedFields.push(field);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const lang = (appData.lang && appData.lang === 'Inglês') ? 'en_us' : (store.lang || 'pt_br');
|
|
56
|
+
let html: string | undefined;
|
|
57
|
+
let templateId: string | undefined;
|
|
58
|
+
|
|
59
|
+
if (action !== 'delete') {
|
|
60
|
+
const triggerBody = trigger.body;
|
|
61
|
+
const resourceId = trigger.resource_id;
|
|
62
|
+
const insertedId = triggerBody._id || null;
|
|
63
|
+
const orderId = resourceId;
|
|
64
|
+
|
|
65
|
+
if (store && order && order.buyers && order.buyers) {
|
|
66
|
+
let checkStatus: string | undefined = order.status;
|
|
67
|
+
let lastValidRecord: { status: string; };
|
|
68
|
+
const customerId = order.buyers[0]._id;
|
|
69
|
+
const customer = (await api.get(`customers/${customerId}`)).data;
|
|
70
|
+
// fulfillment payments_history
|
|
71
|
+
if (customer) {
|
|
72
|
+
modifiedFields.forEach(async (subresource) => {
|
|
73
|
+
let isCustomerNotified: boolean = false;
|
|
74
|
+
let lastNotifiedStatus: string | undefined;
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(order[subresource])) {
|
|
77
|
+
const sortedRecords = order[subresource]
|
|
78
|
+
.sort((
|
|
79
|
+
a: { [x: string]: any; },
|
|
80
|
+
b: { [x: string]: any; },
|
|
81
|
+
) => (a.date_time > b.date_time ? -1 : 1));
|
|
82
|
+
|
|
83
|
+
lastValidRecord = sortedRecords.find(
|
|
84
|
+
({ status }) => orderStatus.includes(status),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (lastValidRecord) {
|
|
88
|
+
checkStatus = lastValidRecord.status;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
isCustomerNotified = Boolean(order[subresource]
|
|
92
|
+
.find((entry) => entry._id === insertedId && entry.customer_notified));
|
|
93
|
+
|
|
94
|
+
if (!isCustomerNotified) {
|
|
95
|
+
const lastNotification = sortedRecords.find((entry) => entry.customer_notified);
|
|
96
|
+
|
|
97
|
+
if (lastNotification) {
|
|
98
|
+
lastNotifiedStatus = lastNotification.status;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (checkStatus) {
|
|
104
|
+
const triggerStatus = toCamelCase(checkStatus);
|
|
105
|
+
let subject = `${triggerActions[triggerStatus].subject[lang]} #${order.number}`;
|
|
106
|
+
/*
|
|
107
|
+
TODO: The SES application configuration file is in SnakeCase
|
|
108
|
+
when referring to status.
|
|
109
|
+
In case application settings change to CamelCase,
|
|
110
|
+
change checkStatus to triggerStatus
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
let customMessage: any;
|
|
114
|
+
if (appData[checkStatus] && appData[checkStatus].custom_message) {
|
|
115
|
+
customMessage = appData[checkStatus].custom_message;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (!isCustomerNotified && lastNotifiedStatus !== checkStatus) {
|
|
119
|
+
// logger.log('> Notify the customer <');
|
|
120
|
+
|
|
121
|
+
if (subresource === 'payments_history') {
|
|
122
|
+
if (!order.financial_status) {
|
|
123
|
+
order.financial_status = {
|
|
124
|
+
current: checkStatus as Exclude<Orders['financial_status'], undefined>['current'],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (
|
|
129
|
+
!lastNotifiedStatus
|
|
130
|
+
&& order.status !== 'cancelled'
|
|
131
|
+
&& checkStatus !== 'unauthorized'
|
|
132
|
+
&& checkStatus !== 'in_dispute'
|
|
133
|
+
&& checkStatus !== 'refunded'
|
|
134
|
+
&& checkStatus !== 'voided'
|
|
135
|
+
) {
|
|
136
|
+
// new order
|
|
137
|
+
subject = `${triggerActions.newOrder.subject[lang]} #${order.number}`;
|
|
138
|
+
if (appData.new_order && appData.new_order.custom_message) {
|
|
139
|
+
customMessage = appData.new_order.custom_message;
|
|
140
|
+
} else {
|
|
141
|
+
customMessage = undefined;
|
|
142
|
+
}
|
|
143
|
+
templateId = appData.new_order && appData.new_order.templateId;
|
|
144
|
+
html = await transactionalMails.new_order(
|
|
145
|
+
store,
|
|
146
|
+
customer,
|
|
147
|
+
order,
|
|
148
|
+
lang,
|
|
149
|
+
customMessage,
|
|
150
|
+
);
|
|
151
|
+
} else if (
|
|
152
|
+
checkStatus !== 'under_analysis'
|
|
153
|
+
|| Date.now() - new Date(order.created_at).getTime() > 180000
|
|
154
|
+
) {
|
|
155
|
+
// TODO: appData[ ] is in SnakeCase
|
|
156
|
+
|
|
157
|
+
templateId = appData[checkStatus] && appData[checkStatus].templateId;
|
|
158
|
+
html = await transactionalMails[triggerStatus](
|
|
159
|
+
store,
|
|
160
|
+
customer,
|
|
161
|
+
order,
|
|
162
|
+
lang,
|
|
163
|
+
customMessage,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
if (!order.fulfillment_status) {
|
|
168
|
+
order.fulfillment_status = {
|
|
169
|
+
current: checkStatus as Exclude<Orders['fulfillment_status'], undefined>['current'],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// TODO: appData[ ] is in SnakeCase
|
|
174
|
+
templateId = appData[checkStatus] && appData[checkStatus].templateId;
|
|
175
|
+
html = await transactionalMails[triggerStatus](
|
|
176
|
+
store,
|
|
177
|
+
customer,
|
|
178
|
+
order,
|
|
179
|
+
lang,
|
|
180
|
+
customMessage,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (html) {
|
|
185
|
+
// const template = transactionalMails.template(triggerStatus)
|
|
186
|
+
// TODO: Need to change (PR) in transactionalMails?
|
|
187
|
+
|
|
188
|
+
const to = [{
|
|
189
|
+
name: customer.display_name,
|
|
190
|
+
email: customer.main_email,
|
|
191
|
+
}];
|
|
192
|
+
await email.send(
|
|
193
|
+
{
|
|
194
|
+
to,
|
|
195
|
+
subject,
|
|
196
|
+
html,
|
|
197
|
+
templateId,
|
|
198
|
+
templateData: {
|
|
199
|
+
store,
|
|
200
|
+
customer,
|
|
201
|
+
order,
|
|
202
|
+
lang,
|
|
203
|
+
customMessage,
|
|
204
|
+
},
|
|
205
|
+
// template
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
// logger.log('>> Email sent');
|
|
209
|
+
if (subresource === 'payments_history' || subresource === 'fulfillment') {
|
|
210
|
+
await updateOrderSubresource(
|
|
211
|
+
orderId,
|
|
212
|
+
subresource,
|
|
213
|
+
lastValidRecord,
|
|
214
|
+
insertedId,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// logger.log('(App Emails) Success');
|
|
220
|
+
} else {
|
|
221
|
+
logger.warn('(App Emails) Not Found Status');
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
logger.warn('(App Emails) Not Found Customer');
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
logger.warn('(App Emails) Not found Order or Store');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return null;
|
|
232
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
welcome: {
|
|
3
|
+
action: 'welcome',
|
|
4
|
+
subject: {
|
|
5
|
+
pt_br: 'Boas vindas!',
|
|
6
|
+
en_us: 'Welcome!',
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
abandonedCart: {
|
|
10
|
+
action: 'abandonedCart',
|
|
11
|
+
subject: {
|
|
12
|
+
pt_br: 'Finalize suas compras!',
|
|
13
|
+
en_us: 'Complete your purchase',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
newOrder: {
|
|
17
|
+
action: 'newOrder',
|
|
18
|
+
subject: {
|
|
19
|
+
pt_br: 'Pedido recebido com sucesso',
|
|
20
|
+
en_us: 'Order confirmed',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
pending: {
|
|
24
|
+
action: 'pending',
|
|
25
|
+
subject: {
|
|
26
|
+
pt_br: 'O pagamento do seu pedido está pendente',
|
|
27
|
+
en_us: 'Pending payment',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
delivered: {
|
|
31
|
+
action: 'delivered',
|
|
32
|
+
subject: {
|
|
33
|
+
pt_br: 'Seu pedido foi entregue!',
|
|
34
|
+
en_us: 'A shipment from your order has been delivered',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
payment: {
|
|
38
|
+
action: 'payment',
|
|
39
|
+
subject: {
|
|
40
|
+
pt_br: 'Seu pagamento foi aprovado!',
|
|
41
|
+
en_us: 'Payment accepted!',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
shipped: {
|
|
45
|
+
action: 'shipped',
|
|
46
|
+
subject: {
|
|
47
|
+
pt_br: 'Seu pedido está a caminho!',
|
|
48
|
+
en_us: 'Your package is on the way!',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
unauthorized: {
|
|
52
|
+
action: 'unauthorized',
|
|
53
|
+
subject: {
|
|
54
|
+
pt_br: 'Pagamento não autorizado',
|
|
55
|
+
en_us: 'Your payment is unauthorized',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
voided: {
|
|
59
|
+
action: 'voided',
|
|
60
|
+
subject: {
|
|
61
|
+
pt_br: 'Seu pedido foi cancelado',
|
|
62
|
+
en_us: 'Your order has been canceled',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
underAnalysis: {
|
|
66
|
+
action: 'underAnalysis',
|
|
67
|
+
subject: {
|
|
68
|
+
pt_br: 'Seu pedido está em análise',
|
|
69
|
+
en_us: 'Request under review',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
partiallyPaid: {
|
|
73
|
+
action: 'partiallyPaid',
|
|
74
|
+
subject: {
|
|
75
|
+
pt_br: 'Seu pedido foi parcialmente pago',
|
|
76
|
+
en_us: 'Order partially paid',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
paid: {
|
|
80
|
+
action: 'paid',
|
|
81
|
+
subject: {
|
|
82
|
+
pt_br: 'Seu pagamento foi aprovado!',
|
|
83
|
+
en_us: 'Your order is paid',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
inDispute: {
|
|
87
|
+
action: 'inDispute',
|
|
88
|
+
subject: {
|
|
89
|
+
pt_br: 'Pagamento em disputa',
|
|
90
|
+
en_us: 'Payment in dispute',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
partiallyRefunded: {
|
|
94
|
+
action: 'partiallyRefunded',
|
|
95
|
+
subject: {
|
|
96
|
+
pt_br: 'Pagamento parcialmente estornado',
|
|
97
|
+
en_us: 'Partially reversed payment',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
refunded: {
|
|
101
|
+
action: 'refunded',
|
|
102
|
+
subject: {
|
|
103
|
+
pt_br: 'Pagamento estornado',
|
|
104
|
+
en_us: 'Refunded Payment',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
invoiceIssued: {
|
|
108
|
+
action: 'invoice_issued',
|
|
109
|
+
subject: {
|
|
110
|
+
pt_br: 'Nota Fiscal do seu pedido',
|
|
111
|
+
en_us: 'Invoice of your order',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
inProduction: {
|
|
115
|
+
action: 'inProduction',
|
|
116
|
+
subject: {
|
|
117
|
+
pt_br: 'Seu pedido está em produção!',
|
|
118
|
+
en_us: 'Your order is in production',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
inSeparation: {
|
|
122
|
+
action: 'inSeparation',
|
|
123
|
+
subject: {
|
|
124
|
+
pt_br: 'Produto em separação',
|
|
125
|
+
en_us: 'Separating product(s)',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
readyForShipping: {
|
|
129
|
+
action: 'readyForShipping',
|
|
130
|
+
subject: {
|
|
131
|
+
pt_br: 'Seu pedido está pronto para o envio!',
|
|
132
|
+
en_us: 'Your order is ready for shipping',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
partiallyShipped: {
|
|
136
|
+
action: 'partiallyShipped',
|
|
137
|
+
subject: {
|
|
138
|
+
pt_br: 'Seu pedido foi parcialmente enviado',
|
|
139
|
+
en_us: 'Your order is partly shipped',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
partiallyDelivered: {
|
|
143
|
+
action: 'partiallyDelivered',
|
|
144
|
+
subject: {
|
|
145
|
+
pt_br: 'Seu pedido foi parcialmente entregue',
|
|
146
|
+
en_us: 'Your order is partially delivered',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
returnedForExchange: {
|
|
150
|
+
action: 'returnedForExchange',
|
|
151
|
+
subject: {
|
|
152
|
+
pt_br: 'Enviado para troca',
|
|
153
|
+
en_us: 'Sent for exchange',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
receivedForExchange: {
|
|
157
|
+
action: 'receivedForExchange',
|
|
158
|
+
subject: {
|
|
159
|
+
pt_br: 'Pedido recebido para troca',
|
|
160
|
+
en_us: 'Order received for exchange',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
returned: {
|
|
164
|
+
action: 'returned',
|
|
165
|
+
subject: {
|
|
166
|
+
pt_br: 'Seu pedido foi retornado',
|
|
167
|
+
en_us: 'Your order has returned',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
authorized: {
|
|
171
|
+
action: 'authorized',
|
|
172
|
+
subject: {
|
|
173
|
+
pt_br: 'Seu pedido está autorizado!',
|
|
174
|
+
en_us: 'Your order is authorized',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import api from '@cloudcommerce/api';
|
|
2
|
+
import config from '@cloudcommerce/firebase/lib/config';
|
|
3
|
+
|
|
4
|
+
const updateOrderSubresource = (
|
|
5
|
+
orderId: string,
|
|
6
|
+
subresource: string,
|
|
7
|
+
lastValidRecord: { [key: string]: any },
|
|
8
|
+
insertedId: string,
|
|
9
|
+
) => {
|
|
10
|
+
const statusRecordId: string = lastValidRecord ? lastValidRecord._id : insertedId;
|
|
11
|
+
|
|
12
|
+
const body = {
|
|
13
|
+
customer_notified: true,
|
|
14
|
+
};
|
|
15
|
+
return api.patch(`orders/${orderId}/${subresource}/${statusRecordId}`, body);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const toCamelCase = (status: string) => {
|
|
19
|
+
return status.replace(/^([A-Z])|[\s-_](\w)/g, (p1, p2) => {
|
|
20
|
+
if (p2) return p2.toUpperCase();
|
|
21
|
+
return p1.toLowerCase();
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getStore = () => {
|
|
26
|
+
const { cmsSettings } = config.get();
|
|
27
|
+
return {
|
|
28
|
+
lang: cmsSettings.lang,
|
|
29
|
+
domain: cmsSettings.domain,
|
|
30
|
+
name: cmsSettings.name,
|
|
31
|
+
corporate_name: cmsSettings.corporate_name || cmsSettings.name,
|
|
32
|
+
contact_email: cmsSettings.email,
|
|
33
|
+
logo: {
|
|
34
|
+
url: `https://${cmsSettings.domain}${cmsSettings.logo}`,
|
|
35
|
+
},
|
|
36
|
+
address: cmsSettings.address,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
updateOrderSubresource,
|
|
42
|
+
toCamelCase,
|
|
43
|
+
getStore,
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './firebase';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/app-frenet",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.128",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce app for Frenet shipping calculation",
|
|
6
6
|
"main": "lib/frenet.js",
|
|
7
7
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@cloudcommerce/api": "workspace:*",
|
|
23
|
-
"axios": "^1.
|
|
23
|
+
"axios": "^1.2.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@cloudcommerce/types": "workspace:*"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Please refer to GitHub [repository releases](https://github.com/ecomplus/cloud-commerce/releases) or monorepo unified [CHANGELOG.md](https://github.com/ecomplus/cloud-commerce/blob/main/CHANGELOG.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# `@cloudcommerce/app-infinitepay`
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
(function () {
|
|
3
|
+
window._infiniteHashCard = function (cardClient) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const elementsForm = `
|
|
6
|
+
<input type="text" data-ip="method" value="credit_card" style="display: none;>
|
|
7
|
+
<input type="text" data-ip="card-cvv" value="${cardClient.cvc}" style="display: none;">
|
|
8
|
+
<input type="text" data-ip="card-number" value="${cardClient.number}" style="display: none;">
|
|
9
|
+
<input type="text" data-ip="card-expiration-month" value="${cardClient.month.toString()}" style="display: none;">
|
|
10
|
+
<input type="text" data-ip="card-expiration-year" value="${cardClient.year.toString()}" style="display: none;">
|
|
11
|
+
<input type="text" data-ip="card-holder-name" value="${cardClient.name}" style="display: none;">
|
|
12
|
+
<input type="text" data-ip="card-holder-document" value="${cardClient.doc}" style="display: none;">`
|
|
13
|
+
|
|
14
|
+
const newForm = document.createElement('form')
|
|
15
|
+
newForm.setAttribute('id', 'formIP')
|
|
16
|
+
newForm.innerHTML = elementsForm
|
|
17
|
+
|
|
18
|
+
document.body.appendChild(newForm)
|
|
19
|
+
|
|
20
|
+
const access_token = window._infiniteJwtTokenCard
|
|
21
|
+
// const sandbox = window._infiniteCardSandbox
|
|
22
|
+
const form = document.querySelector('#formIP')
|
|
23
|
+
const ipay = new IPay({ access_token })
|
|
24
|
+
// console.log('ipay ', ipay)
|
|
25
|
+
ipay.listeners = {
|
|
26
|
+
'result:success': function () {
|
|
27
|
+
// form.submit() // sucesso, continue o pagamento
|
|
28
|
+
console.log('Tokenize OK')
|
|
29
|
+
const token = document.querySelector("[name='ip[token]']").value
|
|
30
|
+
const sessionId = document.querySelector("[name='ip[session_id]']").value
|
|
31
|
+
const card = {
|
|
32
|
+
token,
|
|
33
|
+
cvv: cardClient.cvc,
|
|
34
|
+
card_holder_name: cardClient.name
|
|
35
|
+
}
|
|
36
|
+
const metadata = {
|
|
37
|
+
origin: 'ecomplus',
|
|
38
|
+
store_url: window.location.hostname,
|
|
39
|
+
risk: {
|
|
40
|
+
session_id: sessionId
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const json = JSON.stringify({ card, metadata })
|
|
44
|
+
const data = window.btoa(json)
|
|
45
|
+
resolve(data)
|
|
46
|
+
},
|
|
47
|
+
'result:error': function (errors) {
|
|
48
|
+
console.log('error: ')
|
|
49
|
+
console.log(errors) // erro da tokenização, mostra no console
|
|
50
|
+
reject(errors)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
ipay.generate(form)
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
}())
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ListPaymentsResponse } from '@cloudcommerce/types/modules/list_payments:response';
|
|
2
|
+
type Gateway = ListPaymentsResponse['payment_gateways'][number];
|
|
3
|
+
declare const addInstallments: (total: number | undefined, installments: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}, gateway: Gateway, response?: ListPaymentsResponse) => {
|
|
6
|
+
response: ListPaymentsResponse | undefined;
|
|
7
|
+
gateway: {
|
|
8
|
+
label: string;
|
|
9
|
+
text?: string | undefined;
|
|
10
|
+
icon?: string | undefined;
|
|
11
|
+
intermediator?: {
|
|
12
|
+
name?: string | undefined;
|
|
13
|
+
link?: string | undefined;
|
|
14
|
+
code: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
payment_url?: string | undefined;
|
|
17
|
+
type?: "payment" | "recurrence" | undefined;
|
|
18
|
+
payment_method: {
|
|
19
|
+
code: "credit_card" | "banking_billet" | "online_debit" | "account_deposit" | "debit_card" | "balance_on_intermediary" | "loyalty_points" | "other";
|
|
20
|
+
name?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
discount?: {
|
|
23
|
+
apply_at?: "total" | "subtotal" | "freight" | undefined;
|
|
24
|
+
type?: "fixed" | "percentage" | undefined;
|
|
25
|
+
value?: number | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
card_companies?: string[] | undefined;
|
|
28
|
+
installment_options?: {
|
|
29
|
+
number: number;
|
|
30
|
+
value: number;
|
|
31
|
+
tax?: boolean | undefined;
|
|
32
|
+
}[] | undefined;
|
|
33
|
+
js_client?: {
|
|
34
|
+
script_uri: string;
|
|
35
|
+
fallback_script_uri?: string | undefined;
|
|
36
|
+
onload_expression?: string | undefined;
|
|
37
|
+
container_html?: string | undefined;
|
|
38
|
+
transaction_promise?: string | undefined;
|
|
39
|
+
cc_hash?: {
|
|
40
|
+
function: string;
|
|
41
|
+
is_promise?: boolean | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
cc_installments?: {
|
|
44
|
+
function: string;
|
|
45
|
+
is_promise?: boolean | undefined;
|
|
46
|
+
} | undefined;
|
|
47
|
+
cc_brand?: {
|
|
48
|
+
function: string;
|
|
49
|
+
is_promise?: boolean | undefined;
|
|
50
|
+
} | undefined;
|
|
51
|
+
} | undefined;
|
|
52
|
+
fetch_when_selected?: boolean | undefined;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export default addInstallments;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const standardMonthlyInterest = [
|
|
2
|
+
4.20,
|
|
3
|
+
1.3390,
|
|
4
|
+
1.5041,
|
|
5
|
+
1.5992,
|
|
6
|
+
1.6630,
|
|
7
|
+
1.7057,
|
|
8
|
+
2.3454,
|
|
9
|
+
2.3053,
|
|
10
|
+
2.2755,
|
|
11
|
+
2.2490,
|
|
12
|
+
2.2306,
|
|
13
|
+
2.2111,
|
|
14
|
+
];
|
|
15
|
+
const addInstallments = (total, installments, gateway, response) => {
|
|
16
|
+
const maxInterestFree = installments.max_interest_free;
|
|
17
|
+
const minInstallment = installments.min_installment || 5;
|
|
18
|
+
const qtyPosssibleInstallment = total ? Math.floor((total / minInstallment)) : 12;
|
|
19
|
+
const maxInstallments = installments.max_number
|
|
20
|
+
|| (qtyPosssibleInstallment < 12 ? qtyPosssibleInstallment : 12);
|
|
21
|
+
const monthlyInterest = installments.monthly_interest || 0;
|
|
22
|
+
let monthlyInstallmentInterest = 0;
|
|
23
|
+
if (maxInterestFree <= 1) {
|
|
24
|
+
const IPInterestMonthly = standardMonthlyInterest[maxInstallments - 1];
|
|
25
|
+
monthlyInstallmentInterest = (monthlyInterest > IPInterestMonthly ? monthlyInterest
|
|
26
|
+
: IPInterestMonthly);
|
|
27
|
+
}
|
|
28
|
+
if (maxInstallments > 1) {
|
|
29
|
+
if (response) {
|
|
30
|
+
response.installments_option = {
|
|
31
|
+
min_installment: minInstallment,
|
|
32
|
+
max_number: maxInterestFree > 1 ? maxInterestFree : maxInstallments,
|
|
33
|
+
monthly_interest: monthlyInstallmentInterest,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// list installment options
|
|
37
|
+
gateway.installment_options = [];
|
|
38
|
+
if (total) {
|
|
39
|
+
for (let number = 2; number <= maxInstallments; number++) {
|
|
40
|
+
const tax = !(maxInterestFree >= number);
|
|
41
|
+
let interest;
|
|
42
|
+
if (tax) {
|
|
43
|
+
const IPMonthInterestRate = standardMonthlyInterest[number - 1];
|
|
44
|
+
interest = (monthlyInterest > IPMonthInterestRate ? monthlyInterest : IPMonthInterestRate)
|
|
45
|
+
/ 100;
|
|
46
|
+
}
|
|
47
|
+
const value = !tax ? (total / number)
|
|
48
|
+
: total * (interest / (1 - (1 + interest) ** -number));
|
|
49
|
+
if (value && value >= 1) {
|
|
50
|
+
gateway.installment_options.push({
|
|
51
|
+
number,
|
|
52
|
+
value,
|
|
53
|
+
tax,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { response, gateway };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default addInstallments;
|
|
63
|
+
// # sourceMappingURL=add-installments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-installments.js","sourceRoot":"","sources":["../../src/functions-lib/add-installments.ts"],"names":[],"mappings":"AAEA,MAAM,uBAAuB,GAAG;IAC9B,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;CACP,CAAC;AAIF,MAAM,eAAe,GAAG,CACtB,KAAyB,EACzB,YAAoC,EACpC,OAAgB,EAChB,QAA+B,EAC/B,EAAE;IACF,MAAM,eAAe,GAAG,YAAY,CAAC,iBAAiB,CAAC;IACvD,MAAM,cAAc,GAAG,YAAY,CAAC,eAAe,IAAI,CAAC,CAAC;IACzD,MAAM,uBAAuB,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAClF,MAAM,eAAe,GAAG,YAAY,CAAC,UAAU;WAC1C,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAEnE,MAAM,eAAe,GAAG,YAAY,CAAC,gBAAgB,IAAI,CAAC,CAAC;IAC3D,IAAI,0BAA0B,GAAG,CAAC,CAAC;IAEnC,IAAI,eAAe,IAAI,CAAC,EAAE;QACxB,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;QAEvE,0BAA0B,GAAG,CAAC,eAAe,GAAG,iBAAiB,CAAC,CAAC,CAAC,eAAe;YACjF,CAAC,CAAC,iBAAiB,CAAC,CAAC;KACxB;IAED,IAAI,eAAe,GAAG,CAAC,EAAE;QACvB,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,mBAAmB,GAAG;gBAC7B,eAAe,EAAE,cAAc;gBAC/B,UAAU,EAAE,eAAe,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe;gBACnE,gBAAgB,EAAE,0BAA0B;aAC7C,CAAC;SACH;QAED,2BAA2B;QAC3B,OAAO,CAAC,mBAAmB,GAAG,EAAE,CAAC;QACjC,IAAI,KAAK,EAAE;YACT,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,EAAE,EAAE;gBACxD,MAAM,GAAG,GAAG,CAAC,CAAC,eAAe,IAAI,MAAM,CAAC,CAAC;gBACzC,IAAI,QAAQ,CAAC;gBACb,IAAI,GAAG,EAAE;oBACP,MAAM,mBAAmB,GAAG,uBAAuB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;oBAChE,QAAQ,GAAG,CAAC,eAAe,GAAG,mBAAmB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,mBAAmB,CAAC;0BACtF,GAAG,CAAC;iBACT;gBACD,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC;oBACnC,CAAC,CAAC,KAAK,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;gBAEzD,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC,EAAE;oBACvB,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;wBAC/B,MAAM;wBACN,KAAK;wBACL,GAAG;qBACJ,CAAC,CAAC;iBACJ;aACF;SACF;KACF;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
type Option = {
|
|
3
|
+
clientId: string;
|
|
4
|
+
clientSecret: string;
|
|
5
|
+
typeScope: string;
|
|
6
|
+
isSandbox?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export default class IPAxios {
|
|
9
|
+
preparing: Promise<unknown>;
|
|
10
|
+
axios: AxiosInstance | undefined;
|
|
11
|
+
cardTokenization: string | undefined;
|
|
12
|
+
constructor(options: Option);
|
|
13
|
+
}
|
|
14
|
+
export {};
|