@cloudcommerce/app-galaxpay 0.1.0
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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +230 -0
- package/README.md +1 -0
- package/assets/onload-expression.js +23 -0
- package/events.js +1 -0
- package/lib/functions-lib/all-parses.d.ts +5 -0
- package/lib/functions-lib/all-parses.js +79 -0
- package/lib/functions-lib/all-parses.js.map +1 -0
- package/lib/functions-lib/ecom/events-to-galaxpay.d.ts +3 -0
- package/lib/functions-lib/ecom/events-to-galaxpay.js +75 -0
- package/lib/functions-lib/ecom/events-to-galaxpay.js.map +1 -0
- package/lib/functions-lib/galaxpay/auth/create-access.d.ts +11 -0
- package/lib/functions-lib/galaxpay/auth/create-access.js +60 -0
- package/lib/functions-lib/galaxpay/auth/create-access.js.map +1 -0
- package/lib/functions-lib/galaxpay/auth/create-axios.d.ts +2 -0
- package/lib/functions-lib/galaxpay/auth/create-axios.js +20 -0
- package/lib/functions-lib/galaxpay/auth/create-axios.js.map +1 -0
- package/lib/functions-lib/galaxpay/auth/gerate-token.d.ts +2 -0
- package/lib/functions-lib/galaxpay/auth/gerate-token.js +32 -0
- package/lib/functions-lib/galaxpay/auth/gerate-token.js.map +1 -0
- package/lib/functions-lib/galaxpay/handle-plans.d.ts +30 -0
- package/lib/functions-lib/galaxpay/handle-plans.js +73 -0
- package/lib/functions-lib/galaxpay/handle-plans.js.map +1 -0
- package/lib/functions-lib/galaxpay/update-subscription.d.ts +8 -0
- package/lib/functions-lib/galaxpay/update-subscription.js +56 -0
- package/lib/functions-lib/galaxpay/update-subscription.js.map +1 -0
- package/lib/functions-lib/galaxpay/webhook.d.ts +3 -0
- package/lib/functions-lib/galaxpay/webhook.js +291 -0
- package/lib/functions-lib/galaxpay/webhook.js.map +1 -0
- package/lib/functions-lib/utils.d.ts +8 -0
- package/lib/functions-lib/utils.js +17 -0
- package/lib/functions-lib/utils.js.map +1 -0
- package/lib/galaxpay-create-transaction.d.ts +71 -0
- package/lib/galaxpay-create-transaction.js +199 -0
- package/lib/galaxpay-create-transaction.js.map +1 -0
- package/lib/galaxpay-events.d.ts +6 -0
- package/lib/galaxpay-events.js +21 -0
- package/lib/galaxpay-events.js.map +1 -0
- package/lib/galaxpay-list-payments.d.ts +7 -0
- package/lib/galaxpay-list-payments.js +105 -0
- package/lib/galaxpay-list-payments.js.map +1 -0
- package/lib/galaxpay.d.ts +76 -0
- package/lib/galaxpay.js +12 -0
- package/lib/galaxpay.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/package.json +36 -0
- package/scripts/build.sh +5 -0
- package/src/functions-lib/all-parses.ts +91 -0
- package/src/functions-lib/ecom/events-to-galaxpay.ts +85 -0
- package/src/functions-lib/galaxpay/auth/create-access.ts +80 -0
- package/src/functions-lib/galaxpay/auth/create-axios.ts +21 -0
- package/src/functions-lib/galaxpay/auth/gerate-token.ts +36 -0
- package/src/functions-lib/galaxpay/handle-plans.ts +92 -0
- package/src/functions-lib/galaxpay/update-subscription.ts +73 -0
- package/src/functions-lib/galaxpay/webhook.ts +381 -0
- package/src/functions-lib/utils.ts +23 -0
- package/src/galaxpay-create-transaction.ts +240 -0
- package/src/galaxpay-events.ts +28 -0
- package/src/galaxpay-list-payments.ts +130 -0
- package/src/galaxpay.ts +12 -0
- package/src/index.ts +2 -0
- package/tsconfig.json +6 -0
- package/types/config-app.d.ts +99 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// type Gateway = ListPaymentsResponse['payment_gateways'][number]
|
|
2
|
+
const handleGateway = (appData) => {
|
|
3
|
+
const plans = [];
|
|
4
|
+
if (appData.plans) {
|
|
5
|
+
// Newer versions of the app will have a list of plans
|
|
6
|
+
appData.plans.forEach((plan) => {
|
|
7
|
+
plans.push(plan);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return plans;
|
|
11
|
+
};
|
|
12
|
+
// for create-transaction
|
|
13
|
+
const findPlanToCreateTransction = (label, appData) => {
|
|
14
|
+
let sendPlan;
|
|
15
|
+
if (appData.plans) {
|
|
16
|
+
/*
|
|
17
|
+
More recent versions of the application will have a list of plans,
|
|
18
|
+
where it will be necessary to find the plan by name,
|
|
19
|
+
and return it since it will be necessary to use the periodicity and quantity property
|
|
20
|
+
*/
|
|
21
|
+
// find plan by name (label)
|
|
22
|
+
appData.plans.forEach((plan) => {
|
|
23
|
+
// if the name of the plan is blank, on the list-payments side it is set to 'Plano'
|
|
24
|
+
let planLabel = plan.label || 'Plano';
|
|
25
|
+
planLabel = `${planLabel} ${plan.periodicity}`;
|
|
26
|
+
label = label?.trim();
|
|
27
|
+
if (label === planLabel) {
|
|
28
|
+
sendPlan = plan;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return sendPlan;
|
|
33
|
+
};
|
|
34
|
+
const discountPlan = (planDiscount, amount) => {
|
|
35
|
+
if (planDiscount && planDiscount.value > 0) {
|
|
36
|
+
// default discount option
|
|
37
|
+
const discountOption = {
|
|
38
|
+
value: planDiscount.value,
|
|
39
|
+
apply_at: (planDiscount.apply_at === 'frete' ? 'freight' : planDiscount),
|
|
40
|
+
type: planDiscount.percentage ? 'percentage' : 'fixed',
|
|
41
|
+
};
|
|
42
|
+
if (amount.total) {
|
|
43
|
+
// check amount value to apply discount
|
|
44
|
+
if (planDiscount.min_amount && amount.total < planDiscount.min_amount) {
|
|
45
|
+
planDiscount.value = 0;
|
|
46
|
+
} else {
|
|
47
|
+
delete planDiscount.min_amount;
|
|
48
|
+
const maxDiscount = amount[discountOption.apply_at || 'subtotal'];
|
|
49
|
+
let discountValue;
|
|
50
|
+
if (maxDiscount && discountOption.type === 'percentage') {
|
|
51
|
+
discountValue = (maxDiscount * planDiscount.value) / 100;
|
|
52
|
+
} else {
|
|
53
|
+
discountValue = planDiscount.value;
|
|
54
|
+
if (maxDiscount && discountValue > maxDiscount) {
|
|
55
|
+
discountValue = maxDiscount;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (discountValue && discountValue > 0) {
|
|
59
|
+
amount.discount = (amount.discount || 0) + discountValue;
|
|
60
|
+
amount.total -= discountValue;
|
|
61
|
+
if (amount.total < 0) {
|
|
62
|
+
amount.total = 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return discountOption;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { handleGateway, findPlanToCreateTransction, discountPlan };
|
|
73
|
+
// # sourceMappingURL=handle-plans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-plans.js","sourceRoot":"","sources":["../../../src/functions-lib/galaxpay/handle-plans.ts"],"names":[],"mappings":"AAIA,kEAAkE;AAElE,MAAM,aAAa,GAAG,CAAC,OAAoB,EAAE,EAAE;IAC7C,MAAM,KAAK,GAA6C,EAAE,CAAC;IAC3D,IAAI,OAAO,CAAC,KAAK,EAAE;QACjB,sDAAsD;QACtD,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC7B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,yBAAyB;AACzB,MAAM,0BAA0B,GAAG,CAAC,KAAyB,EAAE,OAAoB,EAAE,EAAE;IACrF,IAAI,QAAsE,CAAC;IAC3E,IAAI,OAAO,CAAC,KAAK,EAAE;QACjB;;;;UAIE;QAEF,4BAA4B;QAC5B,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC7B,mFAAmF;YACnF,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC;YACtC,SAAS,GAAG,GA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AAE;wBAC9C,aAAa,GAAG,WAAW,CAAC;qBAC7B;iBACF;gBAED,IAAI,aAAa,IAAI,aAAa,GAAG,CAAC,EAAE;oBACtC,MAAM,CAAC,QAAQ,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,aAAa,CAAC;oBACzD,MAAM,CAAC,KAAK,IAAI,aAAa,CAAC;oBAC9B,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE;wBACpB,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;qBAClB;iBACF;aACF;SACF;QACD,OAAO,cAAc,CAAC;KACvB;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,OAAO,EACL,aAAa,EACb,0BAA0B,EAC1B,YAAY,GACb,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Orders, Applications } from '@cloudcommerce/types';
|
|
2
|
+
declare const checkAmountItemsOrder: (amount: Orders['amount'], items: Exclude<Orders['items'], undefined>, plan: {
|
|
3
|
+
[x: string]: any;
|
|
4
|
+
}) => number;
|
|
5
|
+
declare const updateValueSubscription: (appData: Applications, subscriptionId: string, amount: Orders['amount'], items: Exclude<Orders['items'], undefined>, plan: {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
}) => Promise<unknown>;
|
|
8
|
+
export { updateValueSubscription, checkAmountItemsOrder, };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import GalaxpayAxios from './auth/create-access.js';
|
|
2
|
+
|
|
3
|
+
const checkAmountItemsOrder = (amount, items, plan) => {
|
|
4
|
+
let subtotal = 0;
|
|
5
|
+
let item;
|
|
6
|
+
for (let i = 0; i < items.length; i++) {
|
|
7
|
+
item = items[i];
|
|
8
|
+
if (item.flags && (item.flags.includes('freebie') || item.flags.includes('discount-set-free'))) {
|
|
9
|
+
items.splice(i, 1);
|
|
10
|
+
} else {
|
|
11
|
+
subtotal += item.quantity * (item.final_price || item.price);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
amount.subtotal = subtotal;
|
|
15
|
+
amount.total = amount.subtotal + (amount.tax || 0) + (amount.freight || 0) + (amount.extra || 0);
|
|
16
|
+
let planDiscount;
|
|
17
|
+
if (plan && plan.discount) {
|
|
18
|
+
if (plan.discount.percentage) {
|
|
19
|
+
planDiscount = amount[plan.discount.apply_at];
|
|
20
|
+
planDiscount *= ((plan.discount.value) / 100);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// if the plan doesn't exist, because it's subscription before the update
|
|
24
|
+
if (plan) {
|
|
25
|
+
amount.discount = (plan.discount && !plan.discount.percentage
|
|
26
|
+
? plan.discount.value : planDiscount) || 0;
|
|
27
|
+
}
|
|
28
|
+
if (amount.discount) {
|
|
29
|
+
amount.total -= amount.discount;
|
|
30
|
+
}
|
|
31
|
+
const total = amount.total - (amount.discount || 0); // BUG :(
|
|
32
|
+
return Math.floor(total.toFixed(2) * 100);
|
|
33
|
+
};
|
|
34
|
+
const updateValueSubscription = (appData, subscriptionId, amount, items, plan) => {
|
|
35
|
+
const value = checkAmountItemsOrder({ ...amount }, [...items], { ...plan });
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const galaxpayAxios = new GalaxpayAxios({
|
|
38
|
+
galaxpayId: appData.hidden_data?.galaxpay_id,
|
|
39
|
+
galaxpayHash: appData.hidden_data?.galaxpay_hash,
|
|
40
|
+
});
|
|
41
|
+
galaxpayAxios.preparing
|
|
42
|
+
.then(async () => {
|
|
43
|
+
if (galaxpayAxios.axios) {
|
|
44
|
+
const { data } = await galaxpayAxios.axios.put(`subscriptions/${subscriptionId}/myId`, { value });
|
|
45
|
+
if (data.type) {
|
|
46
|
+
resolve(true);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}).catch((err) => {
|
|
50
|
+
reject(err);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { updateValueSubscription, checkAmountItemsOrder };
|
|
56
|
+
// # sourceMappingURL=update-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-subscription.js","sourceRoot":"","sources":["../../../src/functions-lib/galaxpay/update-subscription.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD,MAAM,qBAAqB,GAAG,CAC5B,MAAwB,EACxB,KAA0C,EAC1C,IAA0B,EAC1B,EAAE;IACF,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,IAAiD,CAAC;IACtD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAChB,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC,EAAE;YAC9F,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACpB;aAAM;YACL,QAAQ,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;SAC9D;KACF;IACD,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;IACjG,IAAI,YAAY,CAAC;IACjB,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;YAC5B,YAAY,GAAG,MAAM,CAAC,IAAI,C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;YACf,IAAI,aAAa,CAAC,KAAK,EAAE;gBACvB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,cAAc,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;gBAClG,IAAI,IAAI,CAAC,IAAI,EAAE;oBACb,OAAO,CAAC,IAAI,CAAC,CAAC;iBACf;aACF;QACH,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACf,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,OAAO,EACL,uBAAuB,EACvB,qBAAqB,GACtB,CAAC"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import api from '@cloudcommerce/api';
|
|
2
|
+
import { getFirestore } from 'firebase-admin/firestore';
|
|
3
|
+
import logger from 'firebase-functions/logger';
|
|
4
|
+
import { parseStatus, parsePeriodicityToEcom, gerateId } from '../all-parses.js';
|
|
5
|
+
import { updateValueSubscription, checkAmountItemsOrder } from './update-subscription.js';
|
|
6
|
+
|
|
7
|
+
const collectionSubscription = getFirestore().collection('subscriptions');
|
|
8
|
+
const getApp = async () => {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
api.get('applications?app_id=123188&fields=hidden_data')
|
|
11
|
+
.then(({ data: result }) => {
|
|
12
|
+
resolve(result[0]);
|
|
13
|
+
})
|
|
14
|
+
.catch((err) => {
|
|
15
|
+
reject(err);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const checkStatus = (financialStatus, GalaxPayTransaction) => {
|
|
20
|
+
if (financialStatus.current === parseStatus(GalaxPayTransaction.status)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if ((financialStatus.current === 'paid' || financialStatus.current === 'authorized')
|
|
24
|
+
&& parseStatus(GalaxPayTransaction.status) !== 'refunded') {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
const checkStatusNotValid = (status) => {
|
|
30
|
+
const parsedStatus = parseStatus(status);
|
|
31
|
+
// logger.log('>> Status (', status, ')=> ', parsedStatus);
|
|
32
|
+
if (parsedStatus === 'unauthorized' || parsedStatus === 'refunded' || parsedStatus === 'voided') {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
const checkPayDay = (strDate) => {
|
|
38
|
+
// check if today is 3 days before payday.
|
|
39
|
+
const payDay = new Date(strDate);
|
|
40
|
+
const nowTime = new Date().getTime() + 259200000; // add 3day to today
|
|
41
|
+
const now = new Date(nowTime);
|
|
42
|
+
return (now >= payDay);
|
|
43
|
+
};
|
|
44
|
+
const findOrderByTransactionId = (transactionId) => {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
api.get(`orders?transactions._id=${transactionId}`)
|
|
47
|
+
.then(({ data: response }) => {
|
|
48
|
+
const resp = response; // TODO:
|
|
49
|
+
resolve(resp);
|
|
50
|
+
})
|
|
51
|
+
.catch((err) => {
|
|
52
|
+
reject(err);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const findOrderById = async (orderId) => new Promise((resolve) => {
|
|
57
|
+
api.get(`orders/${orderId}?fields=transactions,financial_status`).then(({ data: order }) => {
|
|
58
|
+
resolve(order);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
const createTransaction = async (res, subscriptionLabel, plan, orderNumber, galaxpayFristTransactionId, GalaxPayTransaction, GalaxPaySubscription, GalaxPayTransactionValue, originalOrderId) => {
|
|
62
|
+
if (galaxpayFristTransactionId !== GalaxPayTransaction.galaxPayId) {
|
|
63
|
+
// let body;
|
|
64
|
+
const originalOrder = (await api.get(`orders/${originalOrderId}`)).data;
|
|
65
|
+
// logger.log('> Create new Order ')
|
|
66
|
+
if (originalOrder.transactions && originalOrder.items) {
|
|
67
|
+
const { installment } = GalaxPayTransaction;
|
|
68
|
+
const {
|
|
69
|
+
buyers, items, domain, amount,
|
|
70
|
+
} = originalOrder;
|
|
71
|
+
const channelType = originalOrder.channel_type;
|
|
72
|
+
const shippingLines = originalOrder.shipping_lines;
|
|
73
|
+
const shippingMethodLabel = originalOrder.shipping_method_label;
|
|
74
|
+
const paymentMethodLabel = originalOrder.payment_method_label;
|
|
75
|
+
const originalTransaction = originalOrder.transactions[0];
|
|
76
|
+
const quantity = installment;
|
|
77
|
+
const periodicity = parsePeriodicityToEcom(GalaxPaySubscription.periodicity);
|
|
78
|
+
const dateUpdate = GalaxPayTransaction.datetimeLastSentToOperator
|
|
79
|
+
? new Date(GalaxPayTransaction.datetimeLastSentToOperator).toISOString()
|
|
80
|
+
: new Date().toISOString();
|
|
81
|
+
// remove items free in new orders subscription
|
|
82
|
+
checkAmountItemsOrder(amount, items, plan);
|
|
83
|
+
if (amount.balance) {
|
|
84
|
+
delete amount.balance;
|
|
85
|
+
}
|
|
86
|
+
const transactionId = String(gerateId(GalaxPayTransaction.galaxPayId));
|
|
87
|
+
const transactions = [
|
|
88
|
+
{
|
|
89
|
+
amount: originalTransaction.amount,
|
|
90
|
+
status: {
|
|
91
|
+
updated_at: dateUpdate,
|
|
92
|
+
current: parseStatus(GalaxPayTransaction.status),
|
|
93
|
+
},
|
|
94
|
+
intermediator: {
|
|
95
|
+
transaction_id: GalaxPayTransaction.tid || '',
|
|
96
|
+
transaction_code: GalaxPayTransaction.authorizationCode || '',
|
|
97
|
+
},
|
|
98
|
+
payment_method: originalTransaction.payment_method,
|
|
99
|
+
app: originalTransaction.app,
|
|
100
|
+
_id: transactionId,
|
|
101
|
+
notes: `Parcela #${quantity} referente à ${subscriptionLabel} ${periodicity}`,
|
|
102
|
+
custom_fields: originalTransaction.custom_fields,
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
transactions[0].payment_link = GalaxPaySubscription.paymentLink;
|
|
106
|
+
const financialStatus = {
|
|
107
|
+
updated_at: dateUpdate,
|
|
108
|
+
current: parseStatus(GalaxPayTransaction.status),
|
|
109
|
+
};
|
|
110
|
+
const body = {
|
|
111
|
+
opened_at: new Date().toISOString(),
|
|
112
|
+
items,
|
|
113
|
+
shipping_lines: shippingLines,
|
|
114
|
+
buyers,
|
|
115
|
+
channel_type: channelType,
|
|
116
|
+
domain,
|
|
117
|
+
amount,
|
|
118
|
+
shipping_method_label: shippingMethodLabel,
|
|
119
|
+
payment_method_label: paymentMethodLabel,
|
|
120
|
+
transactions,
|
|
121
|
+
financial_status: financialStatus,
|
|
122
|
+
subscription_order: {
|
|
123
|
+
_id: originalOrderId,
|
|
124
|
+
number: parseInt(orderNumber, 10),
|
|
125
|
+
},
|
|
126
|
+
notes: `Pedido #${quantity} referente à ${subscriptionLabel} ${periodicity}`,
|
|
127
|
+
staff_notes: `Valor cobrado no GalaxPay R$${GalaxPayTransactionValue}`,
|
|
128
|
+
};
|
|
129
|
+
const { result } = await findOrderByTransactionId(transactionId);
|
|
130
|
+
if (!result.length) {
|
|
131
|
+
await api.post('orders', body);
|
|
132
|
+
// logger.log('> Created new order API')
|
|
133
|
+
return res.sendStatus(200);
|
|
134
|
+
}
|
|
135
|
+
// Order Exists
|
|
136
|
+
return res.sendStatus(200);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// logger.log('> Not Found Subscritpion or Transaction exists')
|
|
140
|
+
return res.sendStatus(404);
|
|
141
|
+
};
|
|
142
|
+
const handleWehook = async (req, res) => {
|
|
143
|
+
// https://docs.galaxpay.com.br/webhooks
|
|
144
|
+
// POST transaction.updateStatus update Transation status
|
|
145
|
+
// POST subscription.addTransaction add transation in subscription
|
|
146
|
+
const galaxpayHook = req.body;
|
|
147
|
+
const type = galaxpayHook.event;
|
|
148
|
+
const GalaxPaySubscription = galaxpayHook.Subscription;
|
|
149
|
+
const GalaxPaySubscriptionQuantity = GalaxPaySubscription.quantity;
|
|
150
|
+
const originalOrderId = GalaxPaySubscription.myId;
|
|
151
|
+
const GalaxPayTransaction = galaxpayHook.Transaction;
|
|
152
|
+
const GalaxPayTransactionValue = GalaxPayTransaction.value / 100;
|
|
153
|
+
logger.log(`> (App GalaxPay) WebHook ${type}, Body ${JSON.stringify(galaxpayHook)}, quantity:
|
|
154
|
+
${GalaxPaySubscriptionQuantity}, status: ${GalaxPayTransaction.status} <`);
|
|
155
|
+
// if (galaxpayHook.confirmHash) {
|
|
156
|
+
// logger.log('> ', galaxpayHook.confirmHash);
|
|
157
|
+
// }
|
|
158
|
+
try {
|
|
159
|
+
if (type === 'transaction.updateStatus') {
|
|
160
|
+
const documentSnapshot = await collectionSubscription.doc(originalOrderId).get();
|
|
161
|
+
if (documentSnapshot && documentSnapshot.exists) {
|
|
162
|
+
const docSubscription = documentSnapshot.data();
|
|
163
|
+
if (docSubscription) {
|
|
164
|
+
const {
|
|
165
|
+
galaxpayFristTransactionId, plan, orderNumber, subscriptionLabel,
|
|
166
|
+
} = docSubscription.data();
|
|
167
|
+
if (galaxpayFristTransactionId === GalaxPayTransaction.galaxPayId) {
|
|
168
|
+
// update frist payment
|
|
169
|
+
const order = await findOrderById(originalOrderId);
|
|
170
|
+
// Update value Subscription in GalaxPay
|
|
171
|
+
// logger.log('plan-> ', JSON.stringify(plan));
|
|
172
|
+
// not update subscripton canceled
|
|
173
|
+
if (!checkStatusNotValid(GalaxPayTransaction.status) && order.items) {
|
|
174
|
+
const app = await getApp();
|
|
175
|
+
await updateValueSubscription(app, originalOrderId, order.amount, order.items, plan);
|
|
176
|
+
}
|
|
177
|
+
// logger.log('ORDER: ', JSON.stringify(order.amount), ' **');
|
|
178
|
+
// logger.log('> order ', order)
|
|
179
|
+
if (order.financial_status
|
|
180
|
+
&& checkStatus(order.financial_status, GalaxPayTransaction)) {
|
|
181
|
+
return res.sendStatus(200);
|
|
182
|
+
}
|
|
183
|
+
if (order.transactions) {
|
|
184
|
+
// update payment
|
|
185
|
+
const transactionId = order.transactions[0]._id;
|
|
186
|
+
const bodyPaymentHistory = {
|
|
187
|
+
date_time: new Date().toISOString(),
|
|
188
|
+
status: parseStatus(GalaxPayTransaction.status),
|
|
189
|
+
transaction_id: transactionId,
|
|
190
|
+
notification_code: `${type};${galaxpayHook.webhookId}`,
|
|
191
|
+
flags: ['GalaxPay'],
|
|
192
|
+
}; // TODO: incompatible type=> amount and status;;
|
|
193
|
+
await api.post(`orders/${order._id}/payments_history`, bodyPaymentHistory);
|
|
194
|
+
await api.patch(`orders/${order._id}/transactions/${transactionId}`, {
|
|
195
|
+
intermediator: {
|
|
196
|
+
transaction_id: GalaxPayTransaction.tid || '',
|
|
197
|
+
transaction_code: GalaxPayTransaction.authorizationCode || '',
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
return res.sendStatus(200);
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
/*
|
|
204
|
+
add order, because recurrence creates all transactions in the
|
|
205
|
+
first transaction when quantity is non-zero,search for the order by ID,
|
|
206
|
+
if not found, create the transaction, and if found, check if it will be
|
|
207
|
+
necessary to update the transaction status
|
|
208
|
+
*/
|
|
209
|
+
const transactionId = String(gerateId(GalaxPayTransaction.galaxPayId));
|
|
210
|
+
const { result } = await findOrderByTransactionId(transactionId);
|
|
211
|
+
if (!result || !result.length) {
|
|
212
|
+
// logger.log('> Not found Transaction in API')
|
|
213
|
+
if (!checkStatusNotValid(GalaxPayTransaction.status)
|
|
214
|
+
&& checkPayDay(GalaxPayTransaction.payday)) {
|
|
215
|
+
// necessary to create order
|
|
216
|
+
return createTransaction(res, subscriptionLabel, plan, orderNumber, galaxpayFristTransactionId, GalaxPayTransaction, GalaxPaySubscription, GalaxPayTransactionValue, originalOrderId);
|
|
217
|
+
}
|
|
218
|
+
// TODO: status 400 or 500?
|
|
219
|
+
return res.status(404).send('Status or checkPayDay invalid');
|
|
220
|
+
}
|
|
221
|
+
const order = result[0];
|
|
222
|
+
if (order.financial_status
|
|
223
|
+
&& checkStatus(order.financial_status, GalaxPayTransaction)) {
|
|
224
|
+
// logger.log('> Equals Status')
|
|
225
|
+
return res.sendStatus(200);
|
|
226
|
+
}
|
|
227
|
+
// logger.log('> Order id ')
|
|
228
|
+
// update payment
|
|
229
|
+
const bodyPaymentHistory = {
|
|
230
|
+
date_time: new Date().toISOString(),
|
|
231
|
+
status: parseStatus(GalaxPayTransaction.status),
|
|
232
|
+
transaction_id: transactionId,
|
|
233
|
+
notification_code: `${type};${galaxpayHook.webhookId}`,
|
|
234
|
+
flags: ['GalaxPay'],
|
|
235
|
+
}; // TODO: incompatible type=> amount and status;
|
|
236
|
+
await api.post(`orders/${order._id}/payments_history`, bodyPaymentHistory);
|
|
237
|
+
// logger.log('> create Payment History')
|
|
238
|
+
await api.patch(`orders/${order._id}/transactions/${transactionId}`, {
|
|
239
|
+
intermediator: {
|
|
240
|
+
transaction_id: GalaxPayTransaction.tid || '',
|
|
241
|
+
transaction_code: GalaxPayTransaction.authorizationCode || '',
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
if (parseStatus(GalaxPayTransaction.status) === 'voided'
|
|
245
|
+
|| parseStatus(GalaxPayTransaction.status) === 'refunded') {
|
|
246
|
+
await api.patch(`orders/${order._id}`, { status: 'cancelled' });
|
|
247
|
+
// logger.log('> UPDATE ORDER OK')
|
|
248
|
+
return res.sendStatus(200);
|
|
249
|
+
}
|
|
250
|
+
// logger.log('> UPDATE Transaction OK')
|
|
251
|
+
return res.sendStatus(200);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
//
|
|
256
|
+
return res.status(404).send('Document not found in firestore');
|
|
257
|
+
}
|
|
258
|
+
if (type === 'subscription.addTransaction') {
|
|
259
|
+
if (GalaxPaySubscriptionQuantity === 0) {
|
|
260
|
+
// find transaction in firebase
|
|
261
|
+
const documentSnapshot = await collectionSubscription.doc(originalOrderId).get();
|
|
262
|
+
if (documentSnapshot && documentSnapshot.exists) {
|
|
263
|
+
const docSubscription = documentSnapshot.data();
|
|
264
|
+
if (docSubscription) {
|
|
265
|
+
const {
|
|
266
|
+
galaxpayFristTransactionId, plan, orderNumber, subscriptionLabel,
|
|
267
|
+
} = docSubscription.data();
|
|
268
|
+
if (checkPayDay(GalaxPayTransaction.payday)) {
|
|
269
|
+
return createTransaction(res, subscriptionLabel, plan, orderNumber, galaxpayFristTransactionId, GalaxPayTransaction, GalaxPaySubscription, GalaxPayTransactionValue, originalOrderId);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
//
|
|
274
|
+
return res.status(404).send('Document not found in firestore');
|
|
275
|
+
}
|
|
276
|
+
// Avoid retries of this GalaxPay webhook
|
|
277
|
+
return res.status(200)
|
|
278
|
+
.send(`Subscription webhook with non-zero quantity.
|
|
279
|
+
The Order will be analyzed with the updateStatus webhook.`);
|
|
280
|
+
}
|
|
281
|
+
//
|
|
282
|
+
return res.status(404).send('Unidentified webhook type');
|
|
283
|
+
} catch (err) {
|
|
284
|
+
// verificar catch
|
|
285
|
+
logger.error(err);
|
|
286
|
+
return res.sendStatus(500);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export default handleWehook;
|
|
291
|
+
// # sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../../src/functions-lib/galaxpay/webhook.ts"],"names":[],"mappings":"AAMA,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAIvF,MAAM,sBAAsB,GAAG,YAAY,EAAE,CAAC,UAAU,CAAC,eAAe,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AC5B;AACH,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const readFile: (path: string) => string;
|
|
2
|
+
declare const responseError: (status: number | null, error: string, message: string) => {
|
|
3
|
+
status: number;
|
|
4
|
+
error: string;
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
declare const isSandbox = false;
|
|
8
|
+
export { readFile, responseError, isSandbox, };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import url from 'url';
|
|
3
|
+
import { join as joinPath } from 'path';
|
|
4
|
+
|
|
5
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
6
|
+
const readFile = (path) => fs.readFileSync(joinPath(__dirname, path), 'utf8');
|
|
7
|
+
const responseError = (status, error, message) => {
|
|
8
|
+
return {
|
|
9
|
+
status: status || 409,
|
|
10
|
+
error,
|
|
11
|
+
message,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const isSandbox = false; // TODO: false
|
|
15
|
+
|
|
16
|
+
export { readFile, responseError, isSandbox };
|
|
17
|
+
// # sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/functions-lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAC;AAExC,MAAM,SAAS,GAAG,GAAG,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEnE,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;AAEtF,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,SAAS,GAAG,KAAK,CAAC,CAAC,cAAc;AAEvC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,SAAS,GACV,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: "pending" | "authorized" | "paid" | "unauthorized" | "refunded" | "voided" | "unknown" | "under_analysis" | "in_dispute";
|
|
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;
|