solidus_mp 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e90e231c71dc6382c6d05974fd3e07dd33dfe064eb163637799a76c504600d4d
4
- data.tar.gz: 192d0abde83390e074d79f9e310d51c409916b6f0b9fe43fbdc84d5ee0d2ad0b
3
+ metadata.gz: d29c92bcb9ac399e83b18dcb26c1fc4c0a5afca5561ede0d588286a5cb4e59d8
4
+ data.tar.gz: 6be444c317f9e23f20d357e44c02b8a354ef93d661044ba723acf1112095703f
5
5
  SHA512:
6
- metadata.gz: fecd21500ed0b3a8ed112e66829484f9c89602bc372d2f7e4237230b6ff57439ae8b7ff5b2f67559d4ab407b4c713c538c646a2c10310983696a94e14378f702
7
- data.tar.gz: 75fddd0fd67dce2cbeff6cdb06417ddb32631445e6f91945511e78163ce734bbafa4042cd6dc5e131beaf85ea3c991ca50379e1c1ea14ddfac137b2ec57308aa
6
+ metadata.gz: 1069af3aa6e9e0587dae433367468370e94acbe16c3ae22138c0504a98caa14ff43e344e2e6d85ea7f489d394c31f69353665df500e29d7739d113adbd60c140
7
+ data.tar.gz: 5cb336afb171bc853361e4e66d731ef81e1c4124d91cf1614efdf423c82887a1933171c0ff37c173f5ab69fb915f4fbdda4436e02c8e604783006fe55a4411a8
data/README.md CHANGED
@@ -0,0 +1,30 @@
1
+ # Solidus Bling
2
+
3
+ [![CircleCI](https://circleci.com/gh/solidusio-contrib/solidus_bling.svg?style=shield)](https://circleci.com/gh/solidusio-contrib/solidus_bling)
4
+ [![codecov](https://codecov.io/gh/solidusio-contrib/solidus_bling/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio-contrib/solidus_bling)
5
+
6
+ <!-- Explain what your extension does. -->
7
+
8
+ ## Installation
9
+
10
+ Add solidus_bling to your Gemfile:
11
+
12
+ ```ruby
13
+ gem 'solidus_bling'
14
+ ```
15
+
16
+ Bundle your dependencies and run the installation generator:
17
+
18
+ ```shell
19
+ bin/rails generate solidus_bling:install
20
+ ```
21
+
22
+ ```shell
23
+ bin/rails assets:precompile
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ## License
29
+
30
+ Copyright (c) 2023 ulysses-bull, released under the New BSD License.
@@ -0,0 +1 @@
1
+ json.call(payment_source, :id, :external_id)
@@ -0,0 +1 @@
1
+ json.call(payment_source, :id, :external_id)
@@ -1,220 +1,220 @@
1
- import { Controller } from "@hotwired/stimulus"
2
- import { loadMercadoPago } from "@mercadopago/sdk-js"
3
-
4
- // Connects to data-controller="credit-card"
5
- export default class extends Controller {
6
-
7
- static values = { publicKey: String }
8
- static targets = ["formCardNumber", "formExpirationDate", "formSecurityCode", "formIssuer", "formInstallments", "paymentMethodId", "paymentMethodThumbnail", "formDocumentType", "formCardHolderName"]
9
-
10
- // Anytime the controller is connected to the DOM
11
- async connect() {
12
- await loadMercadoPago()
13
- this.mp = new window.MercadoPago('TEST-dc17baa6-3344-4382-af3f-15d37f3ce4ae')
14
- // estilos dos iframes
15
- const styles = {
16
- style: {
17
- height: "1.5rem",
18
- padding: "0px",
19
- margin: "0px",
20
- fontFamily: "Inter",
21
- placeholderColor: "#9C99AF",
22
- fontSize: "1rem"
23
- },
24
- customFonts: [
25
- {
26
- src: "https://rsms.me/inter/inter.css",
27
- },
28
- ]
29
- }
30
-
31
- // iframe numero cartao
32
- const cardNumberElement = this.createIframe('cardNumber', "Número do cartão", styles, 'formCardNumber')
33
- const expirationDateElement = this.createIframe('expirationDate', "MM/AA", styles, 'formExpirationDate')
34
- const securityCodeElement = this.createIframe('securityCode', "Código de segurança", styles, 'formSecurityCode')
35
- let currentBin
36
- cardNumberElement.on('binChange', async (data) => {
37
- const { bin } = data
38
- try {
39
- if (!bin && this.paymentMethodIdTarget.value) {
40
- this.clearSelectsAndSetPlaceholders("Banco emissor", "Parcelas")
41
- this.paymentMethodIdTarget.value = ""
42
- }
43
-
44
- if (bin && bin !== currentBin) {
45
- const { results } = await this.mp.getPaymentMethods({ bin })
46
- const paymentMethod = results[0]
47
- this.paymentMethodIdTarget.value = paymentMethod.id
48
- this.paymentMethodThumbnailTarget.setAttribute('src', paymentMethod.secure_thumbnail)
49
- this.updatePCIFieldsSettings(paymentMethod, cardNumberElement, securityCodeElement)
50
- this.updateIssuer(paymentMethod, bin)
51
- this.updateInstallments(bin)
52
- }
53
-
54
- currentBin = bin
55
- } catch (e) {
56
- console.error('error getting payment methods: ', e)
57
- }
58
- })
59
-
60
- cardNumberElement.on('focus', this.onFocus(this.formCardNumberTarget))
61
- cardNumberElement.on('blur', this.onBlur(this.formCardNumberTarget))
62
-
63
- expirationDateElement.on('focus', this.onFocus(this.formExpirationDateTarget))
64
- expirationDateElement.on('blur', this.onBlur(this.formExpirationDateTarget))
65
-
66
- securityCodeElement.on('focus', this.onFocus(this.formSecurityCodeTarget))
67
- securityCodeElement.on('blur', this.onBlur(this.formSecurityCodeTarget))
68
- await this.getIdentificationTypes()
69
-
70
- document.getElementById('checkout_form_payment').addEventListener('submit', e => {
71
- if (this.formCardHolderNameTarget.value === "") return
72
- this.createCardToken(e, this.mp)
73
- })
74
-
75
- }
76
-
77
- createIframe(inputName, placeholder, Styles, divId){
78
- const element = this.mp.fields.create(inputName, {
79
- placeholder: placeholder,
80
- ...Styles
81
- }).mount(divId)
82
- return element
83
- }
84
-
85
- onFocus(divElement) {
86
- return function (event) {
87
- divElement.setAttribute('data-focus', 'true')
88
- }
89
- }
90
-
91
- onBlur(divElement) {
92
- return function (event) {
93
- divElement.removeAttribute('data-focus')
94
- }
95
- }
96
-
97
- async getIdentificationTypes() {
98
- try {
99
- const identificationTypes = await this.mp.getIdentificationTypes()
100
-
101
- this.createSelectOptions(this.formDocumentTypeTarget, identificationTypes)
102
- } catch (e) {
103
- return console.error('Error getting identificationTypes: ', e)
104
- }
105
- }
106
-
107
- createSelectOptions(elem, options, labelsAndKeys = { label: "name", value: "id" }) {
108
- const { label, value } = labelsAndKeys
109
-
110
- elem.options.length = 0
111
-
112
- const tempOptions = document.createDocumentFragment()
113
-
114
- options.forEach(option => {
115
- const optValue = option[value]
116
- const optLabel = option[label]
117
-
118
- const opt = document.createElement('option')
119
- opt.value = optValue
120
- opt.textContent = optLabel
121
-
122
- tempOptions.appendChild(opt)
123
- })
124
-
125
- elem.appendChild(tempOptions)
126
- }
127
-
128
- clearSelectsAndSetPlaceholders(issuerPlaceholder, installmentsPlaceholder) {
129
- clearHTMLSelectChildrenFrom(this.formIssuerTarget)
130
- createSelectElementPlaceholder(this.formIssuerTarget, issuerPlaceholder)
131
-
132
- clearHTMLSelectChildrenFrom(this.formInstallmentsTarget)
133
- createSelectElementPlaceholder(this.formInstallmentsTarget, installmentsPlaceholder)
134
- }
135
-
136
- clearHTMLSelectChildrenFrom(element) {
137
- const currOptions = [...element.children]
138
- currOptions.forEach(child => child.remove())
139
- }
140
-
141
- createSelectElementPlaceholder(element, placeholder) {
142
- const optionElement = document.createElement('option')
143
- optionElement.textContent = placeholder
144
- optionElement.setAttribute('selected', "")
145
- optionElement.setAttribute('disabled', "")
146
-
147
- element.appendChild(optionElement)
148
- }
149
-
150
- updatePCIFieldsSettings(paymentMethod, cardNumberElement, securityCodeElement) {
151
- const { settings } = paymentMethod
152
-
153
- const cardNumberSettings = settings[0].card_number
154
- cardNumberElement.update({
155
- settings: cardNumberSettings
156
- })
157
-
158
- const securityCodeSettings = settings[0].security_code
159
- securityCodeElement.update({
160
- settings: securityCodeSettings
161
- })
162
- }
163
-
164
- async updateIssuer(paymentMethod, bin) {
165
- const { additional_info_needed, issuer } = paymentMethod
166
- let issuerOptions = [issuer]
167
-
168
- if (additional_info_needed.includes('issuer_id')) {
169
- issuerOptions = await getIssuers(paymentMethod, bin)
170
- }
171
-
172
- this.createSelectOptions(this.formIssuerTarget, issuerOptions)
173
- }
174
-
175
- async getIssuers(paymentMethod, bin) {
176
- try {
177
- const { id: paymentMethodId } = paymentMethod
178
- return await this.mp.getIssuers({ paymentMethodId, bin })
179
- } catch (e) {
180
- console.error('error getting issuers: ', e)
181
- }
182
- }
183
-
184
- async updateInstallments(bin) {
185
- try {
186
- const installments = await this.mp.getInstallments({
187
- amount: document.getElementById('transactionAmount').value,
188
- bin,
189
- paymentTypeId: 'credit_card'
190
- });
191
- const installmentOptions = installments[0].payer_costs;
192
- const installmentOptionsKeys = { label: 'recommended_message', value: 'installments' };
193
- this.createSelectOptions(this.formInstallmentsTarget, installmentOptions, installmentOptionsKeys);
194
- } catch (error) {
195
- console.error('error getting installments: ', error)
196
- }
197
- }
198
-
199
- async createCardToken(event, mp) {
200
- try {
201
- const tokenElement = document.getElementById('token');
202
- if (!tokenElement.value) {
203
- const formElement = document.getElementById('checkout_form_payment');
204
- event.preventDefault();
205
- const token = await mp.fields.createCardToken({
206
- cardholderName: document.getElementById('formCardHolderName').value,
207
- identificationType: document.getElementById('formDocumentType').value,
208
- identificationNumber: document.getElementById('tax_id').value,
209
- });
210
- tokenElement.value = token.id;
211
- formElement.submit();
212
- } else {
213
- formElement.submit();
214
- }
215
- } catch (e) {
216
- console.error('error creating card token: ', e)
217
- }
218
- }
219
-
220
- }
1
+ import { Controller } from "@hotwired/stimulus"
2
+ import { loadMercadoPago } from "@mercadopago/sdk-js"
3
+
4
+ // Connects to data-controller="credit-card"
5
+ export default class extends Controller {
6
+
7
+ static values = { publicKey: String }
8
+ static targets = ["formCardNumber", "formExpirationDate", "formSecurityCode", "formIssuer", "formInstallments", "paymentMethodId", "paymentMethodThumbnail", "formDocumentType", "formCardHolderName"]
9
+
10
+ // Anytime the controller is connected to the DOM
11
+ async connect() {
12
+ await loadMercadoPago()
13
+ this.mp = new window.MercadoPago('TEST-dc17baa6-3344-4382-af3f-15d37f3ce4ae')
14
+ // estilos dos iframes
15
+ const styles = {
16
+ style: {
17
+ height: "1.5rem",
18
+ padding: "0px",
19
+ margin: "0px",
20
+ fontFamily: "Inter",
21
+ placeholderColor: "#9C99AF",
22
+ fontSize: "1rem"
23
+ },
24
+ customFonts: [
25
+ {
26
+ src: "https://rsms.me/inter/inter.css",
27
+ },
28
+ ]
29
+ }
30
+
31
+ // iframe numero cartao
32
+ const cardNumberElement = this.createIframe('cardNumber', "Número do cartão", styles, 'formCardNumber')
33
+ const expirationDateElement = this.createIframe('expirationDate', "MM/AA", styles, 'formExpirationDate')
34
+ const securityCodeElement = this.createIframe('securityCode', "Código de segurança", styles, 'formSecurityCode')
35
+ let currentBin
36
+ cardNumberElement.on('binChange', async (data) => {
37
+ const { bin } = data
38
+ try {
39
+ if (!bin && this.paymentMethodIdTarget.value) {
40
+ this.clearSelectsAndSetPlaceholders("Banco emissor", "Parcelas")
41
+ this.paymentMethodIdTarget.value = ""
42
+ }
43
+
44
+ if (bin && bin !== currentBin) {
45
+ const { results } = await this.mp.getPaymentMethods({ bin })
46
+ const paymentMethod = results[0]
47
+ this.paymentMethodIdTarget.value = paymentMethod.id
48
+ this.paymentMethodThumbnailTarget.setAttribute('src', paymentMethod.secure_thumbnail)
49
+ this.updatePCIFieldsSettings(paymentMethod, cardNumberElement, securityCodeElement)
50
+ this.updateIssuer(paymentMethod, bin)
51
+ this.updateInstallments(bin)
52
+ }
53
+
54
+ currentBin = bin
55
+ } catch (e) {
56
+ console.error('error getting payment methods: ', e)
57
+ }
58
+ })
59
+
60
+ cardNumberElement.on('focus', this.onFocus(this.formCardNumberTarget))
61
+ cardNumberElement.on('blur', this.onBlur(this.formCardNumberTarget))
62
+
63
+ expirationDateElement.on('focus', this.onFocus(this.formExpirationDateTarget))
64
+ expirationDateElement.on('blur', this.onBlur(this.formExpirationDateTarget))
65
+
66
+ securityCodeElement.on('focus', this.onFocus(this.formSecurityCodeTarget))
67
+ securityCodeElement.on('blur', this.onBlur(this.formSecurityCodeTarget))
68
+ await this.getIdentificationTypes()
69
+
70
+ document.getElementById('checkout_form_payment').addEventListener('submit', e => {
71
+ if (this.formCardHolderNameTarget.value === "") return
72
+ this.createCardToken(e, this.mp)
73
+ })
74
+
75
+ }
76
+
77
+ createIframe(inputName, placeholder, Styles, divId){
78
+ const element = this.mp.fields.create(inputName, {
79
+ placeholder: placeholder,
80
+ ...Styles
81
+ }).mount(divId)
82
+ return element
83
+ }
84
+
85
+ onFocus(divElement) {
86
+ return function (event) {
87
+ divElement.setAttribute('data-focus', 'true')
88
+ }
89
+ }
90
+
91
+ onBlur(divElement) {
92
+ return function (event) {
93
+ divElement.removeAttribute('data-focus')
94
+ }
95
+ }
96
+
97
+ async getIdentificationTypes() {
98
+ try {
99
+ const identificationTypes = await this.mp.getIdentificationTypes()
100
+
101
+ this.createSelectOptions(this.formDocumentTypeTarget, identificationTypes)
102
+ } catch (e) {
103
+ return console.error('Error getting identificationTypes: ', e)
104
+ }
105
+ }
106
+
107
+ createSelectOptions(elem, options, labelsAndKeys = { label: "name", value: "id" }) {
108
+ const { label, value } = labelsAndKeys
109
+
110
+ elem.options.length = 0
111
+
112
+ const tempOptions = document.createDocumentFragment()
113
+
114
+ options.forEach(option => {
115
+ const optValue = option[value]
116
+ const optLabel = option[label]
117
+
118
+ const opt = document.createElement('option')
119
+ opt.value = optValue
120
+ opt.textContent = optLabel
121
+
122
+ tempOptions.appendChild(opt)
123
+ })
124
+
125
+ elem.appendChild(tempOptions)
126
+ }
127
+
128
+ clearSelectsAndSetPlaceholders(issuerPlaceholder, installmentsPlaceholder) {
129
+ clearHTMLSelectChildrenFrom(this.formIssuerTarget)
130
+ createSelectElementPlaceholder(this.formIssuerTarget, issuerPlaceholder)
131
+
132
+ clearHTMLSelectChildrenFrom(this.formInstallmentsTarget)
133
+ createSelectElementPlaceholder(this.formInstallmentsTarget, installmentsPlaceholder)
134
+ }
135
+
136
+ clearHTMLSelectChildrenFrom(element) {
137
+ const currOptions = [...element.children]
138
+ currOptions.forEach(child => child.remove())
139
+ }
140
+
141
+ createSelectElementPlaceholder(element, placeholder) {
142
+ const optionElement = document.createElement('option')
143
+ optionElement.textContent = placeholder
144
+ optionElement.setAttribute('selected', "")
145
+ optionElement.setAttribute('disabled', "")
146
+
147
+ element.appendChild(optionElement)
148
+ }
149
+
150
+ updatePCIFieldsSettings(paymentMethod, cardNumberElement, securityCodeElement) {
151
+ const { settings } = paymentMethod
152
+
153
+ const cardNumberSettings = settings[0].card_number
154
+ cardNumberElement.update({
155
+ settings: cardNumberSettings
156
+ })
157
+
158
+ const securityCodeSettings = settings[0].security_code
159
+ securityCodeElement.update({
160
+ settings: securityCodeSettings
161
+ })
162
+ }
163
+
164
+ async updateIssuer(paymentMethod, bin) {
165
+ const { additional_info_needed, issuer } = paymentMethod
166
+ let issuerOptions = [issuer]
167
+
168
+ if (additional_info_needed.includes('issuer_id')) {
169
+ issuerOptions = await getIssuers(paymentMethod, bin)
170
+ }
171
+
172
+ this.createSelectOptions(this.formIssuerTarget, issuerOptions)
173
+ }
174
+
175
+ async getIssuers(paymentMethod, bin) {
176
+ try {
177
+ const { id: paymentMethodId } = paymentMethod
178
+ return await this.mp.getIssuers({ paymentMethodId, bin })
179
+ } catch (e) {
180
+ console.error('error getting issuers: ', e)
181
+ }
182
+ }
183
+
184
+ async updateInstallments(bin) {
185
+ try {
186
+ const installments = await this.mp.getInstallments({
187
+ amount: document.getElementById('transactionAmount').value,
188
+ bin,
189
+ paymentTypeId: 'credit_card'
190
+ });
191
+ const installmentOptions = installments[0].payer_costs;
192
+ const installmentOptionsKeys = { label: 'recommended_message', value: 'installments' };
193
+ this.createSelectOptions(this.formInstallmentsTarget, installmentOptions, installmentOptionsKeys);
194
+ } catch (error) {
195
+ console.error('error getting installments: ', error)
196
+ }
197
+ }
198
+
199
+ async createCardToken(event, mp) {
200
+ try {
201
+ const tokenElement = document.getElementById('token');
202
+ if (!tokenElement.value) {
203
+ const formElement = document.getElementById('checkout_form_payment');
204
+ event.preventDefault();
205
+ const token = await mp.fields.createCardToken({
206
+ cardholderName: document.getElementById('formCardHolderName').value,
207
+ identificationType: document.getElementById('formDocumentType').value,
208
+ identificationNumber: document.getElementById('tax_id').value,
209
+ });
210
+ tokenElement.value = token.id;
211
+ formElement.submit();
212
+ } else {
213
+ formElement.submit();
214
+ }
215
+ } catch (e) {
216
+ console.error('error creating card token: ', e)
217
+ }
218
+ }
219
+
220
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusMp
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_mp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - caio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-05 00:00:00.000000000 Z
11
+ date: 2023-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -94,8 +94,12 @@ files:
94
94
  - app/models/solidus_mp/mp_card.rb
95
95
  - app/models/solidus_mp/mp_pix.rb
96
96
  - app/models/solidus_mp/pix_payment_source.rb
97
+ - app/views/spree/admin/payments/source_forms/_mercado_pago_card.html.erb
98
+ - app/views/spree/admin/payments/source_forms/_mercado_pago_pix.html.erb
97
99
  - app/views/spree/admin/payments/source_views/_mercado_pago_card.html.erb
98
100
  - app/views/spree/admin/payments/source_views/_mercado_pago_pix.html.erb
101
+ - app/views/spree/api/payments/source_views/_mercado_pago_card.json.jbuilder
102
+ - app/views/spree/api/payments/source_views/_mercado_pago_pix.json.jbuilder
99
103
  - bin/console
100
104
  - bin/rails
101
105
  - bin/rails-engine
@@ -149,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
153
  - !ruby/object:Gem::Version
150
154
  version: '0'
151
155
  requirements: []
152
- rubygems_version: 3.4.6
156
+ rubygems_version: 3.4.19
153
157
  signing_key:
154
158
  specification_version: 4
155
159
  summary: ''