@cloudcommerce/app-galaxpay 2.9.0 → 2.10.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/lib/functions-lib/all-parses.js.map +1 -1
- package/lib/functions-lib/ecom/events-to-galaxpay.js.map +1 -1
- package/lib/functions-lib/galaxpay/auth/create-access.js.map +1 -1
- package/lib/functions-lib/galaxpay/auth/create-axios.js.map +1 -1
- package/lib/functions-lib/galaxpay/auth/gerate-token.js.map +1 -1
- package/lib/functions-lib/galaxpay/handle-plans.js.map +1 -1
- package/lib/functions-lib/galaxpay/update-subscription.js.map +1 -1
- package/lib/functions-lib/galaxpay/webhook.d.ts +1 -0
- package/lib/functions-lib/galaxpay/webhook.js.map +1 -1
- package/lib/galaxpay-create-transaction.js +2 -2
- package/lib/galaxpay-create-transaction.js.map +1 -1
- package/lib/galaxpay-events.js.map +1 -1
- package/lib/galaxpay-list-payments.js +1 -1
- package/lib/galaxpay-list-payments.js.map +1 -1
- package/package.json +12 -6
- package/.turbo/turbo-build.log +0 -5
- package/CHANGELOG.md +0 -1
- package/assets/onload-expression.js +0 -23
- package/assets/onload-expression.min.js +0 -1
- package/scripts/build.sh +0 -4
- package/src/functions-lib/all-parses.ts +0 -91
- package/src/functions-lib/ecom/events-to-galaxpay.ts +0 -104
- package/src/functions-lib/galaxpay/auth/create-access.ts +0 -80
- package/src/functions-lib/galaxpay/auth/create-axios.ts +0 -21
- package/src/functions-lib/galaxpay/auth/gerate-token.ts +0 -36
- package/src/functions-lib/galaxpay/handle-plans.ts +0 -91
- package/src/functions-lib/galaxpay/update-subscription.ts +0 -92
- package/src/functions-lib/galaxpay/webhook.ts +0 -484
- package/src/functions-lib/utils.ts +0 -23
- package/src/galaxpay-create-transaction.ts +0 -257
- package/src/galaxpay-events.ts +0 -28
- package/src/galaxpay-list-payments.ts +0 -148
- package/src/galaxpay.ts +0 -12
- package/src/index.ts +0 -2
- package/tsconfig.json +0 -6
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AppModuleBody,
|
|
3
|
-
CreateTransactionParams,
|
|
4
|
-
CreateTransactionResponse,
|
|
5
|
-
} from '@cloudcommerce/types';
|
|
6
|
-
import type { GalaxpayApp, GalaxPaySubscriptions } from '../types/config-app';
|
|
7
|
-
import logger from 'firebase-functions/logger';
|
|
8
|
-
import { getFirestore } from 'firebase-admin/firestore';
|
|
9
|
-
import Galaxpay from './functions-lib/galaxpay/auth/create-access';
|
|
10
|
-
import { responseError, isSandbox } from './functions-lib/utils';
|
|
11
|
-
import { findPlanToCreateTransction } from './functions-lib/galaxpay/handle-plans';
|
|
12
|
-
import { parseStatus, parsePeriodicityToGalaxPay } from './functions-lib/all-parses';
|
|
13
|
-
|
|
14
|
-
type To = Exclude<CreateTransactionParams['to'], undefined>
|
|
15
|
-
|
|
16
|
-
const firestoreColl = 'galaxpaySubscriptions';
|
|
17
|
-
|
|
18
|
-
const parseAddress = (to: To) => ({
|
|
19
|
-
zipCode: to.zip,
|
|
20
|
-
street: to.street,
|
|
21
|
-
number: String(to.number) || 's/n',
|
|
22
|
-
complementary: to.complement || undefined,
|
|
23
|
-
neighborhood: to.borough,
|
|
24
|
-
city: to.city,
|
|
25
|
-
state: to.province || to.province_code,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export default async (appData: AppModuleBody) => {
|
|
29
|
-
// treat module request body
|
|
30
|
-
const { application } = appData;
|
|
31
|
-
const params = appData.params as CreateTransactionParams;
|
|
32
|
-
// app configured options
|
|
33
|
-
const configApp = {
|
|
34
|
-
...application.data,
|
|
35
|
-
...application.hidden_data,
|
|
36
|
-
} as GalaxpayApp;
|
|
37
|
-
|
|
38
|
-
const orderId = params.order_id;
|
|
39
|
-
const orderNumber = params.order_number;
|
|
40
|
-
const {
|
|
41
|
-
amount,
|
|
42
|
-
// items,
|
|
43
|
-
buyer,
|
|
44
|
-
to,
|
|
45
|
-
type,
|
|
46
|
-
} = params;
|
|
47
|
-
|
|
48
|
-
logger.log('>(App:GalaxPay) Transaction #order:', orderId, ` ${isSandbox ? ' Sandbox' : ''} <`);
|
|
49
|
-
|
|
50
|
-
const transaction: CreateTransactionResponse['transaction'] = {
|
|
51
|
-
// type,
|
|
52
|
-
amount: amount.total,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
if (!process.env.GALAXPAY_ID) {
|
|
56
|
-
const galaxpayId = configApp.galaxpay_id;
|
|
57
|
-
if (typeof galaxpayId === 'string' && galaxpayId) {
|
|
58
|
-
process.env.GALAXPAY_ID = galaxpayId;
|
|
59
|
-
} else {
|
|
60
|
-
logger.warn('Missing GalaxPay ID');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!process.env.GALAXPAY_HASH) {
|
|
65
|
-
const galaxpayHash = configApp.galaxpay_hash;
|
|
66
|
-
if (typeof galaxpayHash === 'string' && galaxpayHash) {
|
|
67
|
-
process.env.GALAXPAY_HASH = galaxpayHash;
|
|
68
|
-
} else {
|
|
69
|
-
logger.warn('Missing GalaxPay Hash');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// setup required `transaction` response object
|
|
73
|
-
const galaxpayAxios = new Galaxpay({
|
|
74
|
-
galaxpayId: process.env.GALAXPAY_ID,
|
|
75
|
-
galaxpayHash: process.env.GALAXPAY_HASH,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// indicates whether the buyer should be redirected to payment link right after checkout
|
|
79
|
-
let redirectToPayment = false;
|
|
80
|
-
|
|
81
|
-
switch (params.payment_method.code) {
|
|
82
|
-
case 'online_debit':
|
|
83
|
-
redirectToPayment = true;
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// https://docs.galaxpay.com.br/subscriptions/create-without-plan
|
|
90
|
-
|
|
91
|
-
const extraFields = [
|
|
92
|
-
{
|
|
93
|
-
tagName: 'order_number',
|
|
94
|
-
tagValue: `${orderNumber}`,
|
|
95
|
-
}];
|
|
96
|
-
|
|
97
|
-
const galaxpayCustomer = {
|
|
98
|
-
myId: buyer.customer_id,
|
|
99
|
-
name: buyer.fullname,
|
|
100
|
-
document: buyer.doc_number,
|
|
101
|
-
emails: [buyer.email],
|
|
102
|
-
phones: [parseInt(`${buyer.phone.number}`, 10)],
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
let methodConfigName = params.payment_method.code === 'credit_card' ? configApp.credit_card?.label
|
|
106
|
-
: 'Cartão de crédito';
|
|
107
|
-
|
|
108
|
-
methodConfigName = (params.payment_method.code === 'account_deposit'
|
|
109
|
-
? (configApp.pix?.label || 'Pix') : (configApp.banking_billet?.label || 'Boleto bancário'));
|
|
110
|
-
|
|
111
|
-
// handle plan label to find plan by name (label)
|
|
112
|
-
let labelPaymentGateway = params.payment_method.name?.replace('- GalaxPay', '');
|
|
113
|
-
labelPaymentGateway = labelPaymentGateway?.replace(methodConfigName, '');
|
|
114
|
-
|
|
115
|
-
let plan = findPlanToCreateTransction(labelPaymentGateway, configApp);
|
|
116
|
-
|
|
117
|
-
if (!plan && configApp.plans) {
|
|
118
|
-
[plan] = configApp.plans;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const finalAmount = amount.total;
|
|
122
|
-
const fristPayment = new Date();
|
|
123
|
-
|
|
124
|
-
const quantity = plan?.quantity || 0;
|
|
125
|
-
const galaxpaySubscriptions: GalaxPaySubscriptions = {
|
|
126
|
-
myId: `${orderId}`, // requered
|
|
127
|
-
value: Math.floor(finalAmount * 100),
|
|
128
|
-
quantity, // recorrence quantity
|
|
129
|
-
periodicity: parsePeriodicityToGalaxPay(plan?.periodicity) || 'monthly',
|
|
130
|
-
Customer: galaxpayCustomer,
|
|
131
|
-
ExtraFields: extraFields,
|
|
132
|
-
mainPaymentMethodId: 'creditcard',
|
|
133
|
-
firstPayDayDate: fristPayment.toISOString().split('T')[0],
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
if (params.payment_method.code === 'credit_card') {
|
|
137
|
-
const card = {
|
|
138
|
-
hash: params.credit_card?.hash,
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const PaymentMethodCreditCard = {
|
|
142
|
-
Card: card,
|
|
143
|
-
preAuthorize: false,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
galaxpaySubscriptions.PaymentMethodCreditCard = PaymentMethodCreditCard;
|
|
147
|
-
} else if (params.payment_method.code === 'banking_billet') {
|
|
148
|
-
if (to) {
|
|
149
|
-
Object.assign(galaxpayCustomer, { Address: parseAddress(to) });
|
|
150
|
-
} else if (params.billing_address) {
|
|
151
|
-
Object.assign(galaxpayCustomer, { Address: parseAddress(params.billing_address) });
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
fristPayment.setDate(fristPayment.getDate() + (configApp.banking_billet?.add_days || 0));
|
|
155
|
-
|
|
156
|
-
galaxpaySubscriptions.mainPaymentMethodId = 'boleto';
|
|
157
|
-
galaxpaySubscriptions.Customer = galaxpayCustomer;
|
|
158
|
-
[galaxpaySubscriptions.firstPayDayDate] = fristPayment.toISOString().split('T');
|
|
159
|
-
} else if (params.payment_method.code === 'account_deposit') {
|
|
160
|
-
// other is PIX
|
|
161
|
-
if (to) {
|
|
162
|
-
Object.assign(galaxpayCustomer, { Address: parseAddress(to) });
|
|
163
|
-
} else if (params.billing_address) {
|
|
164
|
-
Object.assign(galaxpayCustomer, { Address: parseAddress(params.billing_address) });
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const PaymentMethodPix = {
|
|
168
|
-
instructions: configApp.pix?.instructions || 'Pix',
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
fristPayment.setDate(fristPayment.getDate() + (configApp.pix?.add_days || 0));
|
|
172
|
-
|
|
173
|
-
galaxpaySubscriptions.mainPaymentMethodId = 'pix';
|
|
174
|
-
galaxpaySubscriptions.Customer = galaxpayCustomer;
|
|
175
|
-
[galaxpaySubscriptions.firstPayDayDate] = fristPayment.toISOString().split('T');
|
|
176
|
-
galaxpaySubscriptions.PaymentMethodPix = PaymentMethodPix;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
logger.log('>>(App:GalaxPay): subscriptions ', JSON.stringify(galaxpaySubscriptions), ' <<');
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
await galaxpayAxios.preparing;
|
|
183
|
-
} catch (err: any) {
|
|
184
|
-
logger.error('>(App: GalaxPay) Error =>', err);
|
|
185
|
-
return responseError(409, 'NO_GALAXPAY_AUTH', 'Error getting authentication');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const { axios } = galaxpayAxios;
|
|
189
|
-
if (axios) {
|
|
190
|
-
try {
|
|
191
|
-
if (type === 'recurrence') {
|
|
192
|
-
const { data: { Subscription } } = await axios.post('/subscriptions', galaxpaySubscriptions);
|
|
193
|
-
|
|
194
|
-
logger.log('>(App: GalaxPay) New Subscription ', Subscription, ' <');
|
|
195
|
-
transaction.payment_link = Subscription.paymentLink;
|
|
196
|
-
const transactionGalaxPay = Subscription.Transactions[0];
|
|
197
|
-
|
|
198
|
-
transaction.status = {
|
|
199
|
-
updated_at: Subscription.datetimeLastSentToOperator || new Date().toISOString(),
|
|
200
|
-
current: parseStatus(transactionGalaxPay.status),
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
transaction.intermediator = {
|
|
204
|
-
transaction_id: transactionGalaxPay.tid,
|
|
205
|
-
transaction_code: transactionGalaxPay.authorizationCode,
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const documentRef = getFirestore().doc(`${firestoreColl}/${orderId}`);
|
|
209
|
-
if (documentRef) {
|
|
210
|
-
documentRef.set({
|
|
211
|
-
subscriptionLabel: plan?.label ? plan.label : 'Plano',
|
|
212
|
-
status: 'open',
|
|
213
|
-
orderNumber: params.order_number,
|
|
214
|
-
galaxpayFristTransactionId: transactionGalaxPay.galaxPayId,
|
|
215
|
-
quantity,
|
|
216
|
-
create_at: new Date().toISOString(),
|
|
217
|
-
plan,
|
|
218
|
-
})
|
|
219
|
-
.catch(logger.error);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return {
|
|
223
|
-
redirect_to_payment: redirectToPayment,
|
|
224
|
-
transaction,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
return responseError(409, 'GALAXPAY_TYPE_ERR_', 'Invalid transaction type');
|
|
228
|
-
} catch (error: any) {
|
|
229
|
-
// logger.log(error.response);
|
|
230
|
-
// try to debug request error
|
|
231
|
-
let { message } = error;
|
|
232
|
-
const err = {
|
|
233
|
-
message: `GALAXPAY_TRANSACTION_ERR Order: #${orderId} => ${message}`,
|
|
234
|
-
payment: '',
|
|
235
|
-
status: 0,
|
|
236
|
-
response: '',
|
|
237
|
-
};
|
|
238
|
-
if (error.response) {
|
|
239
|
-
const { status, data } = error.response;
|
|
240
|
-
if (status !== 401 && status !== 403) {
|
|
241
|
-
err.payment = JSON.stringify(transaction);
|
|
242
|
-
err.status = status;
|
|
243
|
-
if (typeof data === 'object' && data) {
|
|
244
|
-
err.response = JSON.stringify(data);
|
|
245
|
-
} else {
|
|
246
|
-
err.response = data;
|
|
247
|
-
}
|
|
248
|
-
} else if (data && Array.isArray(data.errors) && data.errors[0] && data.errors[0].message) {
|
|
249
|
-
message = data.errors[0].message;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
logger.error(err);
|
|
253
|
-
return responseError(409, 'GALAXPAY_TRANSACTION_ERR', message);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return responseError(409, 'GALAXPAY_REQUEST_ERR_', 'Unexpected error creating charge');
|
|
257
|
-
};
|
package/src/galaxpay-events.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/prefer-default-export */
|
|
2
|
-
|
|
3
|
-
import '@cloudcommerce/firebase/lib/init';
|
|
4
|
-
import * as functions from 'firebase-functions/v1';
|
|
5
|
-
import config from '@cloudcommerce/firebase/lib/config';
|
|
6
|
-
import {
|
|
7
|
-
createAppEventsFunction,
|
|
8
|
-
ApiEventHandler,
|
|
9
|
-
} from '@cloudcommerce/firebase/lib/helpers/pubsub';
|
|
10
|
-
import handleApiEvent from './functions-lib/ecom/events-to-galaxpay';
|
|
11
|
-
import handleGalaxpayWebhook from './functions-lib/galaxpay/webhook';
|
|
12
|
-
|
|
13
|
-
export const galaxpay = {
|
|
14
|
-
onStoreEvent: createAppEventsFunction(
|
|
15
|
-
'galaxPay',
|
|
16
|
-
handleApiEvent as ApiEventHandler,
|
|
17
|
-
),
|
|
18
|
-
|
|
19
|
-
webhook: functions
|
|
20
|
-
.region(config.get().httpsFunctionOptions.region)
|
|
21
|
-
.https.onRequest((req, res) => {
|
|
22
|
-
if (req.method !== 'POST') {
|
|
23
|
-
res.sendStatus(405);
|
|
24
|
-
} else {
|
|
25
|
-
handleGalaxpayWebhook(req, res);
|
|
26
|
-
}
|
|
27
|
-
}),
|
|
28
|
-
};
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AppModuleBody,
|
|
3
|
-
ListPaymentsParams,
|
|
4
|
-
ListPaymentsResponse,
|
|
5
|
-
} from '@cloudcommerce/types';
|
|
6
|
-
import type { GalaxpayApp } from '../types/config-app';
|
|
7
|
-
import logger from 'firebase-functions/logger';
|
|
8
|
-
import { readFile, responseError, isSandbox } from './functions-lib/utils';
|
|
9
|
-
import { handleGateway, discountPlan } from './functions-lib/galaxpay/handle-plans';
|
|
10
|
-
import { parsePeriodicityToEcom } from './functions-lib/all-parses';
|
|
11
|
-
|
|
12
|
-
type Gateway = ListPaymentsResponse['payment_gateways'][number]
|
|
13
|
-
type CodePaymentMethod = Gateway['payment_method']['code']
|
|
14
|
-
|
|
15
|
-
export default async (data: AppModuleBody) => {
|
|
16
|
-
const { application } = data;
|
|
17
|
-
const params = data.params as ListPaymentsParams;
|
|
18
|
-
// https://apx-mods.e-com.plus/api/v1/list_payments/schema.json?store_id=100
|
|
19
|
-
const amount = params.amount || { total: undefined, discount: undefined };
|
|
20
|
-
// const initialTotalAmount = amount.total;
|
|
21
|
-
|
|
22
|
-
const configApp = {
|
|
23
|
-
...application.data,
|
|
24
|
-
...application.hidden_data,
|
|
25
|
-
} as GalaxpayApp;
|
|
26
|
-
|
|
27
|
-
// setup basic required response object
|
|
28
|
-
const response: ListPaymentsResponse = {
|
|
29
|
-
payment_gateways: [],
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if (!process.env.GALAXPAY_ID) {
|
|
33
|
-
const galaxpayId = configApp.galaxpay_id;
|
|
34
|
-
if (typeof galaxpayId === 'string' && galaxpayId) {
|
|
35
|
-
process.env.GALAXPAY_ID = galaxpayId;
|
|
36
|
-
} else {
|
|
37
|
-
logger.warn('Missing GalaxPay ID');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!process.env.GALAXPAY_HASH) {
|
|
42
|
-
const galaxpayHash = configApp.galaxpay_hash;
|
|
43
|
-
if (typeof galaxpayHash === 'string' && galaxpayHash) {
|
|
44
|
-
process.env.GALAXPAY_HASH = galaxpayHash;
|
|
45
|
-
} else {
|
|
46
|
-
logger.warn('Missing GalaxPay Hash');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!process.env.GALAXPAY_ID || !process.env.GALAXPAY_HASH) {
|
|
51
|
-
return responseError(
|
|
52
|
-
409,
|
|
53
|
-
'NO_GALAXPAY_KEYS',
|
|
54
|
-
'GalaxPay ID e/ou GalaxPay Hash da API indefinido(s) (lojista deve configurar o aplicativo)',
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// common payment methods data
|
|
59
|
-
const intermediator = {
|
|
60
|
-
name: 'GalaxPay',
|
|
61
|
-
link: `https://api.${isSandbox ? 'sandbox.cloud.' : ''}galaxpay.com.br/v2`,
|
|
62
|
-
code: 'galaxpay_app',
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const paymentTypes: Gateway['type'][] = [];
|
|
66
|
-
if (configApp.plans) {
|
|
67
|
-
paymentTypes.push('recurrence');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// setup payment gateway objects
|
|
71
|
-
const plans = handleGateway(configApp);
|
|
72
|
-
|
|
73
|
-
plans.forEach((plan) => {
|
|
74
|
-
['credit_card', 'banking_billet', 'pix'].forEach((paymentMethod) => {
|
|
75
|
-
paymentTypes.forEach((type) => {
|
|
76
|
-
const methodConfig = configApp[paymentMethod] || {};
|
|
77
|
-
const methodMinAmount = methodConfig.min_amount || 0;
|
|
78
|
-
if (!methodConfig.disable && (amount.total && methodMinAmount <= amount.total)) {
|
|
79
|
-
logger.log('> Plan ', plan.periodicity);
|
|
80
|
-
|
|
81
|
-
const isCreditCard = paymentMethod === 'credit_card';
|
|
82
|
-
const isPix = paymentMethod === 'pix';
|
|
83
|
-
let { label } = methodConfig;
|
|
84
|
-
if (!label) {
|
|
85
|
-
if (isCreditCard) {
|
|
86
|
-
label = 'Cartão de crédito';
|
|
87
|
-
} else {
|
|
88
|
-
label = isPix ? 'PIX' : 'Boleto bancário';
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const periodicity = parsePeriodicityToEcom(plan.periodicity);
|
|
93
|
-
const planName = plan.label ? plan.label : 'Plano';
|
|
94
|
-
|
|
95
|
-
if (type === 'recurrence' && planName) {
|
|
96
|
-
label = `${planName} ${periodicity} ${label}`;
|
|
97
|
-
}
|
|
98
|
-
const gateway: Gateway = {
|
|
99
|
-
label,
|
|
100
|
-
icon: methodConfig.icon,
|
|
101
|
-
text: methodConfig.text,
|
|
102
|
-
payment_method: {
|
|
103
|
-
code: isPix ? 'account_deposit' : paymentMethod as CodePaymentMethod, // pix is defined payment method outher
|
|
104
|
-
name: `${label} - ${intermediator.name}`,
|
|
105
|
-
},
|
|
106
|
-
type,
|
|
107
|
-
intermediator,
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
if (isCreditCard) {
|
|
111
|
-
if (!gateway.icon) {
|
|
112
|
-
// Alternative solution
|
|
113
|
-
gateway.icon = 'https://ecom-galaxpay.web.app/credit-card.png';
|
|
114
|
-
// TODO:
|
|
115
|
-
}
|
|
116
|
-
// https://docs.galaxpay.com.br/tokenizacao-cartao-js
|
|
117
|
-
gateway.js_client = {
|
|
118
|
-
script_uri: 'https://js.galaxpay.com.br/checkout.min.js',
|
|
119
|
-
onload_expression: `window._galaxPayPublicToken="${configApp.galaxpay_public_token}";
|
|
120
|
-
window._galaxPaySandbox=${isSandbox};
|
|
121
|
-
${readFile('../../assets/onload-expression.min.js')}`,
|
|
122
|
-
cc_hash: {
|
|
123
|
-
function: '_galaxyHashcard',
|
|
124
|
-
is_promise: true,
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const planDiscount = discountPlan(plan.discount, amount);
|
|
130
|
-
if (planDiscount) {
|
|
131
|
-
if (gateway && gateway.discount) {
|
|
132
|
-
gateway.discount = planDiscount;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
response.discount_option = {
|
|
136
|
-
label,
|
|
137
|
-
...planDiscount,
|
|
138
|
-
apply_at: planDiscount?.apply_at !== 'freight'
|
|
139
|
-
? planDiscount?.apply_at : undefined,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
response.payment_gateways.push(gateway);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
return response;
|
|
148
|
-
};
|
package/src/galaxpay.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { AppModuleBody } from '@cloudcommerce/types';
|
|
2
|
-
import '@cloudcommerce/firebase/lib/init';
|
|
3
|
-
import handleListPayments from './galaxpay-list-payments';
|
|
4
|
-
import handleCreateTransaction from './galaxpay-create-transaction';
|
|
5
|
-
|
|
6
|
-
export const listPayments = async (modBody: AppModuleBody) => {
|
|
7
|
-
return handleListPayments(modBody);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const createTransaction = async (modBody: AppModuleBody) => {
|
|
11
|
-
return handleCreateTransaction(modBody);
|
|
12
|
-
};
|
package/src/index.ts
DELETED