@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,199 @@
|
|
|
1
|
+
import logger from 'firebase-functions/logger';
|
|
2
|
+
import { getFirestore } from 'firebase-admin/firestore';
|
|
3
|
+
import Galaxpay from './functions-lib/galaxpay/auth/create-access.js';
|
|
4
|
+
import { responseError, isSandbox } from './functions-lib/utils.js';
|
|
5
|
+
import { findPlanToCreateTransction } from './functions-lib/galaxpay/handle-plans.js';
|
|
6
|
+
import { parseStatus, parsePeriodicityToGalaxPay } from './functions-lib/all-parses.js';
|
|
7
|
+
|
|
8
|
+
const firestoreColl = 'galaxpaySubscriptions';
|
|
9
|
+
const parseAddress = (to) => ({
|
|
10
|
+
zipCode: to.zip,
|
|
11
|
+
street: to.street,
|
|
12
|
+
number: String(to.number) || 's/n',
|
|
13
|
+
complementary: to.complement || undefined,
|
|
14
|
+
neighborhood: to.borough,
|
|
15
|
+
city: to.city,
|
|
16
|
+
state: to.province || to.province_code,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default async (appData) => {
|
|
20
|
+
// treat module request body
|
|
21
|
+
const { application } = appData;
|
|
22
|
+
const { params } = appData;
|
|
23
|
+
// app configured options
|
|
24
|
+
const configApp = {
|
|
25
|
+
...application.data,
|
|
26
|
+
...application.hidden_data,
|
|
27
|
+
};
|
|
28
|
+
const orderId = params.order_id;
|
|
29
|
+
const orderNumber = params.order_number;
|
|
30
|
+
const {
|
|
31
|
+
amount,
|
|
32
|
+
// items,
|
|
33
|
+
buyer, to, type,
|
|
34
|
+
} = params;
|
|
35
|
+
logger.log('>(App:GalaxPay) Transaction #order:', orderId, ` ${isSandbox ? ' Sandbox' : ''} <`);
|
|
36
|
+
const transaction = {
|
|
37
|
+
// type,
|
|
38
|
+
amount: amount.total,
|
|
39
|
+
};
|
|
40
|
+
// setup required `transaction` response object
|
|
41
|
+
const galaxpayAxios = new Galaxpay({
|
|
42
|
+
galaxpayId: configApp.galaxpay_id,
|
|
43
|
+
galaxpayHash: configApp.galaxpay_hash,
|
|
44
|
+
});
|
|
45
|
+
// indicates whether the buyer should be redirected to payment link right after checkout
|
|
46
|
+
let redirectToPayment = false;
|
|
47
|
+
switch (params.payment_method.code) {
|
|
48
|
+
case 'online_debit':
|
|
49
|
+
redirectToPayment = true;
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
// https://docs.galaxpay.com.br/subscriptions/create-without-plan
|
|
55
|
+
const extraFields = [
|
|
56
|
+
{
|
|
57
|
+
tagName: 'order_number',
|
|
58
|
+
tagValue: `${orderNumber}`,
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
const galaxpayCustomer = {
|
|
62
|
+
myId: buyer.customer_id,
|
|
63
|
+
name: buyer.fullname,
|
|
64
|
+
document: buyer.doc_number,
|
|
65
|
+
emails: [buyer.email],
|
|
66
|
+
phones: [parseInt(`${buyer.phone.number}`, 10)],
|
|
67
|
+
};
|
|
68
|
+
let methodConfigName = params.payment_method.code === 'credit_card' ? configApp.credit_card?.label
|
|
69
|
+
: 'Cartão de crédito';
|
|
70
|
+
methodConfigName = (params.payment_method.code === 'account_deposit'
|
|
71
|
+
? (configApp.pix?.label || 'Pix') : (configApp.banking_billet?.label || 'Boleto bancário'));
|
|
72
|
+
// handle plan label to find plan by name (label)
|
|
73
|
+
let labelPaymentGateway = params.payment_method.name?.replace('- GalaxPay', '');
|
|
74
|
+
labelPaymentGateway = labelPaymentGateway?.replace(methodConfigName, '');
|
|
75
|
+
let plan = findPlanToCreateTransction(labelPaymentGateway, configApp);
|
|
76
|
+
if (!plan && configApp.plans) {
|
|
77
|
+
[plan] = configApp.plans;
|
|
78
|
+
}
|
|
79
|
+
const finalAmount = amount.total;
|
|
80
|
+
const fristPayment = new Date();
|
|
81
|
+
const quantity = plan?.quantity || 0;
|
|
82
|
+
const galaxpaySubscriptions = {
|
|
83
|
+
myId: `${orderId}`,
|
|
84
|
+
value: Math.floor(finalAmount * 100),
|
|
85
|
+
quantity,
|
|
86
|
+
periodicity: parsePeriodicityToGalaxPay(plan?.periodicity) || 'monthly',
|
|
87
|
+
Customer: galaxpayCustomer,
|
|
88
|
+
ExtraFields: extraFields,
|
|
89
|
+
mainPaymentMethodId: 'creditcard',
|
|
90
|
+
firstPayDayDate: fristPayment.toISOString().split('T')[0],
|
|
91
|
+
};
|
|
92
|
+
if (params.payment_method.code === 'credit_card') {
|
|
93
|
+
const card = {
|
|
94
|
+
hash: params.credit_card?.hash,
|
|
95
|
+
};
|
|
96
|
+
const PaymentMethodCreditCard = {
|
|
97
|
+
Card: card,
|
|
98
|
+
preAuthorize: false,
|
|
99
|
+
};
|
|
100
|
+
galaxpaySubscriptions.PaymentMethodCreditCard = PaymentMethodCreditCard;
|
|
101
|
+
} else if (params.payment_method.code === 'banking_billet') {
|
|
102
|
+
if (to) {
|
|
103
|
+
Object.assign(galaxpayCustomer, { Address: parseAddress(to) });
|
|
104
|
+
} else if (params.billing_address) {
|
|
105
|
+
Object.assign(galaxpayCustomer, { Address: parseAddress(params.billing_address) });
|
|
106
|
+
}
|
|
107
|
+
fristPayment.setDate(fristPayment.getDate() + (configApp.banking_billet?.add_days || 0));
|
|
108
|
+
galaxpaySubscriptions.mainPaymentMethodId = 'boleto';
|
|
109
|
+
galaxpaySubscriptions.Customer = galaxpayCustomer;
|
|
110
|
+
[galaxpaySubscriptions.firstPayDayDate] = fristPayment.toISOString().split('T');
|
|
111
|
+
} else if (params.payment_method.code === 'account_deposit') {
|
|
112
|
+
// other is PIX
|
|
113
|
+
if (to) {
|
|
114
|
+
Object.assign(galaxpayCustomer, { Address: parseAddress(to) });
|
|
115
|
+
} else if (params.billing_address) {
|
|
116
|
+
Object.assign(galaxpayCustomer, { Address: parseAddress(params.billing_address) });
|
|
117
|
+
}
|
|
118
|
+
const PaymentMethodPix = {
|
|
119
|
+
instructions: configApp.pix?.instructions || 'Pix',
|
|
120
|
+
};
|
|
121
|
+
fristPayment.setDate(fristPayment.getDate() + (configApp.pix?.add_days || 0));
|
|
122
|
+
galaxpaySubscriptions.mainPaymentMethodId = 'pix';
|
|
123
|
+
galaxpaySubscriptions.Customer = galaxpayCustomer;
|
|
124
|
+
[galaxpaySubscriptions.firstPayDayDate] = fristPayment.toISOString().split('T');
|
|
125
|
+
galaxpaySubscriptions.PaymentMethodPix = PaymentMethodPix;
|
|
126
|
+
}
|
|
127
|
+
logger.log('>>(App:GalaxPay): subscriptions ', JSON.stringify(galaxpaySubscriptions), ' <<');
|
|
128
|
+
try {
|
|
129
|
+
await galaxpayAxios.preparing;
|
|
130
|
+
} catch (err) {
|
|
131
|
+
logger.error('>(App: GalaxPay) Error =>', err);
|
|
132
|
+
return responseError(409, 'NO_GALAXPAY_AUTH', 'Error getting authentication');
|
|
133
|
+
}
|
|
134
|
+
const { axios } = galaxpayAxios;
|
|
135
|
+
if (axios) {
|
|
136
|
+
try {
|
|
137
|
+
if (type === 'recurrence') {
|
|
138
|
+
const { data: { Subscription } } = await axios.post('/subscriptions', galaxpaySubscriptions);
|
|
139
|
+
logger.log('>(App: GalaxPay) New Subscription ', Subscription, ' <');
|
|
140
|
+
transaction.payment_link = Subscription.paymentLink;
|
|
141
|
+
const transactionGalaxPay = Subscription.Transactions[0];
|
|
142
|
+
transaction.status = {
|
|
143
|
+
updated_at: Subscription.datetimeLastSentToOperator || new Date().toISOString(),
|
|
144
|
+
current: parseStatus(transactionGalaxPay.status),
|
|
145
|
+
};
|
|
146
|
+
transaction.intermediator = {
|
|
147
|
+
transaction_id: transactionGalaxPay.tid,
|
|
148
|
+
transaction_code: transactionGalaxPay.authorizationCode,
|
|
149
|
+
};
|
|
150
|
+
const documentRef = getFirestore().doc(`${firestoreColl}/${orderId}`);
|
|
151
|
+
if (documentRef) {
|
|
152
|
+
documentRef.set({
|
|
153
|
+
subscriptionLabel: plan?.label ? plan.label : 'Plano',
|
|
154
|
+
status: 'open',
|
|
155
|
+
orderNumber: params.order_number,
|
|
156
|
+
galaxpayFristTransactionId: transactionGalaxPay.galaxPayId,
|
|
157
|
+
quantity,
|
|
158
|
+
create_at: new Date().toISOString(),
|
|
159
|
+
plan,
|
|
160
|
+
})
|
|
161
|
+
.catch(logger.error);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
redirect_to_payment: redirectToPayment,
|
|
165
|
+
transaction,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return responseError(409, 'GALAXPAY_TYPE_ERR_', 'Invalid transaction type');
|
|
169
|
+
} catch (error) {
|
|
170
|
+
// logger.log(error.response);
|
|
171
|
+
// try to debug request error
|
|
172
|
+
let { message } = error;
|
|
173
|
+
const err = {
|
|
174
|
+
message: `GALAXPAY_TRANSACTION_ERR Order: #${orderId} => ${message}`,
|
|
175
|
+
payment: '',
|
|
176
|
+
status: 0,
|
|
177
|
+
response: '',
|
|
178
|
+
};
|
|
179
|
+
if (error.response) {
|
|
180
|
+
const { status, data } = error.response;
|
|
181
|
+
if (status !== 401 && status !== 403) {
|
|
182
|
+
err.payment = JSON.stringify(transaction);
|
|
183
|
+
err.status = status;
|
|
184
|
+
if (typeof data === 'object' && data) {
|
|
185
|
+
err.response = JSON.stringify(data);
|
|
186
|
+
} else {
|
|
187
|
+
err.response = data;
|
|
188
|
+
}
|
|
189
|
+
} else if (data && Array.isArray(data.errors) && data.errors[0] && data.errors[0].message) {
|
|
190
|
+
message = data.errors[0].message;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
logger.error(err);
|
|
194
|
+
return responseError(409, 'GALAXPAY_TRANSACTION_ERR', message);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return responseError(409, 'GALAXPAY_REQUEST_ERR_', 'Unexpected error creating charge');
|
|
198
|
+
};
|
|
199
|
+
// # sourceMappingURL=galaxpay-create-transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"galaxpay-create-transaction.js","sourceRoot":"","sources":["../src/galaxpay-create-transaction.ts"],"names":[],"mappings":"AAMA,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,QAAQ,MAAM,6CAA6C,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAI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CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;qBACrC;yBAAM;wBACL,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;qBACrB;iBACF;qBAAM,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE;oBACzF,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;iBAClC;aACF;YACD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,aAAa,CAAC,GAAG,EAAE,0BAA0B,EAAE,OAAO,CAAC,CAAC;SAChE;KACF;IACD,OAAO,aAAa,CAAC,GAAG,EAAE,uBAAuB,EAAE,kCAAkC,CAAC,CAAC;AACzF,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { createAppEventsFunction } from '@cloudcommerce/firebase/lib/helpers/pubsub';
|
|
6
|
+
import handleApiEvent from './functions-lib/ecom/events-to-galaxpay.js';
|
|
7
|
+
import handleGalaxpayWebhook from './functions-lib/galaxpay/webhook.js';
|
|
8
|
+
|
|
9
|
+
export const galaxpay = {
|
|
10
|
+
onStoreEvent: createAppEventsFunction('galaxPay', handleApiEvent),
|
|
11
|
+
webhook: functions
|
|
12
|
+
.region(config.get().httpsFunctionOptions.region)
|
|
13
|
+
.https.onRequest((req, res) => {
|
|
14
|
+
if (req.method !== 'POST') {
|
|
15
|
+
res.sendStatus(405);
|
|
16
|
+
} else {
|
|
17
|
+
handleGalaxpayWebhook(req, res);
|
|
18
|
+
}
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
// # sourceMappingURL=galaxpay-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"galaxpay-events.js","sourceRoot":"","sources":["../src/galaxpay-events.ts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,EACL,uBAAuB,GAExB,MAAM,4CAA4C,CAAC;AACpD,OAAO,cAAc,MAAM,yCAAyC,CAAC;AACrE,OAAO,qBAAqB,MAAM,kCAAkC,CAAC;AAErE,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,YAAY,EAAE,uBAAuB,CACnC,UAAU,EACV,cAAiC,CAClC;IAED,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,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SACjC;IACH,CAAC,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import logger from 'firebase-functions/logger';
|
|
2
|
+
import { readFile, responseError, isSandbox } from './functions-lib/utils.js';
|
|
3
|
+
import { handleGateway, discountPlan } from './functions-lib/galaxpay/handle-plans.js';
|
|
4
|
+
import { parsePeriodicityToEcom } from './functions-lib/all-parses.js';
|
|
5
|
+
|
|
6
|
+
export default async (data) => {
|
|
7
|
+
const { application } = data;
|
|
8
|
+
const { params } = data;
|
|
9
|
+
// https://apx-mods.e-com.plus/api/v1/list_payments/schema.json?store_id=100
|
|
10
|
+
const amount = params.amount || { total: undefined, discount: undefined };
|
|
11
|
+
// const initialTotalAmount = amount.total;
|
|
12
|
+
const configApp = {
|
|
13
|
+
...application.data,
|
|
14
|
+
...application.hidden_data,
|
|
15
|
+
};
|
|
16
|
+
// setup basic required response object
|
|
17
|
+
const response = {
|
|
18
|
+
payment_gateways: [],
|
|
19
|
+
};
|
|
20
|
+
if (!configApp.galaxpay_id || !configApp.galaxpay_hash) {
|
|
21
|
+
return responseError(409, 'NO_GALAXPAY_KEYS', 'GalaxPay ID e/ou GalaxPay Hash da API indefinido(s) (lojista deve configurar o aplicativo)');
|
|
22
|
+
}
|
|
23
|
+
// common payment methods data
|
|
24
|
+
const intermediator = {
|
|
25
|
+
name: 'GalaxPay',
|
|
26
|
+
link: `https://api.${isSandbox ? 'sandbox.cloud.' : ''}galaxpay.com.br/v2`,
|
|
27
|
+
code: 'galaxpay_app',
|
|
28
|
+
};
|
|
29
|
+
const paymentTypes = [];
|
|
30
|
+
if (configApp.plans) {
|
|
31
|
+
paymentTypes.push('recurrence');
|
|
32
|
+
}
|
|
33
|
+
// setup payment gateway objects
|
|
34
|
+
const plans = handleGateway(configApp);
|
|
35
|
+
plans.forEach((plan) => {
|
|
36
|
+
['credit_card', 'banking_billet', 'pix'].forEach((paymentMethod) => {
|
|
37
|
+
paymentTypes.forEach((type) => {
|
|
38
|
+
const methodConfig = configApp[paymentMethod] || {};
|
|
39
|
+
const methodMinAmount = methodConfig.min_amount || 0;
|
|
40
|
+
if (!methodConfig.disable && (amount.total && methodMinAmount <= amount.total)) {
|
|
41
|
+
logger.log('> Plan ', plan.periodicity);
|
|
42
|
+
const isCreditCard = paymentMethod === 'credit_card';
|
|
43
|
+
const isPix = paymentMethod === 'pix';
|
|
44
|
+
let { label } = methodConfig;
|
|
45
|
+
if (!label) {
|
|
46
|
+
if (isCreditCard) {
|
|
47
|
+
label = 'Cartão de crédito';
|
|
48
|
+
} else {
|
|
49
|
+
label = isPix ? 'PIX' : 'Boleto bancário';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const periodicity = parsePeriodicityToEcom(plan.periodicity);
|
|
53
|
+
const planName = plan.label ? plan.label : 'Plano';
|
|
54
|
+
if (type === 'recurrence' && planName) {
|
|
55
|
+
label = `${planName} ${periodicity} ${label}`;
|
|
56
|
+
}
|
|
57
|
+
const gateway = {
|
|
58
|
+
label,
|
|
59
|
+
icon: methodConfig.icon,
|
|
60
|
+
text: methodConfig.text,
|
|
61
|
+
payment_method: {
|
|
62
|
+
code: isPix ? 'account_deposit' : paymentMethod,
|
|
63
|
+
name: `${label} - ${intermediator.name}`,
|
|
64
|
+
},
|
|
65
|
+
type,
|
|
66
|
+
intermediator,
|
|
67
|
+
};
|
|
68
|
+
if (isCreditCard) {
|
|
69
|
+
if (!gateway.icon) {
|
|
70
|
+
// Alternative solution
|
|
71
|
+
gateway.icon = 'https://ecom-galaxpay.web.app/credit-card.png';
|
|
72
|
+
// TODO:
|
|
73
|
+
}
|
|
74
|
+
// https://docs.galaxpay.com.br/tokenizacao-cartao-js
|
|
75
|
+
gateway.js_client = {
|
|
76
|
+
script_uri: 'https://js.galaxpay.com.br/checkout.min.js',
|
|
77
|
+
onload_expression: `window._galaxPayPublicToken="${configApp.galaxpay_public_token}";
|
|
78
|
+
window._galaxPaySandbox=${isSandbox};
|
|
79
|
+
${readFile('../../assets/onload-expression.min.js')}`,
|
|
80
|
+
cc_hash: {
|
|
81
|
+
function: '_galaxyHashcard',
|
|
82
|
+
is_promise: true,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const planDiscount = discountPlan(plan.discount, amount);
|
|
87
|
+
if (planDiscount) {
|
|
88
|
+
if (gateway && gateway.discount) {
|
|
89
|
+
gateway.discount = planDiscount;
|
|
90
|
+
}
|
|
91
|
+
response.discount_option = {
|
|
92
|
+
label,
|
|
93
|
+
...planDiscount,
|
|
94
|
+
apply_at: planDiscount?.apply_at !== 'freight'
|
|
95
|
+
? planDiscount?.apply_at : undefined,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
response.payment_gateways.push(gateway);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
return response;
|
|
104
|
+
};
|
|
105
|
+
// # sourceMappingURL=galaxpay-list-payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"galaxpay-list-payments.js","sourceRoot":"","sources":["../src/galaxpay-list-payments.ts"],"names":[],"mappings":"AAMA,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAKpE,eAAe,KAAK,EAAE,IAAmB,EAAE,EAAE;IAC3C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAA4B,CAAC;IACjD,4EAA4E;IAC5E,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IAC1E,2CAA2C;IAE3C,MAAM,SAAS,GAAG;QAChB,GAAG,WAAW,CAAC,IAAI;QACnB,GAAG,WAAW,CAAC,WAAW;KACZ,CAAC;IAEjB,uCAAuC;IACvC,MAAM,QAAQ,GAAyB;QACrC,gBAAgB,EAAE,EAAE;KACrB,CAAC;IAEF,IAAI,CAAC,SAAS,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;QACtD,OAAO,aAAa,CAClB,GAAG,EACH,kBAAkB,EAClB,4FAA4F,CAC7F,CAAC;KACH;IAED,8BAA8B;IAC9B,MAAM,aAAa,GAAG;QACpB,IA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C;wBAED,QAAQ,CAAC,eAAe,GAAG;4BACzB,KAAK;4BACL,GAAG,YAAY;4BACf,QAAQ,EAAE,YAAY,EAAE,QAAQ,KAAK,SAAS;gCAC5C,CAAC,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;yBACvC,CAAC;qBACH;oBACD,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;iBACzC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC,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<{
|
|
4
|
+
status: number;
|
|
5
|
+
error: string;
|
|
6
|
+
message: string;
|
|
7
|
+
} | import("@cloudcommerce/types").ListPaymentsResponse>;
|
|
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: "pending" | "authorized" | "paid" | "unauthorized" | "refunded" | "voided" | "unknown" | "under_analysis" | "in_dispute";
|
|
68
|
+
} | undefined;
|
|
69
|
+
flags?: string[] | undefined;
|
|
70
|
+
custom_fields?: {
|
|
71
|
+
field: string;
|
|
72
|
+
value: string;
|
|
73
|
+
}[] | undefined;
|
|
74
|
+
notes?: string | undefined;
|
|
75
|
+
};
|
|
76
|
+
}>;
|
package/lib/galaxpay.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '@cloudcommerce/firebase/lib/init';
|
|
2
|
+
import handleListPayments from './galaxpay-list-payments.js';
|
|
3
|
+
import handleCreateTransaction from './galaxpay-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=galaxpay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"galaxpay.js","sourceRoot":"","sources":["../src/galaxpay.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"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './galaxpay';
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,cAAc,YAAY,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloudcommerce/app-galaxpay",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "E-Com Plus Cloud Commerce app to integrate Galax Pay for recurring payments",
|
|
6
|
+
"main": "lib/galaxpay.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/galaxpay.js",
|
|
9
|
+
"./events": "./lib/galaxpay-events.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ecomplus/cloud-commerce.git",
|
|
14
|
+
"directory": "packages/apps/galaxpay"
|
|
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/galaxpay#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "^1.2.1",
|
|
24
|
+
"firebase-admin": "^11.3.0",
|
|
25
|
+
"firebase-functions": "^4.1.0",
|
|
26
|
+
"@cloudcommerce/firebase": "0.1.0",
|
|
27
|
+
"@cloudcommerce/api": "0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@firebase/app-types": "^0.9.0",
|
|
31
|
+
"@cloudcommerce/types": "0.1.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "sh scripts/build.sh"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/scripts/build.sh
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// import type { GalaxpayApp } from '../../types/configApp';
|
|
2
|
+
// import type { ListPaymentsResponse } from '@cloudcommerce/types/modules/list_payments:response';
|
|
3
|
+
|
|
4
|
+
// type Gateway = ListPaymentsResponse['payment_gateways'][number]
|
|
5
|
+
|
|
6
|
+
const gerateId = (id: string | number) => {
|
|
7
|
+
const length = 24 - id.toString().length + 1;
|
|
8
|
+
return Array(length).join('0') + id;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const parsePeriodicityToEcom = (periodicity?: string) => {
|
|
12
|
+
switch (periodicity) {
|
|
13
|
+
case 'weekly':
|
|
14
|
+
return 'Semanal';
|
|
15
|
+
case 'biweekly':
|
|
16
|
+
return 'Quinzenal';
|
|
17
|
+
case 'monthly':
|
|
18
|
+
return 'Mensal';
|
|
19
|
+
case 'bimonthly':
|
|
20
|
+
return 'Bimestral';
|
|
21
|
+
case 'quarterly':
|
|
22
|
+
return 'Trimestral';
|
|
23
|
+
case 'biannual':
|
|
24
|
+
return 'Semestral';
|
|
25
|
+
case 'yearly':
|
|
26
|
+
return 'Anual';
|
|
27
|
+
default:
|
|
28
|
+
return periodicity;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const parseStatus = (status?: string) => {
|
|
33
|
+
switch (status) {
|
|
34
|
+
case 'notSend': // Ainda não enviada para operadora de Cartão
|
|
35
|
+
case 'pendingBoleto': // Boleto em aberto
|
|
36
|
+
case 'pendingPix': // Pix em aberto
|
|
37
|
+
return 'pending';
|
|
38
|
+
|
|
39
|
+
case 'authorized': // Autorizado na Operadora de Cartão
|
|
40
|
+
return 'authorized';
|
|
41
|
+
|
|
42
|
+
case 'captured': // Capturada na Operadora de Cartão
|
|
43
|
+
case 'payExternal': // Paga fora do sistema
|
|
44
|
+
case 'payedBoleto': // Boleto compensado
|
|
45
|
+
case 'payedPix': // Pix pago
|
|
46
|
+
case 'free': // Isento
|
|
47
|
+
return 'paid';
|
|
48
|
+
|
|
49
|
+
case 'denied': // Negada na Operadora de Cartão
|
|
50
|
+
return 'unauthorized';
|
|
51
|
+
|
|
52
|
+
case 'reversed': // Estornada na Operadora de Cartão
|
|
53
|
+
return 'refunded';
|
|
54
|
+
|
|
55
|
+
case 'cancel': // Cancelada manualmente
|
|
56
|
+
case 'cancelByContract': // Cancelada ao cancelar a cobrança
|
|
57
|
+
case 'notCompensated': // Boleto baixado por decurso de prazo
|
|
58
|
+
case 'unavailablePix': // Pix indisponível para pagamento
|
|
59
|
+
return 'voided';
|
|
60
|
+
default:
|
|
61
|
+
return 'unknown';
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const parsePeriodicityToGalaxPay = (periodicity?: string) => {
|
|
66
|
+
switch (periodicity) {
|
|
67
|
+
case 'Semanal':
|
|
68
|
+
return 'weekly';
|
|
69
|
+
case 'Quinzenal':
|
|
70
|
+
return 'biweekly';
|
|
71
|
+
case 'Mensal':
|
|
72
|
+
return 'monthly';
|
|
73
|
+
case 'Bimestral':
|
|
74
|
+
return 'bimonthly';
|
|
75
|
+
case 'Trimestral':
|
|
76
|
+
return 'quarterly';
|
|
77
|
+
case 'Semestral':
|
|
78
|
+
return 'biannual';
|
|
79
|
+
case 'Anual':
|
|
80
|
+
return 'yearly';
|
|
81
|
+
default:
|
|
82
|
+
return periodicity;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
gerateId,
|
|
88
|
+
parsePeriodicityToEcom,
|
|
89
|
+
parsePeriodicityToGalaxPay,
|
|
90
|
+
parseStatus,
|
|
91
|
+
};
|