@cloudcommerce/app-paghiper 0.2.2
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/lib/functions-lib/create-axios.d.ts +2 -0
- package/lib/functions-lib/create-axios.js +22 -0
- package/lib/functions-lib/create-axios.js.map +1 -0
- package/lib/functions-lib/handle-webhook.d.ts +3 -0
- package/lib/functions-lib/handle-webhook.js +154 -0
- package/lib/functions-lib/handle-webhook.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/paghiper-create-transaction.d.ts +71 -0
- package/lib/paghiper-create-transaction.js +199 -0
- package/lib/paghiper-create-transaction.js.map +1 -0
- package/lib/paghiper-list-payments.d.ts +7 -0
- package/lib/paghiper-list-payments.js +97 -0
- package/lib/paghiper-list-payments.js.map +1 -0
- package/lib/paghiper-webhook.d.ts +5 -0
- package/lib/paghiper-webhook.js +18 -0
- package/lib/paghiper-webhook.js.map +1 -0
- package/lib/paghiper.d.ts +76 -0
- package/lib/paghiper.js +12 -0
- package/lib/paghiper.js.map +1 -0
- package/package.json +36 -0
- package/src/functions-lib/create-axios.ts +21 -0
- package/src/functions-lib/handle-webhook.ts +176 -0
- package/src/index.ts +1 -0
- package/src/paghiper-create-transaction.ts +242 -0
- package/src/paghiper-list-payments.ts +127 -0
- package/src/paghiper-webhook.ts +17 -0
- package/src/paghiper.ts +12 -0
- package/tsconfig.json +6 -0
- package/types/config-app.d.ts +34 -0
- package/webhook.js +1 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import logger from 'firebase-functions/logger';
|
|
2
|
+
import config from '@cloudcommerce/firebase/lib/config';
|
|
3
|
+
import axios from './functions-lib/create-axios.js';
|
|
4
|
+
|
|
5
|
+
const responseError = (status, error, message) => {
|
|
6
|
+
return {
|
|
7
|
+
status: status || 409,
|
|
8
|
+
error,
|
|
9
|
+
message,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
const createTransactionPagHiper = async (body, isPix) => {
|
|
13
|
+
// create new transaction to PagHiper API
|
|
14
|
+
// https://dev.paghiper.com/reference#gerar-boleto
|
|
15
|
+
if (!isPix && process.env.PAGHIPER_PARTNER_ID) {
|
|
16
|
+
body.partners_id = process.env.PAGHIPER_PARTNER_ID;
|
|
17
|
+
} else if (isPix && process.env.PAGHIPER_PIX_PARTNER_ID) {
|
|
18
|
+
body.partners_id = process.env.PAGHIPER_PIX_PARTNER_ID;
|
|
19
|
+
}
|
|
20
|
+
// returns request promise
|
|
21
|
+
const endpoint = `/${(isPix ? 'invoice' : 'transaction')}/create/`;
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
axios(isPix).post(endpoint, body)
|
|
24
|
+
.then(({ data }) => {
|
|
25
|
+
// save transaction ID on database first
|
|
26
|
+
let createRequest;
|
|
27
|
+
if (isPix) {
|
|
28
|
+
createRequest = data.pix_create_request;
|
|
29
|
+
}
|
|
30
|
+
if (!createRequest) {
|
|
31
|
+
createRequest = data.create_request;
|
|
32
|
+
}
|
|
33
|
+
resolve(createRequest);
|
|
34
|
+
})
|
|
35
|
+
.catch(reject);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default async (appData) => {
|
|
40
|
+
const locationId = config.get().httpsFunctionOptions.region;
|
|
41
|
+
const baseUri = `https://${locationId}-${process.env.GCLOUD_PROJECT}.cloudfunctions.net`;
|
|
42
|
+
const webhookUrl = `${baseUri}/paghiper-webhook`;
|
|
43
|
+
// treat module request body
|
|
44
|
+
const { application } = appData;
|
|
45
|
+
const { params } = appData;
|
|
46
|
+
// app configured options
|
|
47
|
+
const configApp = {
|
|
48
|
+
...application.data,
|
|
49
|
+
...application.hidden_data,
|
|
50
|
+
};
|
|
51
|
+
const orderId = params.order_id;
|
|
52
|
+
const orderNumber = params.order_number;
|
|
53
|
+
const {
|
|
54
|
+
amount, items, buyer, to,
|
|
55
|
+
} = params;
|
|
56
|
+
const billingAddress = params.billing_address;
|
|
57
|
+
logger.log(`> (App PagHiper): Create transaction for #${orderId}`);
|
|
58
|
+
let transaction = {
|
|
59
|
+
amount: amount.total,
|
|
60
|
+
};
|
|
61
|
+
// params object follows create transaction request schema:
|
|
62
|
+
// https://apx-mods.e-com.plus/api/v1/create_transaction/schema.json?store_id=100
|
|
63
|
+
// const orderId = params.order_id;
|
|
64
|
+
// logger.log(`> Create transaction for #${storeId} ${orderId}`);
|
|
65
|
+
// setup transaction body to PagHiper reference
|
|
66
|
+
// https://dev.paghiper.com/reference#gerar-boleto
|
|
67
|
+
const address = billingAddress || to;
|
|
68
|
+
const paghiperTransaction = {
|
|
69
|
+
order_id: orderId || orderNumber || new Date().getTime().toString(),
|
|
70
|
+
payer_email: buyer.email,
|
|
71
|
+
payer_name: buyer.fullname,
|
|
72
|
+
payer_cpf_cnpj: buyer.doc_number,
|
|
73
|
+
payer_phone: buyer.phone.number,
|
|
74
|
+
payer_street: address?.street || '',
|
|
75
|
+
payer_number: address?.number || '',
|
|
76
|
+
payer_complement: address?.complement || '',
|
|
77
|
+
payer_district: address?.borough || '',
|
|
78
|
+
payer_city: address?.city || '',
|
|
79
|
+
payer_state: address?.province_code || '',
|
|
80
|
+
payer_zip_code: address?.zip ? address.zip.replace(/\D/g, '') : '',
|
|
81
|
+
notification_url: webhookUrl,
|
|
82
|
+
discount_cents: amount.discount ? Math.round(amount.discount * 100) : '',
|
|
83
|
+
shipping_price_cents: amount.freight ? Math.round(amount.freight * 100) : '',
|
|
84
|
+
fixed_description: true,
|
|
85
|
+
type_bank_slip: 'boletoA4',
|
|
86
|
+
days_due_date: 5,
|
|
87
|
+
per_day_interest: true,
|
|
88
|
+
items: [],
|
|
89
|
+
};
|
|
90
|
+
// parse transaction items list
|
|
91
|
+
items.forEach((item) => {
|
|
92
|
+
paghiperTransaction.items.push({
|
|
93
|
+
description: item.name || item.product_id,
|
|
94
|
+
item_id: item.sku || item.product_id,
|
|
95
|
+
quantity: item.quantity,
|
|
96
|
+
price_cents: Math.round((item.final_price || item.price) * 100),
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
const isPix = params.payment_method.code === 'account_deposit';
|
|
100
|
+
if (isPix) {
|
|
101
|
+
paghiperTransaction.notification_url += '/pix';
|
|
102
|
+
}
|
|
103
|
+
// use configured PagHiper API key
|
|
104
|
+
paghiperTransaction.apiKey = configApp.paghiper_api_key;
|
|
105
|
+
// merge configured banking billet options
|
|
106
|
+
const options = configApp.banking_billet_options;
|
|
107
|
+
if (typeof options === 'object' && options !== null) {
|
|
108
|
+
// options must have only valid properties for PagHiper transaction object
|
|
109
|
+
Object.keys(options).forEach((prop) => {
|
|
110
|
+
if (options[prop]) {
|
|
111
|
+
paghiperTransaction[prop] = options[prop];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
// send request to PagHiper API
|
|
117
|
+
const createRequest = await createTransactionPagHiper(paghiperTransaction, isPix);
|
|
118
|
+
// transaction created successfully
|
|
119
|
+
// https://dev.paghiper.com/reference#exemplos
|
|
120
|
+
// mount response body
|
|
121
|
+
// https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
|
|
122
|
+
transaction = {
|
|
123
|
+
intermediator: {
|
|
124
|
+
transaction_id: createRequest.transaction_id,
|
|
125
|
+
transaction_code: createRequest.transaction_id,
|
|
126
|
+
transaction_reference: createRequest.order_id,
|
|
127
|
+
},
|
|
128
|
+
amount: createRequest.value_cents
|
|
129
|
+
? parseInt(createRequest.value_cents, 10) / 100
|
|
130
|
+
// use amount from create transaction request body
|
|
131
|
+
: params.amount.total,
|
|
132
|
+
};
|
|
133
|
+
if (isPix) {
|
|
134
|
+
// https://dev.paghiper.com/reference#exemplos-pix
|
|
135
|
+
const pixCode = createRequest.pix_code;
|
|
136
|
+
if (transaction.intermediator) {
|
|
137
|
+
transaction.intermediator.transaction_code = pixCode.emv;
|
|
138
|
+
}
|
|
139
|
+
const pixCodeUrls = ['pix_url', 'qrcode_image_url', 'bacen_url'];
|
|
140
|
+
for (let i = 0; i < pixCodeUrls.length; i++) {
|
|
141
|
+
const pixUrl = pixCode[pixCodeUrls[i]];
|
|
142
|
+
if (pixUrl && pixUrl.startsWith('http')) {
|
|
143
|
+
transaction.payment_link = pixUrl;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
transaction.notes = `<img src="${pixCode.qrcode_image_url}" `
|
|
148
|
+
+ 'style="display:block;max-width:100%;margin:0 auto" />';
|
|
149
|
+
} else {
|
|
150
|
+
const bankSlip = createRequest.bank_slip;
|
|
151
|
+
transaction.payment_link = bankSlip.url_slip;
|
|
152
|
+
transaction.banking_billet = {
|
|
153
|
+
code: bankSlip.digitable_line,
|
|
154
|
+
link: bankSlip.url_slip_pdf,
|
|
155
|
+
};
|
|
156
|
+
if (createRequest.due_date) {
|
|
157
|
+
transaction.banking_billet.valid_thru = new Date(createRequest.due_date).toISOString();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
redirect_to_payment: false,
|
|
162
|
+
transaction,
|
|
163
|
+
};
|
|
164
|
+
} catch (err) {
|
|
165
|
+
let { message } = err;
|
|
166
|
+
let statusCode;
|
|
167
|
+
if (!err.request) {
|
|
168
|
+
// not Axios error ?
|
|
169
|
+
logger.error('> (App PagHiper) =>', err);
|
|
170
|
+
statusCode = 500;
|
|
171
|
+
} else {
|
|
172
|
+
let debugMsg = 'Can\'t create transaction: ';
|
|
173
|
+
if (err.config) {
|
|
174
|
+
debugMsg += `${err.config.url} `;
|
|
175
|
+
}
|
|
176
|
+
if (err.response) {
|
|
177
|
+
debugMsg += err.response.status;
|
|
178
|
+
// https://dev.paghiper.com/reference#mensagens-de-retorno-2
|
|
179
|
+
if (err.response.status === 200) {
|
|
180
|
+
const { data } = err.response;
|
|
181
|
+
if (data) {
|
|
182
|
+
debugMsg += ` ${typeof data === 'object' ? JSON.stringify(data) : data}`;
|
|
183
|
+
debugMsg += ` ${JSON.stringify(paghiperTransaction)}`;
|
|
184
|
+
if (data.create_request && data.create_request.response_message) {
|
|
185
|
+
message = data.create_request.response_message;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
debugMsg += message;
|
|
191
|
+
}
|
|
192
|
+
logger.error('> (App PagHiper) =>', debugMsg);
|
|
193
|
+
statusCode = 409;
|
|
194
|
+
}
|
|
195
|
+
// return error status code
|
|
196
|
+
return responseError(statusCode, 'CREATE_TRANSACTION_ERR', message);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
// # sourceMappingURL=paghiper-create-transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paghiper-create-transaction.js","sourceRoot":"","sources":["../src/paghiper-create-transaction.ts"],"names":[],"mappings":"AAMA,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,KAAK,MAAM,8BAA8B,CAAC;AASjD,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,yBAAyB,GAAG,KAAK,EACrC,IAA0B,EAC1B,KAAe,EACD,EAAE;IAChB,yCAAyC;IACzC,kDAAkD;IAClD,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;QAC7C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;KACpD;SAAM,IAAI,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE;QACvD,IAAI,CAA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E,GAAG,GAAG,CAAC,QAAQ,CAAC;oBAC9B,IAAI,IAAI,EAAE;wBACR,QAAQ,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;wBACzE,QAAQ,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,EAAE,CAAC;wBACtD,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE;4BAC/D,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC;yBAChD;qBACF;iBACF;aACF;iBAAM;gBACL,QAAQ,IAAI,OAAO,CAAC;aACrB;YACD,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;YAC9C,UAAU,GAAG,GAAG,CAAC;SAClB;QAED,2BAA2B;QAC3B,OAAO,aAAa,CAClB,UAAU,EACV,wBAAwB,EACxB,OAAO,CACR,CAAC;KACH;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// import logger from 'firebase-functions/logger';
|
|
2
|
+
const responseError = (status, error, message) => {
|
|
3
|
+
return {
|
|
4
|
+
status: status || 409,
|
|
5
|
+
error,
|
|
6
|
+
message,
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default async (data) => {
|
|
11
|
+
const { application } = data;
|
|
12
|
+
const { params } = data;
|
|
13
|
+
// https://apx-mods.e-com.plus/api/v1/list_payments/schema.json?store_id=100
|
|
14
|
+
const amount = params.amount || { total: undefined, discount: undefined };
|
|
15
|
+
// const initialTotalAmount = amount.total;
|
|
16
|
+
const configApp = {
|
|
17
|
+
...application.data,
|
|
18
|
+
...application.hidden_data,
|
|
19
|
+
};
|
|
20
|
+
// setup basic required response object
|
|
21
|
+
const response = {
|
|
22
|
+
payment_gateways: [],
|
|
23
|
+
};
|
|
24
|
+
if (!configApp.paghiper_api_key) {
|
|
25
|
+
// must have configured PagHiper API key and token
|
|
26
|
+
return responseError(400, 'LIST_PAYMENTS_ERR', 'PagHiper API key is unset on app hidden data (merchant must configure the app)');
|
|
27
|
+
}
|
|
28
|
+
const intermediator = {
|
|
29
|
+
name: 'PagHiper',
|
|
30
|
+
link: 'https://www.paghiper.com/',
|
|
31
|
+
code: 'paghiper',
|
|
32
|
+
};
|
|
33
|
+
const listPaymentMethods = ['banking_billet', 'account_deposit'];
|
|
34
|
+
listPaymentMethods.forEach((paymentMethod) => {
|
|
35
|
+
const isPix = paymentMethod === 'account_deposit';
|
|
36
|
+
const minAmount = configApp.min_amount || isPix ? 3 : 0;
|
|
37
|
+
const methodConfig = isPix ? configApp.pix : configApp;
|
|
38
|
+
const methodEnable = isPix ? configApp?.pix?.enable : configApp?.pix?.disable_billet;
|
|
39
|
+
// Workaround for showcase
|
|
40
|
+
const validateAmount = amount.total ? (amount.total >= minAmount) : true;
|
|
41
|
+
if (methodEnable && validateAmount) {
|
|
42
|
+
let label = methodConfig?.label;
|
|
43
|
+
if (!label) {
|
|
44
|
+
if (isPix) {
|
|
45
|
+
label = 'Pagar com Pix';
|
|
46
|
+
} else {
|
|
47
|
+
label = (!params.lang || params.lang === 'pt_br') ? 'Boleto bancário' : 'Banking billet';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const gateway = {
|
|
51
|
+
label,
|
|
52
|
+
icon: methodConfig?.icon,
|
|
53
|
+
text: methodConfig?.text,
|
|
54
|
+
payment_method: {
|
|
55
|
+
code: paymentMethod,
|
|
56
|
+
name: `${label} - ${intermediator.name}`,
|
|
57
|
+
},
|
|
58
|
+
intermediator,
|
|
59
|
+
};
|
|
60
|
+
if (!gateway.icon && isPix) {
|
|
61
|
+
gateway.icon = 'https://us-central1-ecom-pix.cloudfunctions.net/app/pix.png';
|
|
62
|
+
}
|
|
63
|
+
const discount = methodConfig?.discount;
|
|
64
|
+
gateway.discount = discount;
|
|
65
|
+
if (discount) {
|
|
66
|
+
if (discount.value > 0) {
|
|
67
|
+
if (amount.discount && (configApp.cumulative_discount === false)) {
|
|
68
|
+
// can't offer cumulative discount
|
|
69
|
+
delete gateway.discount;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (discount.apply_at !== 'freight') {
|
|
73
|
+
response.discount_option = {
|
|
74
|
+
apply_at: discount.apply_at,
|
|
75
|
+
type: discount.type,
|
|
76
|
+
value: discount.value,
|
|
77
|
+
label: `${label}`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (discount.min_amount) {
|
|
81
|
+
// check amount value to apply discount
|
|
82
|
+
if (amount.total && amount.total < discount.min_amount) {
|
|
83
|
+
delete gateway.discount;
|
|
84
|
+
} else {
|
|
85
|
+
delete discount.min_amount;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} else if (typeof discount.value !== 'number' || Number.isNaN(discount.value)) {
|
|
89
|
+
delete gateway.discount;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
response.payment_gateways.push(gateway);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return response;
|
|
96
|
+
};
|
|
97
|
+
// # sourceMappingURL=paghiper-list-payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paghiper-list-payments.js","sourceRoot":"","sources":["../src/paghiper-list-payments.ts"],"names":[],"mappings":"AAMA,kDAAkD;AAElD,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;AAKF,eAAe,KAAK,EAAE,IAAmB,EAAE,EAAE;IAC3C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAA4B,CAAC;IAC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B,KAAK,EAAE,GAAG,KAAK,EAAE;yBAClB,CAAC;qBACH;oBAED,IAAI,QAAQ,CAAC,UAAU,EAAE;wBACvB,uCAAuC;wBACvC,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC,UAAU,EAAE;4BACtD,OAAO,OAAO,CAAC,QAAQ,CAAC;yBACzB;6BAAM;4BACL,OAAO,QAAQ,CAAC,UAAU,CAAC;yBAC5B;qBACF;iBACF;qBAAM,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;oBAC7E,OAAO,OAAO,CAAC,QAAQ,CAAC;iBACzB;aACF;YAED,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACzC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
import '@cloudcommerce/firebase/lib/init';
|
|
3
|
+
import * as functions from 'firebase-functions/v1';
|
|
4
|
+
import config from '@cloudcommerce/firebase/lib/config';
|
|
5
|
+
import handleWebhook from './functions-lib/handle-webhook.js';
|
|
6
|
+
|
|
7
|
+
export const paghiper = {
|
|
8
|
+
webhook: functions
|
|
9
|
+
.region(config.get().httpsFunctionOptions.region)
|
|
10
|
+
.https.onRequest((req, res) => {
|
|
11
|
+
if (req.method !== 'POST') {
|
|
12
|
+
res.sendStatus(405);
|
|
13
|
+
} else {
|
|
14
|
+
handleWebhook(req, res);
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
// # sourceMappingURL=paghiper-webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paghiper-webhook.js","sourceRoot":"","sources":["../src/paghiper-webhook.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AACnD,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAE3D,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE,SAAS;SACf,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,MAAM,CAAC;SAChD,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC5B,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;YACzB,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SACrB;aAAM;YACL,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SACzB;IACH,CAAC,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AppModuleBody } from '@cloudcommerce/types';
|
|
2
|
+
import '@cloudcommerce/firebase/lib/init';
|
|
3
|
+
export declare const listPayments: (modBody: AppModuleBody) => Promise<import("@cloudcommerce/types").ListPaymentsResponse | {
|
|
4
|
+
status: number;
|
|
5
|
+
error: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const createTransaction: (modBody: AppModuleBody) => Promise<{
|
|
9
|
+
status: number;
|
|
10
|
+
error: string;
|
|
11
|
+
message: string;
|
|
12
|
+
} | {
|
|
13
|
+
redirect_to_payment: boolean;
|
|
14
|
+
transaction: {
|
|
15
|
+
payment_link?: string | undefined;
|
|
16
|
+
payment_instructions?: string | undefined;
|
|
17
|
+
intermediator?: {
|
|
18
|
+
transaction_id?: string | undefined;
|
|
19
|
+
transaction_code?: string | undefined;
|
|
20
|
+
transaction_reference?: string | undefined;
|
|
21
|
+
payment_method?: {
|
|
22
|
+
code: string;
|
|
23
|
+
name?: string | undefined;
|
|
24
|
+
} | undefined;
|
|
25
|
+
buyer_id?: string | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
credit_card?: {
|
|
28
|
+
holder_name?: string | undefined;
|
|
29
|
+
avs_result_code?: string | null | undefined;
|
|
30
|
+
cvv_result_code?: string | null | undefined;
|
|
31
|
+
bin?: number | undefined;
|
|
32
|
+
company?: string | undefined;
|
|
33
|
+
last_digits?: string | undefined;
|
|
34
|
+
token?: string | undefined;
|
|
35
|
+
error_code?: "incorrect_number" | "invalid_number" | "invalid_expiry_date" | "invalid_cvc" | "expired_card" | "incorrect_cvc" | "incorrect_zip" | "incorrect_address" | "card_declined" | "processing_error" | "call_issuer" | "pick_up_card" | undefined;
|
|
36
|
+
} | undefined;
|
|
37
|
+
banking_billet?: {
|
|
38
|
+
code?: string | undefined;
|
|
39
|
+
valid_thru?: string | undefined;
|
|
40
|
+
text_lines?: string[] | undefined;
|
|
41
|
+
link?: string | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
loyalty_points?: {
|
|
44
|
+
name?: string | undefined;
|
|
45
|
+
program_id: string;
|
|
46
|
+
points_value: number;
|
|
47
|
+
ratio?: number | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
currency_id?: string | undefined;
|
|
50
|
+
currency_symbol?: string | undefined;
|
|
51
|
+
discount?: number | undefined;
|
|
52
|
+
amount: number;
|
|
53
|
+
installments?: {
|
|
54
|
+
number: number;
|
|
55
|
+
value?: number | undefined;
|
|
56
|
+
tax?: boolean | undefined;
|
|
57
|
+
total?: number | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
creditor_fees?: {
|
|
60
|
+
installment?: number | undefined;
|
|
61
|
+
operational?: number | undefined;
|
|
62
|
+
intermediation?: number | undefined;
|
|
63
|
+
other?: number | undefined;
|
|
64
|
+
} | undefined;
|
|
65
|
+
status?: {
|
|
66
|
+
updated_at?: string | undefined;
|
|
67
|
+
current: "paid" | "pending" | "refunded" | "voided" | "under_analysis" | "authorized" | "unauthorized" | "in_dispute" | "unknown";
|
|
68
|
+
} | undefined;
|
|
69
|
+
flags?: string[] | undefined;
|
|
70
|
+
custom_fields?: {
|
|
71
|
+
field: string;
|
|
72
|
+
value: string;
|
|
73
|
+
}[] | undefined;
|
|
74
|
+
notes?: string | undefined;
|
|
75
|
+
};
|
|
76
|
+
}>;
|
package/lib/paghiper.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '@cloudcommerce/firebase/lib/init';
|
|
2
|
+
import handleListPayments from './paghiper-list-payments.js';
|
|
3
|
+
import handleCreateTransaction from './paghiper-create-transaction.js';
|
|
4
|
+
|
|
5
|
+
export const listPayments = async (modBody) => {
|
|
6
|
+
return handleListPayments(modBody);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const createTransaction = async (modBody) => {
|
|
10
|
+
return handleCreateTransaction(modBody);
|
|
11
|
+
};
|
|
12
|
+
// # sourceMappingURL=paghiper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paghiper.js","sourceRoot":"","sources":["../src/paghiper.ts"],"names":[],"mappings":"AACA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAC1D,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AAEpE,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;IAC3D,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,OAAsB,EAAE,EAAE;IAChE,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloudcommerce/app-paghiper",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.2.2",
|
|
5
|
+
"description": "E-Com Plus Cloud Commerce app to integrate PagHiper",
|
|
6
|
+
"main": "lib/paghiper.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/paghiper.js",
|
|
9
|
+
"./webhook": "./lib/paghiper-webhook.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ecomplus/cloud-commerce.git",
|
|
14
|
+
"directory": "packages/apps/paghiper"
|
|
15
|
+
},
|
|
16
|
+
"author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
|
|
17
|
+
"license": "Apache 2.0 with Commons Clause",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/ecomplus/cloud-commerce/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/paghiper#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "^1.2.2",
|
|
24
|
+
"firebase-admin": "^11.4.1",
|
|
25
|
+
"firebase-functions": "^4.2.0",
|
|
26
|
+
"@cloudcommerce/api": "0.2.2",
|
|
27
|
+
"@cloudcommerce/firebase": "0.2.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@firebase/app-types": "^0.9.0",
|
|
31
|
+
"@cloudcommerce/types": "0.2.2"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "sh ../../../scripts/build-lib.sh"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Axios HTTP client
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
// returns a reusable axios instance for PagHiper API
|
|
5
|
+
export default (isPix?: boolean) => axios.create({
|
|
6
|
+
// https://github.com/axios/axios#creating-an-instance
|
|
7
|
+
baseURL: isPix ? 'https://pix.paghiper.com/'
|
|
8
|
+
: 'https://api.paghiper.com/',
|
|
9
|
+
headers: {
|
|
10
|
+
'Content-Type': 'application/json;charset=UTF-8',
|
|
11
|
+
Accept: 'application/json',
|
|
12
|
+
'Accept-Charset': 'UTF-8',
|
|
13
|
+
'Accept-Encoding': 'application/json',
|
|
14
|
+
},
|
|
15
|
+
// wait up to 30s
|
|
16
|
+
timeout: 30000,
|
|
17
|
+
validateStatus(status) {
|
|
18
|
+
// success only when received 201
|
|
19
|
+
return status === 201;
|
|
20
|
+
},
|
|
21
|
+
});
|