cloudcommerce 0.0.126 → 0.0.127
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 +43 -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 +22 -0
- 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 +25 -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,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloudcommerce/app-pagarme",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.127",
|
|
5
|
+
"description": "E-Com Plus Cloud Commerce app to integrate Pagar.me",
|
|
6
|
+
"main": "lib/pagarme.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/pagarme.js",
|
|
9
|
+
"./webhook": "./lib/pagarme-webhook.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ecomplus/cloud-commerce.git",
|
|
14
|
+
"directory": "packages/apps/pagar-me"
|
|
15
|
+
},
|
|
16
|
+
"author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
|
|
17
|
+
"license": "Apache 2.0 with Commons Clause",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/ecomplus/cloud-commerce/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/pagarme#readme",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "sh scripts/build.sh"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@cloudcommerce/api": "workspace:*",
|
|
27
|
+
"@cloudcommerce/firebase": "workspace:*",
|
|
28
|
+
"axios": "^1.2.0",
|
|
29
|
+
"firebase-admin": "^11.3.0",
|
|
30
|
+
"firebase-functions": "^4.1.0",
|
|
31
|
+
"pagarme": "^4.28.0",
|
|
32
|
+
"qs": "^6.11.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@cloudcommerce/types": "workspace:*",
|
|
36
|
+
"@firebase/app-types": "^0.8.1"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ListPaymentsResponse } from '@cloudcommerce/types/modules/list_payments:response';
|
|
2
|
+
|
|
3
|
+
type Gateway = ListPaymentsResponse['payment_gateways'][number]
|
|
4
|
+
|
|
5
|
+
const addInstallments = (
|
|
6
|
+
total: number | undefined,
|
|
7
|
+
installments: { [key: string]: any },
|
|
8
|
+
gateway: Gateway,
|
|
9
|
+
response?: ListPaymentsResponse,
|
|
10
|
+
) => {
|
|
11
|
+
let maxInterestFree = total && !(installments.interest_free_min_amount > total)
|
|
12
|
+
? installments.max_interest_free
|
|
13
|
+
: 0;
|
|
14
|
+
const maxInstallments = installments.max_number && maxInterestFree
|
|
15
|
+
? Math.max(installments.max_number, maxInterestFree)
|
|
16
|
+
: installments.max_number || maxInterestFree;
|
|
17
|
+
if (maxInstallments > 1) {
|
|
18
|
+
// default installments option
|
|
19
|
+
if (!installments.monthly_interest) {
|
|
20
|
+
maxInterestFree = maxInstallments;
|
|
21
|
+
}
|
|
22
|
+
const minInstallment = installments.min_installment || 5;
|
|
23
|
+
if (response) {
|
|
24
|
+
response.installments_option = {
|
|
25
|
+
min_installment: minInstallment,
|
|
26
|
+
max_number: maxInterestFree || installments.max_number,
|
|
27
|
+
monthly_interest: maxInterestFree ? 0 : installments.monthly_interest,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// list installment options
|
|
32
|
+
gateway.installment_options = [];
|
|
33
|
+
if (total) {
|
|
34
|
+
for (let number = 2; number <= maxInstallments; number++) {
|
|
35
|
+
const tax = !(maxInterestFree >= number);
|
|
36
|
+
let interest;
|
|
37
|
+
|
|
38
|
+
if (tax) {
|
|
39
|
+
interest = installments.monthly_interest / 100;
|
|
40
|
+
}
|
|
41
|
+
const value = !tax
|
|
42
|
+
? (total / number)
|
|
43
|
+
// https://pt.wikipedia.org/wiki/Tabela_Price
|
|
44
|
+
: total * (interest / (1 - (1 + interest) ** -number));
|
|
45
|
+
|
|
46
|
+
if (value >= minInstallment) {
|
|
47
|
+
gateway.installment_options.push({
|
|
48
|
+
number,
|
|
49
|
+
value,
|
|
50
|
+
tax,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { response, gateway };
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default addInstallments;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default (pagarmeStatus: string) => {
|
|
2
|
+
switch (pagarmeStatus) {
|
|
3
|
+
case 'processing':
|
|
4
|
+
case 'analyzing':
|
|
5
|
+
return 'under_analysis';
|
|
6
|
+
case 'authorized':
|
|
7
|
+
case 'paid':
|
|
8
|
+
case 'refunded':
|
|
9
|
+
return pagarmeStatus;
|
|
10
|
+
case 'waiting_payment':
|
|
11
|
+
return 'pending';
|
|
12
|
+
case 'pending_refund':
|
|
13
|
+
return 'in_dispute';
|
|
14
|
+
case 'refused':
|
|
15
|
+
return 'unauthorized';
|
|
16
|
+
case 'chargedback':
|
|
17
|
+
return 'refunded';
|
|
18
|
+
case 'pending_review':
|
|
19
|
+
return 'authorized';
|
|
20
|
+
default:
|
|
21
|
+
return 'unknown';
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import type { CreateTransactionParams } from '@cloudcommerce/types/modules/create_transaction:params';
|
|
2
|
+
import type { CreateTransactionResponse } from '@cloudcommerce/types/modules/create_transaction:response';
|
|
3
|
+
import type { AppModuleBody } from '@cloudcommerce/types';
|
|
4
|
+
import logger from 'firebase-functions/logger';
|
|
5
|
+
import config from '@cloudcommerce/firebase/lib/config';
|
|
6
|
+
import axios from 'axios';
|
|
7
|
+
import addInstallments from './functions-lib/add-installments';
|
|
8
|
+
import parseStatus from './functions-lib/parse-status-to-ecom';
|
|
9
|
+
|
|
10
|
+
type To = Exclude<CreateTransactionParams['to'], undefined>
|
|
11
|
+
|
|
12
|
+
const parseAddress = (to: To) => ({
|
|
13
|
+
street: to.street,
|
|
14
|
+
neighborhood: to.borough,
|
|
15
|
+
city: to.city,
|
|
16
|
+
state: to.province || to.province_code,
|
|
17
|
+
country: to.country_code ? to.country_code.toLowerCase() : 'br',
|
|
18
|
+
zipcode: to.zip,
|
|
19
|
+
street_number: String(to.number) || 's/n',
|
|
20
|
+
complementary: to.complement || undefined,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export default async (appData: AppModuleBody) => {
|
|
24
|
+
const locationId = config.get().httpsFunctionOptions.region;
|
|
25
|
+
const baseUri = `https://${locationId}-${process.env.GCLOUD_PROJECT}.cloudfunctions.net`;
|
|
26
|
+
|
|
27
|
+
const { application, storeId } = appData;
|
|
28
|
+
const params = appData.params as CreateTransactionParams;
|
|
29
|
+
// app configured options
|
|
30
|
+
const configApp = { ...application.data, ...application.hidden_data };
|
|
31
|
+
const notificationUrl = `${baseUri}/pagarme-webhook`;
|
|
32
|
+
|
|
33
|
+
const orderId = params.order_id;
|
|
34
|
+
const {
|
|
35
|
+
amount,
|
|
36
|
+
buyer,
|
|
37
|
+
payer,
|
|
38
|
+
to,
|
|
39
|
+
items,
|
|
40
|
+
} = params;
|
|
41
|
+
logger.log('>(App:PagarMe) Transaction #', orderId);
|
|
42
|
+
|
|
43
|
+
// https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
|
|
44
|
+
const transaction: CreateTransactionResponse['transaction'] = {
|
|
45
|
+
amount: amount.total,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const paymentMethod = params.payment_method.code;
|
|
49
|
+
const methodConfig = configApp[paymentMethod] || {};
|
|
50
|
+
const isPix = paymentMethod === 'account_deposit';
|
|
51
|
+
const isCreditCard = paymentMethod === 'credit_card';
|
|
52
|
+
|
|
53
|
+
let { label } = methodConfig;
|
|
54
|
+
if (!label) {
|
|
55
|
+
if (isCreditCard) {
|
|
56
|
+
label = 'Cartão de crédito';
|
|
57
|
+
} else {
|
|
58
|
+
label = !isPix ? 'Boleto bancário' : 'Pix';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// https://docs.pagar.me/docs/realizando-uma-transacao-de-cartao-de-credito
|
|
63
|
+
// https://docs.pagar.me/docs/realizando-uma-transacao-de-boleto-bancario
|
|
64
|
+
let pagarmeTransaction: { [key: string]: any };
|
|
65
|
+
|
|
66
|
+
if (isCreditCard) {
|
|
67
|
+
let installmentsNumber = params.installments_number;
|
|
68
|
+
let finalAmount = amount.total;
|
|
69
|
+
if (installmentsNumber && installmentsNumber > 1) {
|
|
70
|
+
if (configApp.installments) {
|
|
71
|
+
// list all installment options
|
|
72
|
+
const { gateway } = addInstallments(
|
|
73
|
+
amount.total,
|
|
74
|
+
configApp.installments,
|
|
75
|
+
{
|
|
76
|
+
label,
|
|
77
|
+
payment_method: params.payment_method,
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
const installmentOption = gateway.installment_options
|
|
81
|
+
&& gateway.installment_options.find(({ number }) => number === installmentsNumber);
|
|
82
|
+
if (installmentOption) {
|
|
83
|
+
transaction.installments = installmentOption;
|
|
84
|
+
finalAmount = installmentOption.number * installmentOption.value;
|
|
85
|
+
transaction.installments.total = finalAmount;
|
|
86
|
+
} else {
|
|
87
|
+
installmentsNumber = 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
pagarmeTransaction = {
|
|
93
|
+
payment_method: 'credit_card',
|
|
94
|
+
amount: Math.floor(finalAmount * 100),
|
|
95
|
+
installments: installmentsNumber,
|
|
96
|
+
card_hash: params.credit_card && params.credit_card.hash,
|
|
97
|
+
};
|
|
98
|
+
} else if (params.payment_method.code === 'account_deposit') {
|
|
99
|
+
const finalAmount = amount.total;
|
|
100
|
+
const pixConfig = configApp.account_deposit;
|
|
101
|
+
const dueTime = pixConfig.due_time || 60;
|
|
102
|
+
const date = new Date();
|
|
103
|
+
date.setTime(date.getTime() + dueTime * 60000);
|
|
104
|
+
pagarmeTransaction = {
|
|
105
|
+
payment_method: 'pix',
|
|
106
|
+
amount: Math.floor(finalAmount * 100),
|
|
107
|
+
pix_expiration_date: date.toISOString(),
|
|
108
|
+
};
|
|
109
|
+
} else {
|
|
110
|
+
// banking billet
|
|
111
|
+
transaction.banking_billet = {};
|
|
112
|
+
pagarmeTransaction = {
|
|
113
|
+
payment_method: 'boleto',
|
|
114
|
+
async: false,
|
|
115
|
+
amount: Math.floor(amount.total * 100),
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const boleto = configApp.banking_billet;
|
|
119
|
+
if (boleto) {
|
|
120
|
+
if (boleto.instructions) {
|
|
121
|
+
pagarmeTransaction.boleto_instructions = boleto.instructions
|
|
122
|
+
.replace(/\r\n/g, '\n')
|
|
123
|
+
.replace(/\r/g, '\n')
|
|
124
|
+
.substr(0, 255);
|
|
125
|
+
transaction.banking_billet.text_lines = [pagarmeTransaction.boleto_instructions];
|
|
126
|
+
}
|
|
127
|
+
if (boleto.days_due_date) {
|
|
128
|
+
const date = new Date();
|
|
129
|
+
date.setDate(date.getDate() + boleto.days_due_date);
|
|
130
|
+
pagarmeTransaction.boleto_expiration_date = date.toISOString().substring(0, 10);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
pagarmeTransaction.api_key = configApp.pagarme_api_key;
|
|
136
|
+
pagarmeTransaction.postback_url = notificationUrl;
|
|
137
|
+
pagarmeTransaction.soft_descriptor = (configApp.soft_descriptor
|
|
138
|
+
|| `${params.domain}_PagarMe`).substring(0, 13);
|
|
139
|
+
pagarmeTransaction.metadata = {
|
|
140
|
+
order_number: params.order_number,
|
|
141
|
+
store_id: storeId,
|
|
142
|
+
order_id: orderId,
|
|
143
|
+
platform_integration: 'ecomplus',
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
pagarmeTransaction.customer = {
|
|
147
|
+
email: buyer.email,
|
|
148
|
+
name: buyer.fullname,
|
|
149
|
+
external_id: buyer.customer_id,
|
|
150
|
+
type: buyer.registry_type === 'j' ? 'corporation' : 'individual',
|
|
151
|
+
country: (buyer.doc_country || 'BR').toLowerCase(),
|
|
152
|
+
phone_numbers: [`+${(buyer.phone.country_code || '55')}${buyer.phone.number}`],
|
|
153
|
+
documents: [{
|
|
154
|
+
type: buyer.registry_type === 'j' ? 'cnpj' : 'cpf',
|
|
155
|
+
number: buyer.doc_number,
|
|
156
|
+
}],
|
|
157
|
+
};
|
|
158
|
+
const birthDate = buyer.birth_date;
|
|
159
|
+
if (birthDate && birthDate.year && birthDate.day && birthDate.month) {
|
|
160
|
+
pagarmeTransaction.customer.birthday = `${birthDate.year}-`
|
|
161
|
+
+ `${birthDate.month.toString().padStart(2, '0')}-${birthDate.day.toString().padStart(2, '0')}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (to && to.street) {
|
|
165
|
+
pagarmeTransaction.shipping = {
|
|
166
|
+
name: to.name || buyer.fullname,
|
|
167
|
+
fee: Math.floor((amount.freight || 0) * 100),
|
|
168
|
+
address: parseAddress(to),
|
|
169
|
+
};
|
|
170
|
+
pagarmeTransaction.billing = {
|
|
171
|
+
name: (payer || buyer).fullname,
|
|
172
|
+
address: params.billing_address
|
|
173
|
+
? parseAddress(params.billing_address)
|
|
174
|
+
: pagarmeTransaction.shipping.address,
|
|
175
|
+
};
|
|
176
|
+
} else if (params.billing_address) {
|
|
177
|
+
pagarmeTransaction.billing = {
|
|
178
|
+
name: (payer || buyer).fullname,
|
|
179
|
+
address: parseAddress(params.billing_address),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
pagarmeTransaction.items = [];
|
|
184
|
+
items.forEach((item) => {
|
|
185
|
+
if (item.quantity > 0) {
|
|
186
|
+
pagarmeTransaction.items.push({
|
|
187
|
+
id: item.sku || item.variation_id || item.product_id,
|
|
188
|
+
title: item.name || item.sku,
|
|
189
|
+
unit_price: Math.floor((item.final_price || item.price) * 100),
|
|
190
|
+
quantity: item.quantity,
|
|
191
|
+
tangible: Boolean(to && to.street),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
// https://docs.pagar.me/reference#criar-transacao
|
|
198
|
+
const { data } = await axios({
|
|
199
|
+
url: 'https://api.pagar.me/1/transactions',
|
|
200
|
+
method: 'post',
|
|
201
|
+
data: pagarmeTransaction,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
if (data) {
|
|
205
|
+
if (data.authorized_amount) {
|
|
206
|
+
transaction.amount = data.authorized_amount / 100;
|
|
207
|
+
} else if (data.amount) {
|
|
208
|
+
transaction.amount = data.amount / 100;
|
|
209
|
+
}
|
|
210
|
+
const paymentMethodPagarMe = data.payment_method === 'pix'
|
|
211
|
+
? 'account_deposit'
|
|
212
|
+
: data.payment_method;
|
|
213
|
+
transaction.intermediator = {
|
|
214
|
+
payment_method: {
|
|
215
|
+
code: paymentMethodPagarMe || params.payment_method.code,
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
[
|
|
219
|
+
['id', 'transaction_id'],
|
|
220
|
+
['tid', 'transaction_code'],
|
|
221
|
+
['reference_key', 'transaction_reference'],
|
|
222
|
+
].forEach(([dataField, transactionField]) => {
|
|
223
|
+
if (data[dataField] && transaction.intermediator) {
|
|
224
|
+
transaction.intermediator[transactionField] = String(data[dataField]);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
if (data.customer && data.customer.id) {
|
|
228
|
+
transaction.intermediator.buyer_id = String(data.customer.id);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (transaction.banking_billet) {
|
|
232
|
+
if (data.boleto_barcode) {
|
|
233
|
+
transaction.banking_billet.code = data.boleto_barcode;
|
|
234
|
+
}
|
|
235
|
+
if (data.boleto_url && transaction.banking_billet.link) {
|
|
236
|
+
transaction.banking_billet.link = data.boleto_url;
|
|
237
|
+
transaction.payment_link = transaction.banking_billet.link;
|
|
238
|
+
}
|
|
239
|
+
if (data.boleto_expiration_date) {
|
|
240
|
+
transaction.banking_billet.valid_thru = new Date(data.boleto_expiration_date)
|
|
241
|
+
.toISOString();
|
|
242
|
+
}
|
|
243
|
+
} else if (data.card) {
|
|
244
|
+
transaction.credit_card = {
|
|
245
|
+
holder_name: data.card.holder_name,
|
|
246
|
+
last_digits: data.card.last_digits,
|
|
247
|
+
company: data.card.brand,
|
|
248
|
+
token: data.card.fingerprint,
|
|
249
|
+
};
|
|
250
|
+
} else if (paymentMethodPagarMe === 'account_deposit') {
|
|
251
|
+
const qrCode = data.pix_qr_code;
|
|
252
|
+
transaction.intermediator.transaction_code = qrCode;
|
|
253
|
+
const qrCodeSrc = `https://gerarqrcodepix.com.br/api/v1?brcode=${qrCode}&tamanho=256`;
|
|
254
|
+
transaction.notes = `<img src="${qrCodeSrc}" style="display:block;margin:0 auto">`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
transaction.status = {
|
|
258
|
+
updated_at: data.date_created || data.date_updated || new Date().toISOString(),
|
|
259
|
+
current: parseStatus(data.status),
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
status: 200,
|
|
264
|
+
redirect_to_payment: false,
|
|
265
|
+
transaction,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
status: 409,
|
|
270
|
+
message: `PAGARME_TRANSACTION_ERR Order: #${orderId} => Pagar.Me not response`,
|
|
271
|
+
};
|
|
272
|
+
} catch (error: any) {
|
|
273
|
+
logger.error('(App:PagarMe) =>', error);
|
|
274
|
+
let { message } = error;
|
|
275
|
+
//
|
|
276
|
+
const err = {
|
|
277
|
+
message: `PAGARME_TRANSACTION_ERR Order: #${orderId} => ${message}`,
|
|
278
|
+
payment: '',
|
|
279
|
+
status: 0,
|
|
280
|
+
response: '',
|
|
281
|
+
};
|
|
282
|
+
let errCode = 'PAGARME_TRANSACTION_ERR_';
|
|
283
|
+
|
|
284
|
+
if (error.response) {
|
|
285
|
+
const { status, data } = error.response;
|
|
286
|
+
if (status !== 401 && status !== 403) {
|
|
287
|
+
err.payment = JSON.stringify(pagarmeTransaction);
|
|
288
|
+
errCode += status;
|
|
289
|
+
err.status = status;
|
|
290
|
+
if (typeof data === 'object' && data) {
|
|
291
|
+
err.response = JSON.stringify(data);
|
|
292
|
+
} else {
|
|
293
|
+
err.response = data;
|
|
294
|
+
}
|
|
295
|
+
} else if (data && Array.isArray(data.errors) && data.errors[0] && data.errors[0].message) {
|
|
296
|
+
message = data.errors[0].message;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// logger.error(err);
|
|
301
|
+
return {
|
|
302
|
+
status: 409,
|
|
303
|
+
error: errCode,
|
|
304
|
+
message,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { AppModuleBody } from '@cloudcommerce/types';
|
|
2
|
+
import type { ListPaymentsParams } from '@cloudcommerce/types/modules/list_payments:params';
|
|
3
|
+
import type { ListPaymentsResponse } from '@cloudcommerce/types/modules/list_payments:response';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import url from 'url';
|
|
7
|
+
import addInstallments from './functions-lib/add-installments';
|
|
8
|
+
|
|
9
|
+
type Gateway = ListPaymentsResponse['payment_gateways'][number]
|
|
10
|
+
type CodePaymentMethod = Gateway['payment_method']['code']
|
|
11
|
+
|
|
12
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
13
|
+
|
|
14
|
+
export default (data: AppModuleBody) => {
|
|
15
|
+
const { application } = data;
|
|
16
|
+
const params = data.params as ListPaymentsParams;
|
|
17
|
+
// https://apx-mods.e-com.plus/api/v1/list_payments/schema.json?store_id=100
|
|
18
|
+
const amount = params.amount || { total: undefined };
|
|
19
|
+
const initialTotalAmount = amount.total;
|
|
20
|
+
|
|
21
|
+
const configApp = {
|
|
22
|
+
...application.data,
|
|
23
|
+
...application.hidden_data,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (!configApp.pagarme_encryption_key || !configApp.pagarme_api_key) {
|
|
27
|
+
return {
|
|
28
|
+
error: 'NO_PAGARME_KEYS',
|
|
29
|
+
message: 'Chave de API e/ou criptografia não configurada (lojista deve configurar o aplicativo)',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// https://apx-mods.e-com.plus/api/v1/list_payments/response_schema.json?store_id=100
|
|
34
|
+
const response: ListPaymentsResponse = {
|
|
35
|
+
payment_gateways: [],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const { discount } = configApp;
|
|
39
|
+
if (discount && discount.value > 0) {
|
|
40
|
+
if (discount.apply_at !== 'freight') {
|
|
41
|
+
// default discount option
|
|
42
|
+
const { value } = discount;
|
|
43
|
+
response.discount_option = {
|
|
44
|
+
label: configApp.discount_option_label,
|
|
45
|
+
value,
|
|
46
|
+
};
|
|
47
|
+
// specify the discount type and min amount is optional
|
|
48
|
+
const discountTypeMinAmount = ['type', 'min_amount'];
|
|
49
|
+
discountTypeMinAmount.forEach((prop) => {
|
|
50
|
+
if (response.discount_option && discount[prop]) {
|
|
51
|
+
response.discount_option[prop] = discount[prop];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (amount.total) {
|
|
57
|
+
// check amount value to apply discount
|
|
58
|
+
if (amount.total < discount.min_amount) {
|
|
59
|
+
discount.value = 0;
|
|
60
|
+
} else {
|
|
61
|
+
delete discount.min_amount;
|
|
62
|
+
|
|
63
|
+
// fix local amount object
|
|
64
|
+
const maxDiscount = amount[discount.apply_at || 'subtotal'];
|
|
65
|
+
let discountValue: number;
|
|
66
|
+
if (discount.type === 'percentage') {
|
|
67
|
+
discountValue = (maxDiscount * discount.value) / 100;
|
|
68
|
+
} else {
|
|
69
|
+
discountValue = discount.value;
|
|
70
|
+
if (discountValue > maxDiscount) {
|
|
71
|
+
discountValue = maxDiscount;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (discountValue > 0) {
|
|
75
|
+
amount.discount = (amount.discount || 0) + discountValue;
|
|
76
|
+
amount.total -= discountValue;
|
|
77
|
+
if (amount.total < 0) {
|
|
78
|
+
amount.total = 0;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// setup payment gateway objects
|
|
86
|
+
const intermediator = {
|
|
87
|
+
name: 'Pagar.me',
|
|
88
|
+
link: 'https://pagar.me/',
|
|
89
|
+
code: 'pagarme',
|
|
90
|
+
};
|
|
91
|
+
const listPaymentMethods = ['credit_card', 'banking_billet', 'account_deposit'];
|
|
92
|
+
|
|
93
|
+
listPaymentMethods.forEach((paymentMethod) => {
|
|
94
|
+
const methodConfig = configApp[paymentMethod] || {};
|
|
95
|
+
const isPix = paymentMethod === 'account_deposit';
|
|
96
|
+
if (!methodConfig.disable && (!isPix || methodConfig.enable)) {
|
|
97
|
+
const isCreditCard = paymentMethod === 'credit_card';
|
|
98
|
+
let { label } = methodConfig;
|
|
99
|
+
if (!label) {
|
|
100
|
+
if (isCreditCard) {
|
|
101
|
+
label = 'Cartão de crédito';
|
|
102
|
+
} else {
|
|
103
|
+
label = !isPix ? 'Boleto bancário' : 'Pix';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const gateway: Gateway = {
|
|
107
|
+
label,
|
|
108
|
+
icon: methodConfig.icon,
|
|
109
|
+
text: methodConfig.text,
|
|
110
|
+
payment_method: {
|
|
111
|
+
code: paymentMethod as CodePaymentMethod,
|
|
112
|
+
name: `${label} - ${intermediator.name}`,
|
|
113
|
+
},
|
|
114
|
+
intermediator,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
if (methodConfig.discount) {
|
|
118
|
+
gateway.discount = methodConfig.discount;
|
|
119
|
+
} else if (
|
|
120
|
+
discount
|
|
121
|
+
&& (discount[paymentMethod] === true
|
|
122
|
+
|| (!isCreditCard && discount[paymentMethod] !== false))
|
|
123
|
+
) {
|
|
124
|
+
gateway.discount = discount;
|
|
125
|
+
if (response.discount_option && !response.discount_option.label) {
|
|
126
|
+
response.discount_option.label = label;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (isCreditCard) {
|
|
131
|
+
if (!gateway.icon) {
|
|
132
|
+
// gateway.icon = `${baseUri}/credit-card.png`; // TODO: baseUri
|
|
133
|
+
gateway.icon = 'https://us-central1-ecom-pagarme.cloudfunctions.net/app/credit-card.png';
|
|
134
|
+
}
|
|
135
|
+
// https://github.com/pagarme/pagarme-js
|
|
136
|
+
gateway.js_client = {
|
|
137
|
+
script_uri: 'https://assets.pagar.me/pagarme-js/4.8/pagarme.min.js',
|
|
138
|
+
onload_expression: `window._pagarmeKey="${configApp.pagarme_encryption_key}";
|
|
139
|
+
${fs.readFileSync(path.join(__dirname, '../../assets/onload-expression.min.js'), 'utf8')}`,
|
|
140
|
+
cc_hash: {
|
|
141
|
+
function: '_pagarmeHash',
|
|
142
|
+
is_promise: true,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
const { installments } = configApp;
|
|
146
|
+
if (installments) {
|
|
147
|
+
const installmentsTotal = gateway.discount ? amount.total : initialTotalAmount;
|
|
148
|
+
// list all installment options and default one
|
|
149
|
+
addInstallments(installmentsTotal, installments, gateway, response);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
response.payment_gateways.push(gateway);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return response;
|
|
158
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
import logger from 'firebase-functions/logger';
|
|
3
|
+
import api from '@cloudcommerce/api';
|
|
4
|
+
import * as functions from 'firebase-functions/v1';
|
|
5
|
+
import config from '@cloudcommerce/firebase/lib/config';
|
|
6
|
+
import Pagarme from 'pagarme';
|
|
7
|
+
import qs from 'qs';
|
|
8
|
+
import parseStatus from './functions-lib/parse-status-to-ecom';
|
|
9
|
+
|
|
10
|
+
const ECHO_SUCCESS = 'OK';
|
|
11
|
+
|
|
12
|
+
export const pagarme = {
|
|
13
|
+
webhook: functions
|
|
14
|
+
.region(config.get().httpsFunctionOptions.region)
|
|
15
|
+
.https.onRequest(async (req, res) => {
|
|
16
|
+
const { method } = req;
|
|
17
|
+
if (method !== 'POST') {
|
|
18
|
+
res.sendStatus(405);
|
|
19
|
+
} else {
|
|
20
|
+
// read configured E-Com Plus app data
|
|
21
|
+
const app = (await api.get(
|
|
22
|
+
'applications?app_id=117391&fields=hidden_data',
|
|
23
|
+
)).data.result;
|
|
24
|
+
const apiKeyPagame = app[0].hidden_data?.pagarme_api_key;
|
|
25
|
+
|
|
26
|
+
// https://docs.pagar.me/docs/gerenciando-postbacks
|
|
27
|
+
const pagarmeTransaction = req.body && req.body.transaction;
|
|
28
|
+
if (pagarmeTransaction && pagarmeTransaction.metadata) {
|
|
29
|
+
// const storeId = parseInt(pagarmeTransaction.metadata.store_id, 10);
|
|
30
|
+
const orderId = pagarmeTransaction.metadata.order_id;
|
|
31
|
+
|
|
32
|
+
if (/^[a-f0-9]{24}$/.test(orderId)) {
|
|
33
|
+
logger.log('>(App:PagarMe) Webhook Order: ', orderId);
|
|
34
|
+
|
|
35
|
+
// validate Pagar.me postback
|
|
36
|
+
// https://github.com/pagarme/pagarme-js/issues/170#issuecomment-503729557
|
|
37
|
+
const verifyBody = qs.stringify(req.body);
|
|
38
|
+
const headerSignature = req.headers['x-hub-signature'];
|
|
39
|
+
|
|
40
|
+
if (headerSignature && !Array.isArray(headerSignature)) {
|
|
41
|
+
const signature = headerSignature.replace('sha1=', '');
|
|
42
|
+
if (!Pagarme.postback.verifySignature(apiKeyPagame, verifyBody, signature)) {
|
|
43
|
+
res.sendStatus(403);
|
|
44
|
+
} else {
|
|
45
|
+
try {
|
|
46
|
+
// get E-Com Plus order
|
|
47
|
+
const order = (await api.get(`orders/${orderId}`)).data;
|
|
48
|
+
|
|
49
|
+
if (order && order.transactions) {
|
|
50
|
+
// add new transaction status to payment history
|
|
51
|
+
const transaction = order.transactions?.find(({ intermediator }) => {
|
|
52
|
+
return intermediator
|
|
53
|
+
&& intermediator.transaction_id === String(pagarmeTransaction.id);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const bodyPaymentHistory = {
|
|
57
|
+
date_time: new Date().toISOString(),
|
|
58
|
+
status: parseStatus(req.body.current_status || pagarmeTransaction.status),
|
|
59
|
+
notification_code: req.body.fingerprint,
|
|
60
|
+
flags: ['pagarme'],
|
|
61
|
+
} as any; // TODO: incompatible type=> amount and status
|
|
62
|
+
|
|
63
|
+
if (transaction) {
|
|
64
|
+
Object.assign(bodyPaymentHistory, { transaction_id: transaction._id });
|
|
65
|
+
}
|
|
66
|
+
if (req.body.old_status) {
|
|
67
|
+
bodyPaymentHistory.flags.push(`old:${req.body.old_status}`.substring(0, 20));
|
|
68
|
+
}
|
|
69
|
+
// return appSdk.apiRequest(storeId, resource, method, body);
|
|
70
|
+
await api.post(`orders/${orderId}/payments_history`, bodyPaymentHistory);
|
|
71
|
+
res.status(200).send(ECHO_SUCCESS);
|
|
72
|
+
} else {
|
|
73
|
+
//
|
|
74
|
+
res.status(404).send('>(App:PagarMe) Order not found');
|
|
75
|
+
}
|
|
76
|
+
} catch (err: any) {
|
|
77
|
+
err.metadata = pagarmeTransaction.metadata;
|
|
78
|
+
logger.error('(App:PagarMe) =>', err);
|
|
79
|
+
res.sendStatus(500);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
res.sendStatus(404);
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
};
|