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.
- package/.eslintrc.cjs +1 -93
- package/CHANGELOG.md +37 -0
- package/ecomplus-stores/monocard/functions/ssr/package.json +2 -1
- package/ecomplus-stores/tia-sonia/functions/ssr/package.json +2 -1
- package/package.json +7 -7
- package/packages/api/package.json +1 -1
- package/packages/apps/correios/package.json +2 -2
- package/packages/apps/custom-payment/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/datafrete/package.json +4 -4
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/emails/package.json +2 -2
- package/packages/apps/fb-conversions/lib/fb-conversions-events.js +131 -111
- package/packages/apps/fb-conversions/lib/fb-conversions-events.js.map +1 -1
- package/packages/apps/fb-conversions/lib/functions-lib/create-fb-objects.js +69 -0
- package/packages/apps/fb-conversions/lib/functions-lib/create-fb-objects.js.map +1 -0
- package/packages/apps/fb-conversions/package.json +4 -4
- package/packages/apps/fb-conversions/src/fb-conversions-events.ts +173 -125
- package/packages/apps/fb-conversions/src/functions-lib/create-fb-objects.ts +104 -0
- package/packages/apps/frenet/package.json +4 -4
- package/packages/apps/galaxpay/lib/galaxpay-list-payments.d.ts +2 -2
- package/packages/apps/galaxpay/lib/galaxpay.d.ts +2 -2
- package/packages/apps/galaxpay/package.json +4 -4
- package/packages/apps/google-analytics/package.json +4 -4
- package/packages/apps/infinitepay/package.json +4 -4
- package/packages/apps/jadlog/package.json +2 -2
- package/packages/apps/loyalty-points/package.json +1 -1
- package/packages/apps/mercadopago/package.json +4 -4
- package/packages/apps/pagarme/package.json +4 -4
- package/packages/apps/paghiper/CHANGELOG.md +1 -0
- package/packages/apps/paghiper/README.md +1 -0
- package/packages/apps/paghiper/lib/functions-lib/create-axios.d.ts +2 -0
- package/packages/apps/paghiper/lib/functions-lib/create-axios.js +22 -0
- package/packages/apps/paghiper/lib/functions-lib/create-axios.js.map +1 -0
- package/packages/apps/paghiper/lib/functions-lib/handle-webhook.d.ts +3 -0
- package/packages/apps/paghiper/lib/functions-lib/handle-webhook.js +154 -0
- package/packages/apps/paghiper/lib/functions-lib/handle-webhook.js.map +1 -0
- package/packages/apps/paghiper/lib/index.d.ts +1 -0
- package/packages/apps/paghiper/lib/index.js +2 -0
- package/packages/apps/paghiper/lib/index.js.map +1 -0
- package/packages/apps/paghiper/lib/paghiper-create-transaction.d.ts +71 -0
- package/packages/apps/paghiper/lib/paghiper-create-transaction.js +199 -0
- package/packages/apps/paghiper/lib/paghiper-create-transaction.js.map +1 -0
- package/packages/apps/paghiper/lib/paghiper-list-payments.d.ts +7 -0
- package/packages/apps/paghiper/lib/paghiper-list-payments.js +97 -0
- package/packages/apps/paghiper/lib/paghiper-list-payments.js.map +1 -0
- package/packages/apps/paghiper/lib/paghiper-webhook.d.ts +5 -0
- package/packages/apps/paghiper/lib/paghiper-webhook.js +18 -0
- package/packages/apps/paghiper/lib/paghiper-webhook.js.map +1 -0
- package/packages/apps/paghiper/lib/paghiper.d.ts +76 -0
- package/packages/apps/paghiper/lib/paghiper.js +12 -0
- package/packages/apps/paghiper/lib/paghiper.js.map +1 -0
- package/packages/apps/paghiper/package.json +36 -0
- package/packages/apps/paghiper/src/functions-lib/create-axios.ts +21 -0
- package/packages/apps/paghiper/src/functions-lib/handle-webhook.ts +176 -0
- package/packages/apps/paghiper/src/index.ts +1 -0
- package/packages/apps/paghiper/src/paghiper-create-transaction.ts +242 -0
- package/packages/apps/paghiper/src/paghiper-list-payments.ts +127 -0
- package/packages/apps/paghiper/src/paghiper-webhook.ts +17 -0
- package/packages/apps/paghiper/src/paghiper.ts +12 -0
- package/packages/apps/paghiper/tsconfig.json +6 -0
- package/packages/apps/paghiper/types/config-app.d.ts +34 -0
- package/packages/apps/paghiper/webhook.js +1 -0
- package/packages/apps/pix/package.json +4 -4
- package/packages/apps/tiny-erp/lib/integration/post-tiny-erp.js.map +1 -1
- package/packages/apps/tiny-erp/package.json +4 -4
- package/packages/apps/tiny-erp/src/integration/post-tiny-erp.ts +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/emails/package.json +2 -2
- package/packages/events/lib/firebase.js +2 -0
- package/packages/events/lib/firebase.js.map +1 -1
- package/packages/events/package.json +4 -3
- package/packages/events/src/firebase.ts +2 -0
- package/packages/firebase/lib/config.d.ts +3 -0
- package/packages/firebase/lib/config.js +4 -0
- package/packages/firebase/lib/config.js.map +1 -1
- package/packages/firebase/package.json +3 -3
- package/packages/firebase/src/config.ts +4 -0
- package/packages/i18n/package.json +1 -1
- package/packages/modules/lib/firebase/call-app-module.js +12 -0
- package/packages/modules/lib/firebase/call-app-module.js.map +1 -1
- package/packages/modules/package.json +6 -5
- package/packages/modules/src/firebase/call-app-module.ts +12 -0
- package/packages/passport/package.json +3 -3
- package/packages/ssr/package.json +7 -7
- package/packages/storefront/.base.eslintrc.cjs +93 -0
- package/packages/storefront/.eslintrc.cjs +1 -1
- package/packages/storefront/astro.config.mjs +2 -0
- package/packages/storefront/client.d.ts +1 -1
- package/packages/storefront/config/storefront.cms.mjs +2 -2
- package/packages/storefront/dist/client/_astro/PitchBar.f3579a5b.js +1 -0
- package/packages/storefront/dist/client/_astro/Prices.8e5cead5.js +1 -0
- package/packages/storefront/dist/client/_astro/Prices.vue_vue_type_script_setup_true_lang.b8cbeb54.js +1 -0
- package/packages/storefront/dist/client/_astro/ProductCard.6d8b6d86.js +1 -0
- package/packages/storefront/dist/client/_astro/StickyHeader.7b0f3963.js +1 -0
- package/packages/storefront/dist/client/{assets/_...slug_.fea84512.css → _astro/_...slug_.97285eba.css} +1 -1
- package/packages/storefront/dist/client/_astro/client.3e777d4c.js +1 -0
- package/packages/storefront/dist/client/_astro/ecom-utils.92f137f6.js +1 -0
- package/packages/storefront/dist/client/_astro/hoisted.6edd7364.js +1 -0
- package/packages/storefront/dist/client/{assets → _astro}/index.90df622b.css +0 -0
- package/packages/storefront/dist/client/_astro/modules-info.dde776b4.js +1 -0
- package/packages/storefront/dist/client/_astro/runtime-core.esm-bundler.7cf33881.js +1 -0
- package/packages/storefront/dist/client/_astro/runtime-dom.esm-bundler.1a4c7407.js +1 -0
- package/packages/storefront/dist/client/{assets → _astro}/server.4d9646d8.css +0 -0
- package/packages/storefront/dist/client/_astro/session-utm.72684b84.js +1 -0
- package/packages/storefront/dist/client/{chunks/workbox-window.prod.es5.10f2e5ac.js → _astro/workbox-window.prod.es5.295a6886.js} +0 -0
- package/packages/storefront/dist/client/fallback/index.html +73 -0
- package/packages/storefront/dist/client/sw.js +1 -1
- package/packages/storefront/dist/server/chunks/astro.89bd9221.mjs +3378 -0
- package/packages/storefront/dist/server/chunks/pages/all.c27193d6.mjs +2195 -0
- package/packages/storefront/dist/server/chunks/prerender.89f63027.mjs +2 -0
- package/packages/storefront/dist/server/entry.mjs +516 -5742
- package/packages/storefront/package.json +9 -9
- package/packages/storefront/src/lib/components/Carousel.vue +1 -0
- package/packages/storefront/src/lib/components/CarouselControl.vue +1 -1
- package/packages/storefront/src/lib/components/PitchBar.vue +27 -10
- package/packages/storefront/src/lib/components/Prices.vue +24 -24
- package/packages/storefront/src/lib/components/StickyHeader.vue +56 -0
- package/packages/storefront/src/lib/layouts/Base.astro +6 -0
- package/packages/storefront/src/lib/layouts/BaseBody.astro +0 -1
- package/packages/storefront/src/lib/layouts/PagesHeader.astro +24 -3
- package/packages/storefront/src/lib/scripts/modules-info-preset.ts +60 -0
- package/packages/storefront/src/lib/ssr/Picture.astro +18 -0
- package/packages/storefront/src/lib/ssr/image.ts +12 -2
- package/packages/storefront/src/lib/ssr-context.ts +18 -4
- package/packages/storefront/src/lib/state/modules-info.ts +44 -14
- package/packages/storefront/src/lib/types/cms-settings.d.ts +2 -1
- package/packages/storefront/storefront.config.mjs +20 -8
- package/packages/storefront/tailwind.config.cjs +1 -1
- package/packages/types/index.ts +17 -0
- package/packages/types/package.json +1 -1
- package/packages/storefront/dist/client/PitchBar.afe7ff5c.js +0 -1
- package/packages/storefront/dist/client/Prices.eaf8a32c.js +0 -1
- package/packages/storefront/dist/client/ProductCard.1106b153.js +0 -1
- package/packages/storefront/dist/client/chunks/Prices.vue_vue_type_script_setup_true_lang.781b6501.js +0 -1
- package/packages/storefront/dist/client/chunks/ecom-utils.63984324.js +0 -1
- package/packages/storefront/dist/client/chunks/runtime-core.esm-bundler.fa6cdb60.js +0 -1
- package/packages/storefront/dist/client/chunks/session-utm.2de8b604.js +0 -1
- package/packages/storefront/dist/client/client.367a6497.js +0 -1
- package/packages/storefront/dist/client/hoisted.4671ed15.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paghiper-list-payments.js","sourceRoot":"","sources":["../src/paghiper-list-payments.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
import '@cloudcommerce/firebase/lib/init';
|
|
3
|
+
import * as functions from 'firebase-functions/v1';
|
|
4
|
+
import config from '@cloudcommerce/firebase/lib/config';
|
|
5
|
+
import handleWebhook from './functions-lib/handle-webhook.js';
|
|
6
|
+
|
|
7
|
+
export const paghiper = {
|
|
8
|
+
webhook: functions
|
|
9
|
+
.region(config.get().httpsFunctionOptions.region)
|
|
10
|
+
.https.onRequest((req, res) => {
|
|
11
|
+
if (req.method !== 'POST') {
|
|
12
|
+
res.sendStatus(405);
|
|
13
|
+
} else {
|
|
14
|
+
handleWebhook(req, res);
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
// # sourceMappingURL=paghiper-webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paghiper-webhook.js","sourceRoot":"","sources":["../src/paghiper-webhook.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAE3D,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE,SAAS;SACf,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,MAAM,CAAC;SAChD,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC5B,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;YACzB,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SACrB;aAAM;YACL,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SACzB;IACH,CAAC,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AppModuleBody } from '@cloudcommerce/types';
|
|
2
|
+
import '@cloudcommerce/firebase/lib/init';
|
|
3
|
+
export declare const listPayments: (modBody: AppModuleBody) => Promise<import("@cloudcommerce/types").ListPaymentsResponse | {
|
|
4
|
+
status: number;
|
|
5
|
+
error: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const createTransaction: (modBody: AppModuleBody) => Promise<{
|
|
9
|
+
status: number;
|
|
10
|
+
error: string;
|
|
11
|
+
message: string;
|
|
12
|
+
} | {
|
|
13
|
+
redirect_to_payment: boolean;
|
|
14
|
+
transaction: {
|
|
15
|
+
payment_link?: string | undefined;
|
|
16
|
+
payment_instructions?: string | undefined;
|
|
17
|
+
intermediator?: {
|
|
18
|
+
transaction_id?: string | undefined;
|
|
19
|
+
transaction_code?: string | undefined;
|
|
20
|
+
transaction_reference?: string | undefined;
|
|
21
|
+
payment_method?: {
|
|
22
|
+
code: string;
|
|
23
|
+
name?: string | undefined;
|
|
24
|
+
} | undefined;
|
|
25
|
+
buyer_id?: string | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
credit_card?: {
|
|
28
|
+
holder_name?: string | undefined;
|
|
29
|
+
avs_result_code?: string | null | undefined;
|
|
30
|
+
cvv_result_code?: string | null | undefined;
|
|
31
|
+
bin?: number | undefined;
|
|
32
|
+
company?: string | undefined;
|
|
33
|
+
last_digits?: string | undefined;
|
|
34
|
+
token?: string | undefined;
|
|
35
|
+
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;
|
|
36
|
+
} | undefined;
|
|
37
|
+
banking_billet?: {
|
|
38
|
+
code?: string | undefined;
|
|
39
|
+
valid_thru?: string | undefined;
|
|
40
|
+
text_lines?: string[] | undefined;
|
|
41
|
+
link?: string | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
loyalty_points?: {
|
|
44
|
+
name?: string | undefined;
|
|
45
|
+
program_id: string;
|
|
46
|
+
points_value: number;
|
|
47
|
+
ratio?: number | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
currency_id?: string | undefined;
|
|
50
|
+
currency_symbol?: string | undefined;
|
|
51
|
+
discount?: number | undefined;
|
|
52
|
+
amount: number;
|
|
53
|
+
installments?: {
|
|
54
|
+
number: number;
|
|
55
|
+
value?: number | undefined;
|
|
56
|
+
tax?: boolean | undefined;
|
|
57
|
+
total?: number | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
creditor_fees?: {
|
|
60
|
+
installment?: number | undefined;
|
|
61
|
+
operational?: number | undefined;
|
|
62
|
+
intermediation?: number | undefined;
|
|
63
|
+
other?: number | undefined;
|
|
64
|
+
} | undefined;
|
|
65
|
+
status?: {
|
|
66
|
+
updated_at?: string | undefined;
|
|
67
|
+
current: "paid" | "pending" | "refunded" | "voided" | "under_analysis" | "authorized" | "unauthorized" | "in_dispute" | "unknown";
|
|
68
|
+
} | undefined;
|
|
69
|
+
flags?: string[] | undefined;
|
|
70
|
+
custom_fields?: {
|
|
71
|
+
field: string;
|
|
72
|
+
value: string;
|
|
73
|
+
}[] | undefined;
|
|
74
|
+
notes?: string | undefined;
|
|
75
|
+
};
|
|
76
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '@cloudcommerce/firebase/lib/init';
|
|
2
|
+
import handleListPayments from './paghiper-list-payments.js';
|
|
3
|
+
import handleCreateTransaction from './paghiper-create-transaction.js';
|
|
4
|
+
|
|
5
|
+
export const listPayments = async (modBody) => {
|
|
6
|
+
return handleListPayments(modBody);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const createTransaction = async (modBody) => {
|
|
10
|
+
return handleCreateTransaction(modBody);
|
|
11
|
+
};
|
|
12
|
+
// # sourceMappingURL=paghiper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paghiper.js","sourceRoot":"","sources":["../src/paghiper.ts"],"names":[],"mappings":"AACA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAC1D,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AAEpE,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;IAC3D,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;IAChE,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloudcommerce/app-paghiper",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.2.3",
|
|
5
|
+
"description": "E-Com Plus Cloud Commerce app to integrate PagHiper",
|
|
6
|
+
"main": "lib/paghiper.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/paghiper.js",
|
|
9
|
+
"./webhook": "./lib/paghiper-webhook.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ecomplus/cloud-commerce.git",
|
|
14
|
+
"directory": "packages/apps/paghiper"
|
|
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/paghiper#readme",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "sh ../../../scripts/build-lib.sh"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@cloudcommerce/api": "workspace:*",
|
|
27
|
+
"@cloudcommerce/firebase": "workspace:*",
|
|
28
|
+
"axios": "^1.2.2",
|
|
29
|
+
"firebase-admin": "^11.4.1",
|
|
30
|
+
"firebase-functions": "^4.2.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@cloudcommerce/types": "workspace:*",
|
|
34
|
+
"@firebase/app-types": "^0.9.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Axios HTTP client
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
// returns a reusable axios instance for PagHiper API
|
|
5
|
+
export default (isPix?: boolean) => 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
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { Orders } from '@cloudcommerce/types';
|
|
2
|
+
import type { Request, Response } from 'firebase-functions';
|
|
3
|
+
import api from '@cloudcommerce/api';
|
|
4
|
+
import logger from 'firebase-functions/logger';
|
|
5
|
+
import { Endpoint } from '@cloudcommerce/api/lib/types';
|
|
6
|
+
import config from '@cloudcommerce/firebase/lib/config';
|
|
7
|
+
import Axios from './create-axios';
|
|
8
|
+
|
|
9
|
+
const { apps } = config.get();
|
|
10
|
+
|
|
11
|
+
const CLIENT_ERR = 'invalidClient';
|
|
12
|
+
|
|
13
|
+
const listOrdersByTransaction = async (transactionCode: string) => {
|
|
14
|
+
let filters = `?transactions.intermediator.transaction_id=${transactionCode}`;
|
|
15
|
+
filters += '&fields=_id,transactions._id,';
|
|
16
|
+
filters += 'transactions.app,transactions.intermediator,transactions.status';
|
|
17
|
+
|
|
18
|
+
// send and return authenticated Store API request
|
|
19
|
+
const { result } = (await api.get(`/orders${filters}` as Endpoint)).data;
|
|
20
|
+
return result as Orders[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const readNotification = async (readNotificationBody: { [x: string]: any }, isPix?: boolean) => {
|
|
24
|
+
// read full notification body from PagHiper API
|
|
25
|
+
// https://dev.paghiper.com/reference#qq
|
|
26
|
+
// returns request promise
|
|
27
|
+
const endpoint = `/${(isPix ? 'invoice' : 'transaction')}/notification/`;
|
|
28
|
+
const { data } = await Axios(isPix).post(endpoint, readNotificationBody);
|
|
29
|
+
return data;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default async (req: Request, res: Response) => {
|
|
33
|
+
const { body } = req;
|
|
34
|
+
const isPix = Boolean(req.params.pix);
|
|
35
|
+
// handle PagHiper notification request
|
|
36
|
+
// https://dev.paghiper.com/reference#qq
|
|
37
|
+
const transactionCode = (body && body.transaction_id);
|
|
38
|
+
if (!transactionCode) {
|
|
39
|
+
return res.sendStatus(400);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
logger.log(`> Paghiper notification for ${transactionCode}`);
|
|
43
|
+
// const docRef = (await collectionSubscription.doc(transactionCode).get()).data();
|
|
44
|
+
const Apps = (await api.get(
|
|
45
|
+
`applications?app_id=${apps.pagHiper.appId}&fields=hidden_data`,
|
|
46
|
+
)).data.result;
|
|
47
|
+
const configApp = Apps[0].hidden_data?.paghiper_api_key;
|
|
48
|
+
try {
|
|
49
|
+
if (configApp.paghiper_token && configApp.paghiper_api_key === body.apiKey) {
|
|
50
|
+
// list order IDs for respective transaction code
|
|
51
|
+
const orders = await listOrdersByTransaction(transactionCode);
|
|
52
|
+
const paghiperResponse = await readNotification(
|
|
53
|
+
{ ...body, token: configApp.paghiper_token },
|
|
54
|
+
isPix,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const handleNotification = async (isRetry?: boolean) => {
|
|
58
|
+
let { status } = paghiperResponse.status_request;
|
|
59
|
+
logger.log(`PagHiper ${transactionCode} -> '${status}'`);
|
|
60
|
+
switch (status) {
|
|
61
|
+
case 'pending':
|
|
62
|
+
case 'paid':
|
|
63
|
+
case 'refunded':
|
|
64
|
+
// is the same
|
|
65
|
+
break;
|
|
66
|
+
case 'canceled':
|
|
67
|
+
status = 'voided';
|
|
68
|
+
break;
|
|
69
|
+
case 'processing':
|
|
70
|
+
status = 'under_analysis';
|
|
71
|
+
break;
|
|
72
|
+
case 'reserved':
|
|
73
|
+
// https://atendimento.paghiper.com/hc/pt-br/articles/360016177713
|
|
74
|
+
status = 'authorized';
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
// ignore unknow status
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
// change transaction status on E-Com Plus API
|
|
83
|
+
const notificationCode = body.notification_id;
|
|
84
|
+
orders.forEach(async ({ _id, transactions }) => {
|
|
85
|
+
let transactionId: string | undefined;
|
|
86
|
+
if (transactions) {
|
|
87
|
+
transactions.forEach((transaction) => {
|
|
88
|
+
const { app, intermediator } = transaction;
|
|
89
|
+
if (intermediator && intermediator.transaction_id === String(transactionCode)) {
|
|
90
|
+
if (transaction.status) {
|
|
91
|
+
if (
|
|
92
|
+
transaction.status.current === status
|
|
93
|
+
|| (status === 'pending' && transaction.status.current === 'paid')
|
|
94
|
+
) {
|
|
95
|
+
// ignore old/duplicated notification
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (app && app.intermediator && app.intermediator.code !== 'paghiper') {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
transactionId = transaction._id;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let bodyPaymentHistory: { [x: string]: any };
|
|
108
|
+
|
|
109
|
+
if (typeof status === 'object' && status !== null) {
|
|
110
|
+
// request body object sent as 'status' function param
|
|
111
|
+
bodyPaymentHistory = status;
|
|
112
|
+
} else {
|
|
113
|
+
bodyPaymentHistory = {
|
|
114
|
+
date_time: new Date().toISOString(),
|
|
115
|
+
status,
|
|
116
|
+
};
|
|
117
|
+
if (notificationCode) {
|
|
118
|
+
bodyPaymentHistory.notification_code = notificationCode;
|
|
119
|
+
}
|
|
120
|
+
if (typeof transactionId === 'string' && /^[a-f0-9]{24}$/.test(transactionId)) {
|
|
121
|
+
bodyPaymentHistory.transaction_id = transactionId;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
await api.post(`orders/${_id}/payments_history`, bodyPaymentHistory as any); // TODO: incompatible type
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return res.status(204).send('SUCCESS');
|
|
128
|
+
} catch (err: any) {
|
|
129
|
+
//
|
|
130
|
+
const { message, response } = err;
|
|
131
|
+
let statusCode: number;
|
|
132
|
+
if (!err.request && err.name !== CLIENT_ERR && err.code !== 'EMPTY') {
|
|
133
|
+
// not Axios error ?
|
|
134
|
+
logger.error(err);
|
|
135
|
+
statusCode = 500;
|
|
136
|
+
} else {
|
|
137
|
+
const resStatus = response && response.status;
|
|
138
|
+
let debugMsg = `[#${transactionCode}] Unhandled notification: `;
|
|
139
|
+
if (err.config) {
|
|
140
|
+
debugMsg += `${err.config.url} `;
|
|
141
|
+
}
|
|
142
|
+
debugMsg += (resStatus || message);
|
|
143
|
+
|
|
144
|
+
if (!isRetry
|
|
145
|
+
&& ((resStatus === 401 && response.data && response.data.error_code === 132)
|
|
146
|
+
|| resStatus >= 500)
|
|
147
|
+
) {
|
|
148
|
+
// delay and retry once
|
|
149
|
+
await new Promise((resolve) => {
|
|
150
|
+
setTimeout(() => {
|
|
151
|
+
resolve(true);
|
|
152
|
+
}, 700);
|
|
153
|
+
});
|
|
154
|
+
return handleNotification(true);
|
|
155
|
+
// statusCode = 503;
|
|
156
|
+
}
|
|
157
|
+
logger.error(debugMsg);
|
|
158
|
+
statusCode = 409;
|
|
159
|
+
}
|
|
160
|
+
// return response with error
|
|
161
|
+
return res.status(statusCode)
|
|
162
|
+
.send({
|
|
163
|
+
error: 'paghiper_notification_error',
|
|
164
|
+
message,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
await handleNotification();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return res.status(400).send('API key does not match');
|
|
172
|
+
} catch (err: any) {
|
|
173
|
+
logger.error(err);
|
|
174
|
+
return res.sendStatus(500);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './paghiper';
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AppModuleBody,
|
|
3
|
+
CreateTransactionParams,
|
|
4
|
+
CreateTransactionResponse,
|
|
5
|
+
} from '@cloudcommerce/types';
|
|
6
|
+
import type { PagHiperApp } from '../types/config-app';
|
|
7
|
+
import logger from 'firebase-functions/logger';
|
|
8
|
+
import config from '@cloudcommerce/firebase/lib/config';
|
|
9
|
+
import axios from './functions-lib/create-axios';
|
|
10
|
+
|
|
11
|
+
type ItemsPagHiper = {
|
|
12
|
+
description: string,
|
|
13
|
+
item_id: string,
|
|
14
|
+
quantity: number,
|
|
15
|
+
price_cents: number,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const responseError = (status: number | null, error: string, message: string) => {
|
|
19
|
+
return {
|
|
20
|
+
status: status || 409,
|
|
21
|
+
error,
|
|
22
|
+
message,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const createTransactionPagHiper = async (
|
|
27
|
+
body: { [x: string]: any },
|
|
28
|
+
isPix?: boolean,
|
|
29
|
+
): Promise<any> => {
|
|
30
|
+
// create new transaction to PagHiper API
|
|
31
|
+
// https://dev.paghiper.com/reference#gerar-boleto
|
|
32
|
+
if (!isPix && process.env.PAGHIPER_PARTNER_ID) {
|
|
33
|
+
body.partners_id = process.env.PAGHIPER_PARTNER_ID;
|
|
34
|
+
} else if (isPix && process.env.PAGHIPER_PIX_PARTNER_ID) {
|
|
35
|
+
body.partners_id = process.env.PAGHIPER_PIX_PARTNER_ID;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// returns request promise
|
|
39
|
+
const endpoint = `/${(isPix ? 'invoice' : 'transaction')}/create/`;
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
axios(isPix).post(endpoint, body)
|
|
42
|
+
.then(({ data }) => {
|
|
43
|
+
// save transaction ID on database first
|
|
44
|
+
let createRequest: any;
|
|
45
|
+
if (isPix) {
|
|
46
|
+
createRequest = data.pix_create_request;
|
|
47
|
+
}
|
|
48
|
+
if (!createRequest) {
|
|
49
|
+
createRequest = data.create_request;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
resolve(createRequest);
|
|
53
|
+
})
|
|
54
|
+
.catch(reject);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default async (appData: AppModuleBody) => {
|
|
59
|
+
const locationId = config.get().httpsFunctionOptions.region;
|
|
60
|
+
const baseUri = `https://${locationId}-${process.env.GCLOUD_PROJECT}.cloudfunctions.net`;
|
|
61
|
+
|
|
62
|
+
const webhookUrl = `${baseUri}/paghiper-webhook`;
|
|
63
|
+
|
|
64
|
+
// treat module request body
|
|
65
|
+
const { application } = appData;
|
|
66
|
+
const params = appData.params as CreateTransactionParams;
|
|
67
|
+
|
|
68
|
+
// app configured options
|
|
69
|
+
const configApp = {
|
|
70
|
+
...application.data,
|
|
71
|
+
...application.hidden_data,
|
|
72
|
+
} as PagHiperApp;
|
|
73
|
+
|
|
74
|
+
const orderId = params.order_id;
|
|
75
|
+
const orderNumber = params.order_number;
|
|
76
|
+
const {
|
|
77
|
+
amount,
|
|
78
|
+
items,
|
|
79
|
+
buyer,
|
|
80
|
+
to,
|
|
81
|
+
} = params;
|
|
82
|
+
|
|
83
|
+
const billingAddress = params.billing_address;
|
|
84
|
+
|
|
85
|
+
logger.log(`> (App PagHiper): Create transaction for #${orderId}`);
|
|
86
|
+
let transaction: CreateTransactionResponse['transaction'] = {
|
|
87
|
+
amount: amount.total,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// params object follows create transaction request schema:
|
|
91
|
+
// https://apx-mods.e-com.plus/api/v1/create_transaction/schema.json?store_id=100
|
|
92
|
+
// const orderId = params.order_id;
|
|
93
|
+
// logger.log(`> Create transaction for #${storeId} ${orderId}`);
|
|
94
|
+
// setup transaction body to PagHiper reference
|
|
95
|
+
|
|
96
|
+
// https://dev.paghiper.com/reference#gerar-boleto
|
|
97
|
+
const address = billingAddress || to;
|
|
98
|
+
|
|
99
|
+
const paghiperTransaction: { [x: string]: any } = {
|
|
100
|
+
order_id: orderId || orderNumber || new Date().getTime().toString(),
|
|
101
|
+
payer_email: buyer.email,
|
|
102
|
+
payer_name: buyer.fullname,
|
|
103
|
+
payer_cpf_cnpj: buyer.doc_number,
|
|
104
|
+
payer_phone: buyer.phone.number,
|
|
105
|
+
payer_street: address?.street || '',
|
|
106
|
+
payer_number: address?.number || '',
|
|
107
|
+
payer_complement: address?.complement || '',
|
|
108
|
+
payer_district: address?.borough || '',
|
|
109
|
+
payer_city: address?.city || '',
|
|
110
|
+
payer_state: address?.province_code || '',
|
|
111
|
+
payer_zip_code: address?.zip ? address.zip.replace(/\D/g, '') : '',
|
|
112
|
+
notification_url: webhookUrl,
|
|
113
|
+
discount_cents: amount.discount ? Math.round(amount.discount * 100) : '',
|
|
114
|
+
shipping_price_cents: amount.freight ? Math.round(amount.freight * 100) : '',
|
|
115
|
+
fixed_description: true,
|
|
116
|
+
type_bank_slip: 'boletoA4',
|
|
117
|
+
days_due_date: 5,
|
|
118
|
+
per_day_interest: true,
|
|
119
|
+
items: [] as ItemsPagHiper[],
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// parse transaction items list
|
|
123
|
+
items.forEach((item) => {
|
|
124
|
+
paghiperTransaction.items.push({
|
|
125
|
+
description: item.name || item.product_id,
|
|
126
|
+
item_id: item.sku || item.product_id,
|
|
127
|
+
quantity: item.quantity,
|
|
128
|
+
price_cents: Math.round((item.final_price || item.price) * 100),
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const isPix = params.payment_method.code === 'account_deposit';
|
|
133
|
+
if (isPix) {
|
|
134
|
+
paghiperTransaction.notification_url += '/pix';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// use configured PagHiper API key
|
|
138
|
+
paghiperTransaction.apiKey = configApp.paghiper_api_key;
|
|
139
|
+
// merge configured banking billet options
|
|
140
|
+
const options = configApp.banking_billet_options;
|
|
141
|
+
if (typeof options === 'object' && options !== null) {
|
|
142
|
+
// options must have only valid properties for PagHiper transaction object
|
|
143
|
+
Object.keys(options).forEach((prop) => {
|
|
144
|
+
if (options[prop]) {
|
|
145
|
+
paghiperTransaction[prop] = options[prop];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
// send request to PagHiper API
|
|
152
|
+
const createRequest = await createTransactionPagHiper(paghiperTransaction, isPix);
|
|
153
|
+
|
|
154
|
+
// transaction created successfully
|
|
155
|
+
// https://dev.paghiper.com/reference#exemplos
|
|
156
|
+
// mount response body
|
|
157
|
+
// https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
|
|
158
|
+
transaction = {
|
|
159
|
+
intermediator: {
|
|
160
|
+
transaction_id: createRequest.transaction_id,
|
|
161
|
+
transaction_code: createRequest.transaction_id,
|
|
162
|
+
transaction_reference: createRequest.order_id,
|
|
163
|
+
},
|
|
164
|
+
amount: createRequest.value_cents
|
|
165
|
+
? parseInt(createRequest.value_cents, 10) / 100
|
|
166
|
+
// use amount from create transaction request body
|
|
167
|
+
: params.amount.total,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (isPix) {
|
|
171
|
+
// https://dev.paghiper.com/reference#exemplos-pix
|
|
172
|
+
const pixCode = createRequest.pix_code;
|
|
173
|
+
if (transaction.intermediator) {
|
|
174
|
+
transaction.intermediator.transaction_code = pixCode.emv;
|
|
175
|
+
}
|
|
176
|
+
const pixCodeUrls = ['pix_url', 'qrcode_image_url', 'bacen_url'];
|
|
177
|
+
for (let i = 0; i < pixCodeUrls.length; i++) {
|
|
178
|
+
const pixUrl = pixCode[pixCodeUrls[i]];
|
|
179
|
+
if (pixUrl && pixUrl.startsWith('http')) {
|
|
180
|
+
transaction.payment_link = pixUrl;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
transaction.notes = `<img src="${pixCode.qrcode_image_url}" `
|
|
185
|
+
+ 'style="display:block;max-width:100%;margin:0 auto" />';
|
|
186
|
+
} else {
|
|
187
|
+
const bankSlip = createRequest.bank_slip;
|
|
188
|
+
transaction.payment_link = bankSlip.url_slip;
|
|
189
|
+
transaction.banking_billet = {
|
|
190
|
+
code: bankSlip.digitable_line,
|
|
191
|
+
link: bankSlip.url_slip_pdf,
|
|
192
|
+
};
|
|
193
|
+
if (createRequest.due_date) {
|
|
194
|
+
transaction.banking_billet.valid_thru = new Date(createRequest.due_date).toISOString();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
redirect_to_payment: false,
|
|
200
|
+
transaction,
|
|
201
|
+
};
|
|
202
|
+
} catch (err: any) {
|
|
203
|
+
let { message } = err;
|
|
204
|
+
let statusCode: number | null;
|
|
205
|
+
if (!err.request) {
|
|
206
|
+
// not Axios error ?
|
|
207
|
+
logger.error('> (App PagHiper) =>', err);
|
|
208
|
+
statusCode = 500;
|
|
209
|
+
} else {
|
|
210
|
+
let debugMsg = 'Can\'t create transaction: ';
|
|
211
|
+
if (err.config) {
|
|
212
|
+
debugMsg += `${err.config.url} `;
|
|
213
|
+
}
|
|
214
|
+
if (err.response) {
|
|
215
|
+
debugMsg += err.response.status;
|
|
216
|
+
|
|
217
|
+
// https://dev.paghiper.com/reference#mensagens-de-retorno-2
|
|
218
|
+
if (err.response.status === 200) {
|
|
219
|
+
const { data } = err.response;
|
|
220
|
+
if (data) {
|
|
221
|
+
debugMsg += ` ${typeof data === 'object' ? JSON.stringify(data) : data}`;
|
|
222
|
+
debugMsg += ` ${JSON.stringify(paghiperTransaction)}`;
|
|
223
|
+
if (data.create_request && data.create_request.response_message) {
|
|
224
|
+
message = data.create_request.response_message;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
debugMsg += message;
|
|
230
|
+
}
|
|
231
|
+
logger.error('> (App PagHiper) =>', debugMsg);
|
|
232
|
+
statusCode = 409;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// return error status code
|
|
236
|
+
return responseError(
|
|
237
|
+
statusCode,
|
|
238
|
+
'CREATE_TRANSACTION_ERR',
|
|
239
|
+
message,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
};
|