@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,130 @@
|
|
|
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 (!configApp.galaxpay_id || !configApp.galaxpay_hash) {
|
|
33
|
+
return responseError(
|
|
34
|
+
409,
|
|
35
|
+
'NO_GALAXPAY_KEYS',
|
|
36
|
+
'GalaxPay ID e/ou GalaxPay Hash da API indefinido(s) (lojista deve configurar o aplicativo)',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// common payment methods data
|
|
41
|
+
const intermediator = {
|
|
42
|
+
name: 'GalaxPay',
|
|
43
|
+
link: `https://api.${isSandbox ? 'sandbox.cloud.' : ''}galaxpay.com.br/v2`,
|
|
44
|
+
code: 'galaxpay_app',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const paymentTypes: Gateway['type'][] = [];
|
|
48
|
+
if (configApp.plans) {
|
|
49
|
+
paymentTypes.push('recurrence');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// setup payment gateway objects
|
|
53
|
+
const plans = handleGateway(configApp);
|
|
54
|
+
|
|
55
|
+
plans.forEach((plan) => {
|
|
56
|
+
['credit_card', 'banking_billet', 'pix'].forEach((paymentMethod) => {
|
|
57
|
+
paymentTypes.forEach((type) => {
|
|
58
|
+
const methodConfig = configApp[paymentMethod] || {};
|
|
59
|
+
const methodMinAmount = methodConfig.min_amount || 0;
|
|
60
|
+
if (!methodConfig.disable && (amount.total && methodMinAmount <= amount.total)) {
|
|
61
|
+
logger.log('> Plan ', plan.periodicity);
|
|
62
|
+
|
|
63
|
+
const isCreditCard = paymentMethod === 'credit_card';
|
|
64
|
+
const isPix = paymentMethod === 'pix';
|
|
65
|
+
let { label } = methodConfig;
|
|
66
|
+
if (!label) {
|
|
67
|
+
if (isCreditCard) {
|
|
68
|
+
label = 'Cartão de crédito';
|
|
69
|
+
} else {
|
|
70
|
+
label = isPix ? 'PIX' : 'Boleto bancário';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const periodicity = parsePeriodicityToEcom(plan.periodicity);
|
|
75
|
+
const planName = plan.label ? plan.label : 'Plano';
|
|
76
|
+
|
|
77
|
+
if (type === 'recurrence' && planName) {
|
|
78
|
+
label = `${planName} ${periodicity} ${label}`;
|
|
79
|
+
}
|
|
80
|
+
const gateway: Gateway = {
|
|
81
|
+
label,
|
|
82
|
+
icon: methodConfig.icon,
|
|
83
|
+
text: methodConfig.text,
|
|
84
|
+
payment_method: {
|
|
85
|
+
code: isPix ? 'account_deposit' : paymentMethod as CodePaymentMethod, // pix is defined payment method outher
|
|
86
|
+
name: `${label} - ${intermediator.name}`,
|
|
87
|
+
},
|
|
88
|
+
type,
|
|
89
|
+
intermediator,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
if (isCreditCard) {
|
|
93
|
+
if (!gateway.icon) {
|
|
94
|
+
// Alternative solution
|
|
95
|
+
gateway.icon = 'https://ecom-galaxpay.web.app/credit-card.png';
|
|
96
|
+
// TODO:
|
|
97
|
+
}
|
|
98
|
+
// https://docs.galaxpay.com.br/tokenizacao-cartao-js
|
|
99
|
+
gateway.js_client = {
|
|
100
|
+
script_uri: 'https://js.galaxpay.com.br/checkout.min.js',
|
|
101
|
+
onload_expression: `window._galaxPayPublicToken="${configApp.galaxpay_public_token}";
|
|
102
|
+
window._galaxPaySandbox=${isSandbox};
|
|
103
|
+
${readFile('../../assets/onload-expression.min.js')}`,
|
|
104
|
+
cc_hash: {
|
|
105
|
+
function: '_galaxyHashcard',
|
|
106
|
+
is_promise: true,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const planDiscount = discountPlan(plan.discount, amount);
|
|
112
|
+
if (planDiscount) {
|
|
113
|
+
if (gateway && gateway.discount) {
|
|
114
|
+
gateway.discount = planDiscount;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
response.discount_option = {
|
|
118
|
+
label,
|
|
119
|
+
...planDiscount,
|
|
120
|
+
apply_at: planDiscount?.apply_at !== 'freight'
|
|
121
|
+
? planDiscount?.apply_at : undefined,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
response.payment_gateways.push(gateway);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
return response;
|
|
130
|
+
};
|
package/src/galaxpay.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
export type GalaxpayApp = {
|
|
3
|
+
galaxpay_id: string,
|
|
4
|
+
galaxpay_hash: string,
|
|
5
|
+
galaxpay_sandbox?: boolean,
|
|
6
|
+
galaxpay_public_token?: string,
|
|
7
|
+
credit_card?: {
|
|
8
|
+
disable?: boolean,
|
|
9
|
+
label?: string,
|
|
10
|
+
min_amount: number,
|
|
11
|
+
text?: string,
|
|
12
|
+
icon?: string,
|
|
13
|
+
}
|
|
14
|
+
banking_billet?: {
|
|
15
|
+
disable?: boolean,
|
|
16
|
+
label?: string,
|
|
17
|
+
min_amount: number,
|
|
18
|
+
text?: string,
|
|
19
|
+
icon?: string,
|
|
20
|
+
add_days: integer,
|
|
21
|
+
};
|
|
22
|
+
pix?: {
|
|
23
|
+
disable?: boolean,
|
|
24
|
+
label?: string,
|
|
25
|
+
min_amount: number,
|
|
26
|
+
instructions?: string,
|
|
27
|
+
add_days: integer
|
|
28
|
+
};
|
|
29
|
+
plans?: {
|
|
30
|
+
label: string,
|
|
31
|
+
periodicity: 'Semanal' | 'Quinzenal' | 'Mensal' | 'Bimestral' | 'Trimestral' | 'Semestral' | 'Anual'
|
|
32
|
+
quantity: integer | 0,
|
|
33
|
+
discount: {
|
|
34
|
+
percentage: boolean,
|
|
35
|
+
value: number,
|
|
36
|
+
apply_at: 'total' | 'subtotal' | 'frete',
|
|
37
|
+
min_amount?: number
|
|
38
|
+
}
|
|
39
|
+
}[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type GalaxPaySubscriptions = {
|
|
43
|
+
myId: string,
|
|
44
|
+
value: integer,
|
|
45
|
+
quantity: integer,
|
|
46
|
+
periodicity: string,
|
|
47
|
+
firstPayDayDate: string,
|
|
48
|
+
additionalInfo?: string,
|
|
49
|
+
mainPaymentMethodId: string,
|
|
50
|
+
Customer: {
|
|
51
|
+
myId?: string,
|
|
52
|
+
name: string,
|
|
53
|
+
document: string,
|
|
54
|
+
emails: string[],
|
|
55
|
+
phones?: integer[],
|
|
56
|
+
Address?: {
|
|
57
|
+
zipCode: number,
|
|
58
|
+
street: string,
|
|
59
|
+
number: string,
|
|
60
|
+
complement?: string,
|
|
61
|
+
neighborhood: string,
|
|
62
|
+
city: string,
|
|
63
|
+
state: string
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
Transactions?: {
|
|
67
|
+
myId: string,
|
|
68
|
+
installment: integer,
|
|
69
|
+
value?: integer,
|
|
70
|
+
payday?: string,
|
|
71
|
+
payedOutsideGalaxPay?: boolean,
|
|
72
|
+
additionalInfo?: string,
|
|
73
|
+
}[],
|
|
74
|
+
PaymentMethodCreditCard?: {
|
|
75
|
+
Card?: {
|
|
76
|
+
hash?: string,
|
|
77
|
+
},
|
|
78
|
+
preAuthorize: boolean
|
|
79
|
+
},
|
|
80
|
+
PaymentMethodBoleto?: {
|
|
81
|
+
fine?: integer,
|
|
82
|
+
interest?: integer,
|
|
83
|
+
instructions?: string,
|
|
84
|
+
deadlineDays?: integer
|
|
85
|
+
},
|
|
86
|
+
PaymentMethodPix?: {
|
|
87
|
+
fine?: integer,
|
|
88
|
+
interest?: integer,
|
|
89
|
+
instructions?: string,
|
|
90
|
+
Deadline?: {
|
|
91
|
+
type?: string,
|
|
92
|
+
value?: integer
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
ExtraFields?: {
|
|
96
|
+
tagName: string
|
|
97
|
+
tagValue: string
|
|
98
|
+
}[]
|
|
99
|
+
}
|