cloudcommerce 0.2.1 → 0.2.3

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.
Files changed (141) hide show
  1. package/.eslintrc.cjs +1 -93
  2. package/CHANGELOG.md +37 -0
  3. package/ecomplus-stores/monocard/functions/ssr/package.json +2 -1
  4. package/ecomplus-stores/tia-sonia/functions/ssr/package.json +2 -1
  5. package/package.json +7 -7
  6. package/packages/api/package.json +1 -1
  7. package/packages/apps/correios/package.json +2 -2
  8. package/packages/apps/custom-payment/package.json +1 -1
  9. package/packages/apps/custom-shipping/package.json +1 -1
  10. package/packages/apps/datafrete/package.json +4 -4
  11. package/packages/apps/discounts/package.json +1 -1
  12. package/packages/apps/emails/package.json +2 -2
  13. package/packages/apps/fb-conversions/lib/fb-conversions-events.js +131 -111
  14. package/packages/apps/fb-conversions/lib/fb-conversions-events.js.map +1 -1
  15. package/packages/apps/fb-conversions/lib/functions-lib/create-fb-objects.js +69 -0
  16. package/packages/apps/fb-conversions/lib/functions-lib/create-fb-objects.js.map +1 -0
  17. package/packages/apps/fb-conversions/package.json +4 -4
  18. package/packages/apps/fb-conversions/src/fb-conversions-events.ts +173 -125
  19. package/packages/apps/fb-conversions/src/functions-lib/create-fb-objects.ts +104 -0
  20. package/packages/apps/frenet/package.json +4 -4
  21. package/packages/apps/galaxpay/lib/galaxpay-list-payments.d.ts +2 -2
  22. package/packages/apps/galaxpay/lib/galaxpay.d.ts +2 -2
  23. package/packages/apps/galaxpay/package.json +4 -4
  24. package/packages/apps/google-analytics/package.json +4 -4
  25. package/packages/apps/infinitepay/package.json +4 -4
  26. package/packages/apps/jadlog/package.json +2 -2
  27. package/packages/apps/loyalty-points/package.json +1 -1
  28. package/packages/apps/mercadopago/package.json +4 -4
  29. package/packages/apps/pagarme/package.json +4 -4
  30. package/packages/apps/paghiper/CHANGELOG.md +1 -0
  31. package/packages/apps/paghiper/README.md +1 -0
  32. package/packages/apps/paghiper/lib/functions-lib/create-axios.d.ts +2 -0
  33. package/packages/apps/paghiper/lib/functions-lib/create-axios.js +22 -0
  34. package/packages/apps/paghiper/lib/functions-lib/create-axios.js.map +1 -0
  35. package/packages/apps/paghiper/lib/functions-lib/handle-webhook.d.ts +3 -0
  36. package/packages/apps/paghiper/lib/functions-lib/handle-webhook.js +154 -0
  37. package/packages/apps/paghiper/lib/functions-lib/handle-webhook.js.map +1 -0
  38. package/packages/apps/paghiper/lib/index.d.ts +1 -0
  39. package/packages/apps/paghiper/lib/index.js +2 -0
  40. package/packages/apps/paghiper/lib/index.js.map +1 -0
  41. package/packages/apps/paghiper/lib/paghiper-create-transaction.d.ts +71 -0
  42. package/packages/apps/paghiper/lib/paghiper-create-transaction.js +199 -0
  43. package/packages/apps/paghiper/lib/paghiper-create-transaction.js.map +1 -0
  44. package/packages/apps/paghiper/lib/paghiper-list-payments.d.ts +7 -0
  45. package/packages/apps/paghiper/lib/paghiper-list-payments.js +97 -0
  46. package/packages/apps/paghiper/lib/paghiper-list-payments.js.map +1 -0
  47. package/packages/apps/paghiper/lib/paghiper-webhook.d.ts +5 -0
  48. package/packages/apps/paghiper/lib/paghiper-webhook.js +18 -0
  49. package/packages/apps/paghiper/lib/paghiper-webhook.js.map +1 -0
  50. package/packages/apps/paghiper/lib/paghiper.d.ts +76 -0
  51. package/packages/apps/paghiper/lib/paghiper.js +12 -0
  52. package/packages/apps/paghiper/lib/paghiper.js.map +1 -0
  53. package/packages/apps/paghiper/package.json +36 -0
  54. package/packages/apps/paghiper/src/functions-lib/create-axios.ts +21 -0
  55. package/packages/apps/paghiper/src/functions-lib/handle-webhook.ts +176 -0
  56. package/packages/apps/paghiper/src/index.ts +1 -0
  57. package/packages/apps/paghiper/src/paghiper-create-transaction.ts +242 -0
  58. package/packages/apps/paghiper/src/paghiper-list-payments.ts +127 -0
  59. package/packages/apps/paghiper/src/paghiper-webhook.ts +17 -0
  60. package/packages/apps/paghiper/src/paghiper.ts +12 -0
  61. package/packages/apps/paghiper/tsconfig.json +6 -0
  62. package/packages/apps/paghiper/types/config-app.d.ts +34 -0
  63. package/packages/apps/paghiper/webhook.js +1 -0
  64. package/packages/apps/pix/package.json +4 -4
  65. package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js.map +1 -1
  66. package/packages/apps/tiny-erp/package.json +4 -4
  67. package/packages/apps/tiny-erp/src/integration/post-tiny-erp.ts +1 -1
  68. package/packages/cli/package.json +1 -1
  69. package/packages/config/package.json +1 -1
  70. package/packages/emails/package.json +2 -2
  71. package/packages/events/lib/firebase.js +2 -0
  72. package/packages/events/lib/firebase.js.map +1 -1
  73. package/packages/events/package.json +4 -3
  74. package/packages/events/src/firebase.ts +2 -0
  75. package/packages/firebase/lib/config.d.ts +3 -0
  76. package/packages/firebase/lib/config.js +4 -0
  77. package/packages/firebase/lib/config.js.map +1 -1
  78. package/packages/firebase/package.json +3 -3
  79. package/packages/firebase/src/config.ts +4 -0
  80. package/packages/i18n/package.json +1 -1
  81. package/packages/modules/lib/firebase/call-app-module.js +12 -0
  82. package/packages/modules/lib/firebase/call-app-module.js.map +1 -1
  83. package/packages/modules/package.json +6 -5
  84. package/packages/modules/src/firebase/call-app-module.ts +12 -0
  85. package/packages/passport/package.json +3 -3
  86. package/packages/ssr/package.json +7 -7
  87. package/packages/storefront/.base.eslintrc.cjs +93 -0
  88. package/packages/storefront/.eslintrc.cjs +1 -1
  89. package/packages/storefront/astro.config.mjs +2 -0
  90. package/packages/storefront/client.d.ts +1 -1
  91. package/packages/storefront/config/storefront.cms.mjs +2 -2
  92. package/packages/storefront/dist/client/_astro/PitchBar.f3579a5b.js +1 -0
  93. package/packages/storefront/dist/client/_astro/Prices.8e5cead5.js +1 -0
  94. package/packages/storefront/dist/client/_astro/Prices.vue_vue_type_script_setup_true_lang.b8cbeb54.js +1 -0
  95. package/packages/storefront/dist/client/_astro/ProductCard.6d8b6d86.js +1 -0
  96. package/packages/storefront/dist/client/_astro/StickyHeader.7b0f3963.js +1 -0
  97. package/packages/storefront/dist/client/{assets/_...slug_.fea84512.css → _astro/_...slug_.97285eba.css} +1 -1
  98. package/packages/storefront/dist/client/_astro/client.3e777d4c.js +1 -0
  99. package/packages/storefront/dist/client/_astro/ecom-utils.92f137f6.js +1 -0
  100. package/packages/storefront/dist/client/_astro/hoisted.6edd7364.js +1 -0
  101. package/packages/storefront/dist/client/{assets → _astro}/index.90df622b.css +0 -0
  102. package/packages/storefront/dist/client/_astro/modules-info.dde776b4.js +1 -0
  103. package/packages/storefront/dist/client/_astro/runtime-core.esm-bundler.7cf33881.js +1 -0
  104. package/packages/storefront/dist/client/_astro/runtime-dom.esm-bundler.1a4c7407.js +1 -0
  105. package/packages/storefront/dist/client/{assets → _astro}/server.4d9646d8.css +0 -0
  106. package/packages/storefront/dist/client/_astro/session-utm.72684b84.js +1 -0
  107. package/packages/storefront/dist/client/{chunks/workbox-window.prod.es5.10f2e5ac.js → _astro/workbox-window.prod.es5.295a6886.js} +0 -0
  108. package/packages/storefront/dist/client/fallback/index.html +73 -0
  109. package/packages/storefront/dist/client/sw.js +1 -1
  110. package/packages/storefront/dist/server/chunks/astro.89bd9221.mjs +3378 -0
  111. package/packages/storefront/dist/server/chunks/pages/all.c27193d6.mjs +2195 -0
  112. package/packages/storefront/dist/server/chunks/prerender.89f63027.mjs +2 -0
  113. package/packages/storefront/dist/server/entry.mjs +516 -5742
  114. package/packages/storefront/package.json +9 -9
  115. package/packages/storefront/src/lib/components/Carousel.vue +1 -0
  116. package/packages/storefront/src/lib/components/CarouselControl.vue +1 -1
  117. package/packages/storefront/src/lib/components/PitchBar.vue +27 -10
  118. package/packages/storefront/src/lib/components/Prices.vue +24 -24
  119. package/packages/storefront/src/lib/components/StickyHeader.vue +56 -0
  120. package/packages/storefront/src/lib/layouts/Base.astro +6 -0
  121. package/packages/storefront/src/lib/layouts/BaseBody.astro +0 -1
  122. package/packages/storefront/src/lib/layouts/PagesHeader.astro +24 -3
  123. package/packages/storefront/src/lib/scripts/modules-info-preset.ts +60 -0
  124. package/packages/storefront/src/lib/ssr/Picture.astro +18 -0
  125. package/packages/storefront/src/lib/ssr/image.ts +12 -2
  126. package/packages/storefront/src/lib/ssr-context.ts +18 -4
  127. package/packages/storefront/src/lib/state/modules-info.ts +44 -14
  128. package/packages/storefront/src/lib/types/cms-settings.d.ts +2 -1
  129. package/packages/storefront/storefront.config.mjs +20 -8
  130. package/packages/storefront/tailwind.config.cjs +1 -1
  131. package/packages/types/index.ts +17 -0
  132. package/packages/types/package.json +1 -1
  133. package/packages/storefront/dist/client/PitchBar.afe7ff5c.js +0 -1
  134. package/packages/storefront/dist/client/Prices.eaf8a32c.js +0 -1
  135. package/packages/storefront/dist/client/ProductCard.1106b153.js +0 -1
  136. package/packages/storefront/dist/client/chunks/Prices.vue_vue_type_script_setup_true_lang.781b6501.js +0 -1
  137. package/packages/storefront/dist/client/chunks/ecom-utils.63984324.js +0 -1
  138. package/packages/storefront/dist/client/chunks/runtime-core.esm-bundler.fa6cdb60.js +0 -1
  139. package/packages/storefront/dist/client/chunks/session-utm.2de8b604.js +0 -1
  140. package/packages/storefront/dist/client/client.367a6497.js +0 -1
  141. package/packages/storefront/dist/client/hoisted.4671ed15.js +0 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-loyalty-points",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "description": "E-Com Plus Cloud Commerce app to handle simple loyalty points programs",
6
6
  "main": "lib/loyalty-points.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-mercadopago",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Mercado Pago",
6
6
  "main": "lib/mercadopago.js",
7
7
  "exports": {
@@ -25,9 +25,9 @@
25
25
  "dependencies": {
26
26
  "@cloudcommerce/api": "workspace:*",
27
27
  "@cloudcommerce/firebase": "workspace:*",
28
- "axios": "^1.2.2",
29
- "firebase-admin": "^11.4.1",
30
- "firebase-functions": "^4.1.1"
28
+ "axios": "^1.2.3",
29
+ "firebase-admin": "^11.5.0",
30
+ "firebase-functions": "^4.2.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@cloudcommerce/types": "workspace:*",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pagarme",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pagar.me",
6
6
  "main": "lib/pagarme.js",
7
7
  "exports": {
@@ -25,9 +25,9 @@
25
25
  "dependencies": {
26
26
  "@cloudcommerce/api": "workspace:*",
27
27
  "@cloudcommerce/firebase": "workspace:*",
28
- "axios": "^1.2.2",
29
- "firebase-admin": "^11.4.1",
30
- "firebase-functions": "^4.1.1",
28
+ "axios": "^1.2.3",
29
+ "firebase-admin": "^11.5.0",
30
+ "firebase-functions": "^4.2.0",
31
31
  "pagarme": "^4.29.0",
32
32
  "qs": "^6.11.0"
33
33
  },
@@ -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-paghiper`
@@ -0,0 +1,2 @@
1
+ declare const _default: (isPix?: boolean) => import("axios").AxiosInstance;
2
+ export default _default;
@@ -0,0 +1,22 @@
1
+ // Axios HTTP client
2
+ import axios from 'axios';
3
+
4
+ // returns a reusable axios instance for PagHiper API
5
+ export default (isPix) => axios.create({
6
+ // https://github.com/axios/axios#creating-an-instance
7
+ baseURL: isPix ? 'https://pix.paghiper.com/'
8
+ : 'https://api.paghiper.com/',
9
+ headers: {
10
+ 'Content-Type': 'application/json;charset=UTF-8',
11
+ Accept: 'application/json',
12
+ 'Accept-Charset': 'UTF-8',
13
+ 'Accept-Encoding': 'application/json',
14
+ },
15
+ // wait up to 30s
16
+ timeout: 30000,
17
+ validateStatus(status) {
18
+ // success only when received 201
19
+ return status === 201;
20
+ },
21
+ });
22
+ // # sourceMappingURL=create-axios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-axios.js","sourceRoot":"","sources":["../../src/functions-lib/create-axios.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,qDAAqD;AACrD,eAAe,CAAC,KAAe,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;IAC/C,sDAAsD;IACtD,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,2BAA2B;QAC1C,CAAC,CAAC,2BAA2B;IAC/B,OAAO,EAAE;QACP,cAAc,EAAE,gCAAgC;QAChD,MAAM,EAAE,kBAAkB;QAC1B,gBAAgB,EAAE,OAAO;QACzB,iBAAiB,EAAE,kBAAkB;KACtC;IACD,iBAAiB;IACjB,OAAO,EAAE,KAAK;IACd,cAAc,CAAC,MAAM;QACnB,iCAAiC;QACjC,OAAO,MAAM,KAAK,GAAG,CAAC;IACxB,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Request, Response } from 'firebase-functions';
2
+ declare const _default: (req: Request, res: Response) => Promise<Response<any>>;
3
+ export default _default;
@@ -0,0 +1,154 @@
1
+ import api from '@cloudcommerce/api';
2
+ import logger from 'firebase-functions/logger';
3
+ import config from '@cloudcommerce/firebase/lib/config';
4
+ import Axios from './create-axios.js';
5
+
6
+ const { apps } = config.get();
7
+ const CLIENT_ERR = 'invalidClient';
8
+ const listOrdersByTransaction = async (transactionCode) => {
9
+ let filters = `?transactions.intermediator.transaction_id=${transactionCode}`;
10
+ filters += '&fields=_id,transactions._id,';
11
+ filters += 'transactions.app,transactions.intermediator,transactions.status';
12
+ // send and return authenticated Store API request
13
+ const { result } = (await api.get(`/orders${filters}`)).data;
14
+ return result;
15
+ };
16
+ const readNotification = async (readNotificationBody, isPix) => {
17
+ // read full notification body from PagHiper API
18
+ // https://dev.paghiper.com/reference#qq
19
+ // returns request promise
20
+ const endpoint = `/${(isPix ? 'invoice' : 'transaction')}/notification/`;
21
+ const { data } = await Axios(isPix).post(endpoint, readNotificationBody);
22
+ return data;
23
+ };
24
+
25
+ export default async (req, res) => {
26
+ const { body } = req;
27
+ const isPix = Boolean(req.params.pix);
28
+ // handle PagHiper notification request
29
+ // https://dev.paghiper.com/reference#qq
30
+ const transactionCode = (body && body.transaction_id);
31
+ if (!transactionCode) {
32
+ return res.sendStatus(400);
33
+ }
34
+ logger.log(`> Paghiper notification for ${transactionCode}`);
35
+ // const docRef = (await collectionSubscription.doc(transactionCode).get()).data();
36
+ const Apps = (await api.get(`applications?app_id=${apps.pagHiper.appId}&fields=hidden_data`)).data.result;
37
+ const configApp = Apps[0].hidden_data?.paghiper_api_key;
38
+ try {
39
+ if (configApp.paghiper_token && configApp.paghiper_api_key === body.apiKey) {
40
+ // list order IDs for respective transaction code
41
+ const orders = await listOrdersByTransaction(transactionCode);
42
+ const paghiperResponse = await readNotification({ ...body, token: configApp.paghiper_token }, isPix);
43
+ const handleNotification = async (isRetry) => {
44
+ let { status } = paghiperResponse.status_request;
45
+ logger.log(`PagHiper ${transactionCode} -> '${status}'`);
46
+ switch (status) {
47
+ case 'pending':
48
+ case 'paid':
49
+ case 'refunded':
50
+ // is the same
51
+ break;
52
+ case 'canceled':
53
+ status = 'voided';
54
+ break;
55
+ case 'processing':
56
+ status = 'under_analysis';
57
+ break;
58
+ case 'reserved':
59
+ // https://atendimento.paghiper.com/hc/pt-br/articles/360016177713
60
+ status = 'authorized';
61
+ break;
62
+ default:
63
+ // ignore unknow status
64
+ return true;
65
+ }
66
+ try {
67
+ // change transaction status on E-Com Plus API
68
+ const notificationCode = body.notification_id;
69
+ orders.forEach(async ({ _id, transactions }) => {
70
+ let transactionId;
71
+ if (transactions) {
72
+ transactions.forEach((transaction) => {
73
+ const { app, intermediator } = transaction;
74
+ if (intermediator && intermediator.transaction_id === String(transactionCode)) {
75
+ if (transaction.status) {
76
+ if (transaction.status.current === status
77
+ || (status === 'pending' && transaction.status.current === 'paid')) {
78
+ // ignore old/duplicated notification
79
+ return;
80
+ }
81
+ }
82
+ if (app && app.intermediator && app.intermediator.code !== 'paghiper') {
83
+ return;
84
+ }
85
+ transactionId = transaction._id;
86
+ }
87
+ });
88
+ }
89
+ let bodyPaymentHistory;
90
+ if (typeof status === 'object' && status !== null) {
91
+ // request body object sent as 'status' function param
92
+ bodyPaymentHistory = status;
93
+ } else {
94
+ bodyPaymentHistory = {
95
+ date_time: new Date().toISOString(),
96
+ status,
97
+ };
98
+ if (notificationCode) {
99
+ bodyPaymentHistory.notification_code = notificationCode;
100
+ }
101
+ if (typeof transactionId === 'string' && /^[a-f0-9]{24}$/.test(transactionId)) {
102
+ bodyPaymentHistory.transaction_id = transactionId;
103
+ }
104
+ }
105
+ await api.post(`orders/${_id}/payments_history`, bodyPaymentHistory); // TODO: incompatible type
106
+ });
107
+ return res.status(204).send('SUCCESS');
108
+ } catch (err) {
109
+ //
110
+ const { message, response } = err;
111
+ let statusCode;
112
+ if (!err.request && err.name !== CLIENT_ERR && err.code !== 'EMPTY') {
113
+ // not Axios error ?
114
+ logger.error(err);
115
+ statusCode = 500;
116
+ } else {
117
+ const resStatus = response && response.status;
118
+ let debugMsg = `[#${transactionCode}] Unhandled notification: `;
119
+ if (err.config) {
120
+ debugMsg += `${err.config.url} `;
121
+ }
122
+ debugMsg += (resStatus || message);
123
+ if (!isRetry
124
+ && ((resStatus === 401 && response.data && response.data.error_code === 132)
125
+ || resStatus >= 500)) {
126
+ // delay and retry once
127
+ await new Promise((resolve) => {
128
+ setTimeout(() => {
129
+ resolve(true);
130
+ }, 700);
131
+ });
132
+ return handleNotification(true);
133
+ // statusCode = 503;
134
+ }
135
+ logger.error(debugMsg);
136
+ statusCode = 409;
137
+ }
138
+ // return response with error
139
+ return res.status(statusCode)
140
+ .send({
141
+ error: 'paghiper_notification_error',
142
+ message,
143
+ });
144
+ }
145
+ };
146
+ await handleNotification();
147
+ }
148
+ return res.status(400).send('API key does not match');
149
+ } catch (err) {
150
+ logger.error(err);
151
+ return res.sendStatus(500);
152
+ }
153
+ };
154
+ // # sourceMappingURL=handle-webhook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-webhook.js","sourceRoot":"","sources":["../../src/functions-lib/handle-webhook.ts"],"names":[],"mappings":"AAEA,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAE/C,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAEnC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;AAE9B,MAAM,UAAU,GAAG,eAAe,CAAC;AAEnC,MAAM,uBAAuB,GAAG,KAAK,EAAE,eAAuB,EAAE,EAAE;IAChE,IAAI,OAAO,GAAG,8CAA8C,eAAe,EAAE,CAAC;IAC9E,OAAO,IAAI,+BAA+B,CAAC;IAC3C,OAAO,IAAI,iEAAiE,CAAC;IAE7E,kDAAkD;IAClD,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,UAAU,OAAO,EAAc,CAAC,CAAC,CAAC,IAAI,CAAC;IACzE,OAAO,MAAkB,CAAC;AAC5B,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,KAAK,EAAE,oBAA0C,EAAE,KAAe,EAAE,EAAE;IAC7F,gDAAgD;IAChD,wCAAwC;IACxC,0BAA0B;IAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,gBAAgB,CAAC;IACzE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,oBAAoB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"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -0,0 +1,71 @@
1
+ import type { AppModuleBody } from '@cloudcommerce/types';
2
+ declare const _default: (appData: AppModuleBody) => Promise<{
3
+ status: number;
4
+ error: string;
5
+ message: string;
6
+ } | {
7
+ redirect_to_payment: boolean;
8
+ transaction: {
9
+ payment_link?: string | undefined;
10
+ payment_instructions?: string | undefined;
11
+ intermediator?: {
12
+ transaction_id?: string | undefined;
13
+ transaction_code?: string | undefined;
14
+ transaction_reference?: string | undefined;
15
+ payment_method?: {
16
+ code: string;
17
+ name?: string | undefined;
18
+ } | undefined;
19
+ buyer_id?: string | undefined;
20
+ } | undefined;
21
+ credit_card?: {
22
+ holder_name?: string | undefined;
23
+ avs_result_code?: string | null | undefined;
24
+ cvv_result_code?: string | null | undefined;
25
+ bin?: number | undefined;
26
+ company?: string | undefined;
27
+ last_digits?: string | undefined;
28
+ token?: string | undefined;
29
+ error_code?: "incorrect_number" | "invalid_number" | "invalid_expiry_date" | "invalid_cvc" | "expired_card" | "incorrect_cvc" | "incorrect_zip" | "incorrect_address" | "card_declined" | "processing_error" | "call_issuer" | "pick_up_card" | undefined;
30
+ } | undefined;
31
+ banking_billet?: {
32
+ code?: string | undefined;
33
+ valid_thru?: string | undefined;
34
+ text_lines?: string[] | undefined;
35
+ link?: string | undefined;
36
+ } | undefined;
37
+ loyalty_points?: {
38
+ name?: string | undefined;
39
+ program_id: string;
40
+ points_value: number;
41
+ ratio?: number | undefined;
42
+ } | undefined;
43
+ currency_id?: string | undefined;
44
+ currency_symbol?: string | undefined;
45
+ discount?: number | undefined;
46
+ amount: number;
47
+ installments?: {
48
+ number: number;
49
+ value?: number | undefined;
50
+ tax?: boolean | undefined;
51
+ total?: number | undefined;
52
+ } | undefined;
53
+ creditor_fees?: {
54
+ installment?: number | undefined;
55
+ operational?: number | undefined;
56
+ intermediation?: number | undefined;
57
+ other?: number | undefined;
58
+ } | undefined;
59
+ status?: {
60
+ updated_at?: string | undefined;
61
+ current: "paid" | "pending" | "refunded" | "voided" | "under_analysis" | "authorized" | "unauthorized" | "in_dispute" | "unknown";
62
+ } | undefined;
63
+ flags?: string[] | undefined;
64
+ custom_fields?: {
65
+ field: string;
66
+ value: string;
67
+ }[] | undefined;
68
+ notes?: string | undefined;
69
+ };
70
+ }>;
71
+ export default _default;
@@ -0,0 +1,199 @@
1
+ import logger from 'firebase-functions/logger';
2
+ import config from '@cloudcommerce/firebase/lib/config';
3
+ import axios from './functions-lib/create-axios.js';
4
+
5
+ const responseError = (status, error, message) => {
6
+ return {
7
+ status: status || 409,
8
+ error,
9
+ message,
10
+ };
11
+ };
12
+ const createTransactionPagHiper = async (body, isPix) => {
13
+ // create new transaction to PagHiper API
14
+ // https://dev.paghiper.com/reference#gerar-boleto
15
+ if (!isPix && process.env.PAGHIPER_PARTNER_ID) {
16
+ body.partners_id = process.env.PAGHIPER_PARTNER_ID;
17
+ } else if (isPix && process.env.PAGHIPER_PIX_PARTNER_ID) {
18
+ body.partners_id = process.env.PAGHIPER_PIX_PARTNER_ID;
19
+ }
20
+ // returns request promise
21
+ const endpoint = `/${(isPix ? 'invoice' : 'transaction')}/create/`;
22
+ return new Promise((resolve, reject) => {
23
+ axios(isPix).post(endpoint, body)
24
+ .then(({ data }) => {
25
+ // save transaction ID on database first
26
+ let createRequest;
27
+ if (isPix) {
28
+ createRequest = data.pix_create_request;
29
+ }
30
+ if (!createRequest) {
31
+ createRequest = data.create_request;
32
+ }
33
+ resolve(createRequest);
34
+ })
35
+ .catch(reject);
36
+ });
37
+ };
38
+
39
+ export default async (appData) => {
40
+ const locationId = config.get().httpsFunctionOptions.region;
41
+ const baseUri = `https://${locationId}-${process.env.GCLOUD_PROJECT}.cloudfunctions.net`;
42
+ const webhookUrl = `${baseUri}/paghiper-webhook`;
43
+ // treat module request body
44
+ const { application } = appData;
45
+ const { params } = appData;
46
+ // app configured options
47
+ const configApp = {
48
+ ...application.data,
49
+ ...application.hidden_data,
50
+ };
51
+ const orderId = params.order_id;
52
+ const orderNumber = params.order_number;
53
+ const {
54
+ amount, items, buyer, to,
55
+ } = params;
56
+ const billingAddress = params.billing_address;
57
+ logger.log(`> (App PagHiper): Create transaction for #${orderId}`);
58
+ let transaction = {
59
+ amount: amount.total,
60
+ };
61
+ // params object follows create transaction request schema:
62
+ // https://apx-mods.e-com.plus/api/v1/create_transaction/schema.json?store_id=100
63
+ // const orderId = params.order_id;
64
+ // logger.log(`> Create transaction for #${storeId} ${orderId}`);
65
+ // setup transaction body to PagHiper reference
66
+ // https://dev.paghiper.com/reference#gerar-boleto
67
+ const address = billingAddress || to;
68
+ const paghiperTransaction = {
69
+ order_id: orderId || orderNumber || new Date().getTime().toString(),
70
+ payer_email: buyer.email,
71
+ payer_name: buyer.fullname,
72
+ payer_cpf_cnpj: buyer.doc_number,
73
+ payer_phone: buyer.phone.number,
74
+ payer_street: address?.street || '',
75
+ payer_number: address?.number || '',
76
+ payer_complement: address?.complement || '',
77
+ payer_district: address?.borough || '',
78
+ payer_city: address?.city || '',
79
+ payer_state: address?.province_code || '',
80
+ payer_zip_code: address?.zip ? address.zip.replace(/\D/g, '') : '',
81
+ notification_url: webhookUrl,
82
+ discount_cents: amount.discount ? Math.round(amount.discount * 100) : '',
83
+ shipping_price_cents: amount.freight ? Math.round(amount.freight * 100) : '',
84
+ fixed_description: true,
85
+ type_bank_slip: 'boletoA4',
86
+ days_due_date: 5,
87
+ per_day_interest: true,
88
+ items: [],
89
+ };
90
+ // parse transaction items list
91
+ items.forEach((item) => {
92
+ paghiperTransaction.items.push({
93
+ description: item.name || item.product_id,
94
+ item_id: item.sku || item.product_id,
95
+ quantity: item.quantity,
96
+ price_cents: Math.round((item.final_price || item.price) * 100),
97
+ });
98
+ });
99
+ const isPix = params.payment_method.code === 'account_deposit';
100
+ if (isPix) {
101
+ paghiperTransaction.notification_url += '/pix';
102
+ }
103
+ // use configured PagHiper API key
104
+ paghiperTransaction.apiKey = configApp.paghiper_api_key;
105
+ // merge configured banking billet options
106
+ const options = configApp.banking_billet_options;
107
+ if (typeof options === 'object' && options !== null) {
108
+ // options must have only valid properties for PagHiper transaction object
109
+ Object.keys(options).forEach((prop) => {
110
+ if (options[prop]) {
111
+ paghiperTransaction[prop] = options[prop];
112
+ }
113
+ });
114
+ }
115
+ try {
116
+ // send request to PagHiper API
117
+ const createRequest = await createTransactionPagHiper(paghiperTransaction, isPix);
118
+ // transaction created successfully
119
+ // https://dev.paghiper.com/reference#exemplos
120
+ // mount response body
121
+ // https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
122
+ transaction = {
123
+ intermediator: {
124
+ transaction_id: createRequest.transaction_id,
125
+ transaction_code: createRequest.transaction_id,
126
+ transaction_reference: createRequest.order_id,
127
+ },
128
+ amount: createRequest.value_cents
129
+ ? parseInt(createRequest.value_cents, 10) / 100
130
+ // use amount from create transaction request body
131
+ : params.amount.total,
132
+ };
133
+ if (isPix) {
134
+ // https://dev.paghiper.com/reference#exemplos-pix
135
+ const pixCode = createRequest.pix_code;
136
+ if (transaction.intermediator) {
137
+ transaction.intermediator.transaction_code = pixCode.emv;
138
+ }
139
+ const pixCodeUrls = ['pix_url', 'qrcode_image_url', 'bacen_url'];
140
+ for (let i = 0; i < pixCodeUrls.length; i++) {
141
+ const pixUrl = pixCode[pixCodeUrls[i]];
142
+ if (pixUrl && pixUrl.startsWith('http')) {
143
+ transaction.payment_link = pixUrl;
144
+ break;
145
+ }
146
+ }
147
+ transaction.notes = `<img src="${pixCode.qrcode_image_url}" `
148
+ + 'style="display:block;max-width:100%;margin:0 auto" />';
149
+ } else {
150
+ const bankSlip = createRequest.bank_slip;
151
+ transaction.payment_link = bankSlip.url_slip;
152
+ transaction.banking_billet = {
153
+ code: bankSlip.digitable_line,
154
+ link: bankSlip.url_slip_pdf,
155
+ };
156
+ if (createRequest.due_date) {
157
+ transaction.banking_billet.valid_thru = new Date(createRequest.due_date).toISOString();
158
+ }
159
+ }
160
+ return {
161
+ redirect_to_payment: false,
162
+ transaction,
163
+ };
164
+ } catch (err) {
165
+ let { message } = err;
166
+ let statusCode;
167
+ if (!err.request) {
168
+ // not Axios error ?
169
+ logger.error('> (App PagHiper) =>', err);
170
+ statusCode = 500;
171
+ } else {
172
+ let debugMsg = 'Can\'t create transaction: ';
173
+ if (err.config) {
174
+ debugMsg += `${err.config.url} `;
175
+ }
176
+ if (err.response) {
177
+ debugMsg += err.response.status;
178
+ // https://dev.paghiper.com/reference#mensagens-de-retorno-2
179
+ if (err.response.status === 200) {
180
+ const { data } = err.response;
181
+ if (data) {
182
+ debugMsg += ` ${typeof data === 'object' ? JSON.stringify(data) : data}`;
183
+ debugMsg += ` ${JSON.stringify(paghiperTransaction)}`;
184
+ if (data.create_request && data.create_request.response_message) {
185
+ message = data.create_request.response_message;
186
+ }
187
+ }
188
+ }
189
+ } else {
190
+ debugMsg += message;
191
+ }
192
+ logger.error('> (App PagHiper) =>', debugMsg);
193
+ statusCode = 409;
194
+ }
195
+ // return error status code
196
+ return responseError(statusCode, 'CREATE_TRANSACTION_ERR', message);
197
+ }
198
+ };
199
+ // # sourceMappingURL=paghiper-create-transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paghiper-create-transaction.js","sourceRoot":"","sources":["../src/paghiper-create-transaction.ts"],"names":[],"mappings":"AAMA,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,KAAK,MAAM,8BAA8B,CAAC;AASjD,MAAM,aAAa,GAAG,CAAC,MAAqB,EAAE,KAAa,EAAE,OAAe,EAAE,EAAE;IAC9E,OAAO;QACL,MAAM,EAAE,MAAM,IAAI,GAAG;QACrB,KAAK;QACL,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,KAAK,EACrC,IAA0B,EAC1B,KAAe,EACD,EAAE;IAChB,yCAAyC;IACzC,kDAAkD;IAClD,IAAI,CAAC,K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ACD,IAAI,GAAG,CAAC,QAAQ,EAAE;gBAChB,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAEhC,4DAA4D;gBAC5D,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;oBAC/B,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,QAAQ,CAAC;oBAC9B,IAAI,IAAI,EAAE;wBACR,QAAQ,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;wBACzE,QAAQ,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,EAAE,CAAC;wBACtD,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE;4BAC/D,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC;yBAChD;qBACF;iBACF;aACF;iBAAM;gBACL,QAAQ,IAAI,OAAO,CAAC;aACrB;YACD,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;YAC9C,UAAU,GAAG,GAAG,CAAC;SAClB;QAED,2BAA2B;QAC3B,OAAO,aAAa,CAClB,UAAU,EACV,wBAAwB,EACxB,OAAO,CACR,CAAC;KACH;AACH,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { AppModuleBody, ListPaymentsResponse } from '@cloudcommerce/types';
2
+ declare const _default: (data: AppModuleBody) => Promise<ListPaymentsResponse | {
3
+ status: number;
4
+ error: string;
5
+ message: string;
6
+ }>;
7
+ export default _default;
@@ -0,0 +1,97 @@
1
+ // import logger from 'firebase-functions/logger';
2
+ const responseError = (status, error, message) => {
3
+ return {
4
+ status: status || 409,
5
+ error,
6
+ message,
7
+ };
8
+ };
9
+
10
+ export default async (data) => {
11
+ const { application } = data;
12
+ const { params } = data;
13
+ // https://apx-mods.e-com.plus/api/v1/list_payments/schema.json?store_id=100
14
+ const amount = params.amount || { total: undefined, discount: undefined };
15
+ // const initialTotalAmount = amount.total;
16
+ const configApp = {
17
+ ...application.data,
18
+ ...application.hidden_data,
19
+ };
20
+ // setup basic required response object
21
+ const response = {
22
+ payment_gateways: [],
23
+ };
24
+ if (!configApp.paghiper_api_key) {
25
+ // must have configured PagHiper API key and token
26
+ return responseError(400, 'LIST_PAYMENTS_ERR', 'PagHiper API key is unset on app hidden data (merchant must configure the app)');
27
+ }
28
+ const intermediator = {
29
+ name: 'PagHiper',
30
+ link: 'https://www.paghiper.com/',
31
+ code: 'paghiper',
32
+ };
33
+ const listPaymentMethods = ['banking_billet', 'account_deposit'];
34
+ listPaymentMethods.forEach((paymentMethod) => {
35
+ const isPix = paymentMethod === 'account_deposit';
36
+ const minAmount = configApp.min_amount || isPix ? 3 : 0;
37
+ const methodConfig = isPix ? configApp.pix : configApp;
38
+ const methodEnable = isPix ? configApp?.pix?.enable : configApp?.pix?.disable_billet;
39
+ // Workaround for showcase
40
+ const validateAmount = amount.total ? (amount.total >= minAmount) : true;
41
+ if (methodEnable && validateAmount) {
42
+ let label = methodConfig?.label;
43
+ if (!label) {
44
+ if (isPix) {
45
+ label = 'Pagar com Pix';
46
+ } else {
47
+ label = (!params.lang || params.lang === 'pt_br') ? 'Boleto bancário' : 'Banking billet';
48
+ }
49
+ }
50
+ const gateway = {
51
+ label,
52
+ icon: methodConfig?.icon,
53
+ text: methodConfig?.text,
54
+ payment_method: {
55
+ code: paymentMethod,
56
+ name: `${label} - ${intermediator.name}`,
57
+ },
58
+ intermediator,
59
+ };
60
+ if (!gateway.icon && isPix) {
61
+ gateway.icon = 'https://us-central1-ecom-pix.cloudfunctions.net/app/pix.png';
62
+ }
63
+ const discount = methodConfig?.discount;
64
+ gateway.discount = discount;
65
+ if (discount) {
66
+ if (discount.value > 0) {
67
+ if (amount.discount && (configApp.cumulative_discount === false)) {
68
+ // can't offer cumulative discount
69
+ delete gateway.discount;
70
+ return;
71
+ }
72
+ if (discount.apply_at !== 'freight') {
73
+ response.discount_option = {
74
+ apply_at: discount.apply_at,
75
+ type: discount.type,
76
+ value: discount.value,
77
+ label: `${label}`,
78
+ };
79
+ }
80
+ if (discount.min_amount) {
81
+ // check amount value to apply discount
82
+ if (amount.total && amount.total < discount.min_amount) {
83
+ delete gateway.discount;
84
+ } else {
85
+ delete discount.min_amount;
86
+ }
87
+ }
88
+ } else if (typeof discount.value !== 'number' || Number.isNaN(discount.value)) {
89
+ delete gateway.discount;
90
+ }
91
+ }
92
+ response.payment_gateways.push(gateway);
93
+ }
94
+ });
95
+ return response;
96
+ };
97
+ // # sourceMappingURL=paghiper-list-payments.js.map