@cloudcommerce/app-mercadopago 2.11.2 → 2.12.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.
@@ -0,0 +1,142 @@
1
+ /* eslint-disable */
2
+ (function () {
3
+ window.Mercadopago.getIdentificationTypes();
4
+
5
+ window._mpHash = function (data) {
6
+ return new Promise((resolve, reject) => {
7
+ window
8
+ ._mpBrand(data.number)
9
+ .then(() => {
10
+ return setMPForm(data);
11
+ })
12
+ .then((res) => {
13
+ window
14
+ .Mercadopago
15
+ .getIssuers(window.mpPaymentMethodId, (status, issuer) => {
16
+ console.log(issuer);
17
+ const token = `${res.id} // ${JSON.stringify({
18
+ payment_method_id: window.mpPaymentMethodId,
19
+ issuer,
20
+ deviceId: window.MP_DEVICE_SESSION_ID || 0
21
+ })}`;
22
+ return resolve(token);
23
+ });
24
+ })
25
+ .catch(reject);
26
+ });
27
+ };
28
+
29
+ window._mpInstallments = function (data) {
30
+ return new Promise((resolve, reject) => {
31
+ window
32
+ ._mpBrand(data.number)
33
+ .then((paymentMethodId) => {
34
+ const options = {
35
+ payment_method_id: paymentMethodId,
36
+ amount: data.amount,
37
+ };
38
+
39
+ return window
40
+ .Mercadopago
41
+ .getInstallments(options, (status, data) => {
42
+ if (status === 200) {
43
+ const installmentList = [];
44
+ for (let i = 0; i < data[0].payer_costs.length; i++) {
45
+ const opt = data[0].payer_costs[i];
46
+ installmentList.push({
47
+ number: opt.installments,
48
+ tax: (opt.installment_rate > 0),
49
+ value: opt.installment_amount,
50
+ });
51
+ }
52
+
53
+ resolve(installmentList);
54
+ } else {
55
+ console.log('installments method info error:', response);
56
+ reject(response);
57
+ }
58
+ });
59
+ })
60
+ .catch(reject);
61
+ });
62
+ };
63
+
64
+ window._mpBrand = function (number) {
65
+ return new Promise((resolve, reject) => {
66
+ let bin = String(number);
67
+ bin = bin.substring(0, 6);
68
+ if (bin.length >= 6) {
69
+ return window
70
+ .Mercadopago
71
+ .getPaymentMethod({
72
+ bin,
73
+ }, (status, resp) => {
74
+ if (status === 200) {
75
+ window.mpPaymentMethodId = resp[0].id;
76
+ resolve(resp[0].id);
77
+ } else {
78
+ console.log('payment method info error:', resp);
79
+ reject(resp);
80
+ }
81
+ });
82
+ }
83
+ reject(new Error('Failed trying installments with card number yet imcomplete'));
84
+ });
85
+ };
86
+
87
+ function setMPForm(data) {
88
+ return new Promise((resolve, reject) => {
89
+ const { customer } = window.storefrontApp;
90
+ const mpParams = {};
91
+ mpParams.cardNumber = data.number;
92
+ mpParams.cardholderName = data.name;
93
+ mpParams.cardExpirationMonth = data.month;
94
+ mpParams.cardExpirationYear = data.year;
95
+ mpParams.securityCode = data.cvc;
96
+
97
+ if (data.doc) {
98
+ mpParams.docNumber = data.doc;
99
+ } else {
100
+ mpParams.docNumber = customer.doc_number;
101
+ }
102
+
103
+ mpParams.email = customer.main_email;
104
+ mpParams.payment_method_id = window.mpPaymentMethodId;
105
+
106
+ const $form = document.createElement('form');
107
+
108
+ for (const key in mpParams) {
109
+ if (mpParams[key]) {
110
+ const value = mpParams[key];
111
+ const $input = document.createElement('input');
112
+ $input.setAttribute('type', 'text');
113
+ $input.setAttribute('id', key);
114
+ $input.setAttribute('data-checkout', key);
115
+ $input.setAttribute('value', value);
116
+ $form.appendChild($input);
117
+ }
118
+ }
119
+
120
+ // todo
121
+ // - select typeDoc
122
+ const $typeDoc = document.createElement('select');
123
+ $typeDoc.setAttribute('data-checkout', 'docType');
124
+ const $typeDocOption = document.createElement('option');
125
+ $typeDocOption.text = customer.registry_type === 'j' ? 'CNPJ' : 'CPF';
126
+ $typeDocOption.value = customer.registry_type === 'j' ? 'CNPJ' : 'CPF';
127
+ $typeDocOption.setAttribute('selected', true);
128
+ $typeDoc.add($typeDocOption);
129
+
130
+ $form.appendChild($typeDoc);
131
+ // - select installments
132
+
133
+ window.Mercadopago.createToken($form, (status, resp) => {
134
+ if (status === 200) {
135
+ resolve(resp);
136
+ } else {
137
+ reject(resp);
138
+ }
139
+ });
140
+ });
141
+ }
142
+ }());
@@ -0,0 +1 @@
1
+ window.Mercadopago.getIdentificationTypes(),window._mpHash=function(t){return new Promise((o,e)=>{window._mpBrand(t.number).then(()=>{return c=t,new Promise((n,o)=>{var e,t,r=window.storefrontApp["customer"],a={},d=(a.cardNumber=c.number,a.cardholderName=c.name,a.cardExpirationMonth=c.month,a.cardExpirationYear=c.year,a.securityCode=c.cvc,c.doc?a.docNumber=c.doc:a.docNumber=r.doc_number,a.email=r.main_email,a.payment_method_id=window.mpPaymentMethodId,document.createElement("form"));for(const s in a)a[s]&&(e=a[s],(t=document.createElement("input")).setAttribute("type","text"),t.setAttribute("id",s),t.setAttribute("data-checkout",s),t.setAttribute("value",e),d.appendChild(t));var i=document.createElement("select"),m=(i.setAttribute("data-checkout","docType"),document.createElement("option"));m.text="j"===r.registry_type?"CNPJ":"CPF",m.value="j"===r.registry_type?"CNPJ":"CPF",m.setAttribute("selected",!0),i.add(m),d.appendChild(i),window.Mercadopago.createToken(d,(e,t)=>{(200===e?n:o)(t)})});var c}).then(n=>{window.Mercadopago.getIssuers(window.mpPaymentMethodId,(e,t)=>{console.log(t);t=n.id+" // "+JSON.stringify({payment_method_id:window.mpPaymentMethodId,issuer:t,deviceId:window.MP_DEVICE_SESSION_ID||0});return o(t)})}).catch(e)})},window._mpInstallments=function(t){return new Promise((r,a)=>{window._mpBrand(t.number).then(e=>{e={payment_method_id:e,amount:t.amount};return window.Mercadopago.getInstallments(e,(e,t)=>{if(200===e){var n=[];for(let e=0;e<t[0].payer_costs.length;e++){var o=t[0].payer_costs[e];n.push({number:o.installments,tax:0<o.installment_rate,value:o.installment_amount})}r(n)}else console.log("installments method info error:",response),a(response)})}).catch(a)})},window._mpBrand=function(t){return new Promise((n,o)=>{let e=String(t);if(6<=(e=e.substring(0,6)).length)return window.Mercadopago.getPaymentMethod({bin:e},(e,t)=>{200===e?(window.mpPaymentMethodId=t[0].id,n(t[0].id)):(console.log("payment method info error:",t),o(t))});o(new Error("Failed trying installments with card number yet imcomplete"))})};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-mercadopago",
3
3
  "type": "module",
4
- "version": "2.11.2",
5
- "description": "E-Com Plus Cloud Commerce app to integrate Mercado Pago",
4
+ "version": "2.12.0",
5
+ "description": "e-com.plus Cloud Commerce app to integrate Mercado Pago",
6
6
  "main": "lib/mercadopago.js",
7
7
  "exports": {
8
8
  ".": "./lib/mercadopago.js",
@@ -11,6 +11,7 @@
11
11
  "files": [
12
12
  "/lib",
13
13
  "/lib-mjs",
14
+ "/assets",
14
15
  "/types",
15
16
  "/*.{js,mjs,ts}"
16
17
  ],
@@ -29,13 +30,13 @@
29
30
  "axios": "^1.6.8",
30
31
  "firebase-admin": "^12.0.0",
31
32
  "firebase-functions": "^4.8.2",
32
- "@cloudcommerce/api": "2.11.2",
33
- "@cloudcommerce/firebase": "2.11.2"
33
+ "@cloudcommerce/api": "2.12.0",
34
+ "@cloudcommerce/firebase": "2.12.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@firebase/app-types": "^0.9.1",
37
- "@cloudcommerce/test-base": "2.11.2",
38
- "@cloudcommerce/types": "2.11.2"
38
+ "@cloudcommerce/test-base": "2.12.0",
39
+ "@cloudcommerce/types": "2.12.0"
39
40
  },
40
41
  "scripts": {
41
42
  "build": "bash scripts/build.sh",