solidus_mp 0.3.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/solidus_mp/card.rb +5 -0
- data/app/models/solidus_mp/customer.rb +6 -0
- data/app/models/solidus_mp/mp_card.rb +66 -5
- data/db/migrate/20240510185743_add_last_four_digits_to_credit_card_source.rb +5 -0
- data/db/migrate/20240715124647_create_solidus_mp_customers.rb +17 -0
- data/db/migrate/20240715125709_create_solidus_mp_cards.rb +14 -0
- data/db/migrate/20240715131005_add_saved_card_column_to_card_source.rb +5 -0
- data/lib/solidus_mp/version.rb +1 -1
- data/spec/models/solidus_mp/card_spec.rb +7 -0
- data/spec/models/solidus_mp/customer_spec.rb +7 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a0d0a12e6c7919205dcbf772d5166d5536f33b90375c1f7c0b06f81df3b0db6
|
4
|
+
data.tar.gz: 51230aee3d7846768b29df33365f8aaa0f1b4c283a3a924d2a8d3e50544bcd60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 144d042e10f881f3df08ab85710ead0c23330042ed435bcc19be3237ec7fd75cce4a78a698e9f23f39d4b9c4a91601e782a7d2ca35d375a78988da2e9750b36b
|
7
|
+
data.tar.gz: d4d08f6d1b79592acb31ff5ad1b1bfb44a0b0456be7f5b58bebf0effa2a838cbeb6c8734e8ffa9caae6dff67b17f98de949916d40c86ff5e98af2599597e6b3a
|
@@ -22,9 +22,13 @@ module SolidusMp
|
|
22
22
|
source.is_a?(payment_source_class)
|
23
23
|
end
|
24
24
|
|
25
|
-
def create_card_payment payment
|
26
|
-
|
27
|
-
|
25
|
+
def create_card_payment payment, user
|
26
|
+
if user
|
27
|
+
customer = find_or_create_customer(payment, user)
|
28
|
+
save_credit_card(payment, customer)
|
29
|
+
end
|
30
|
+
mp_payment = create_mp_payment(payment, customer.try(:external_id))
|
31
|
+
payment.source.update(external_id: mp_payment.id, three_ds_url: mp_payment.three_ds_info_external_resource_url, three_ds_creq: mp_payment.three_ds_info_creq, last_four_digits: mp_payment.last_four_digits)
|
28
32
|
if mp_payment.error || mp_payment.internal_error
|
29
33
|
payment.invalidate
|
30
34
|
error_message = "#{mp_payment.error || mp_payment.internal_error} (#{mp_payment.status_detail})"
|
@@ -39,9 +43,66 @@ module SolidusMp
|
|
39
43
|
payment.source
|
40
44
|
end
|
41
45
|
|
42
|
-
def
|
46
|
+
def find_or_create_customer(payment, user)
|
47
|
+
customer = SolidusMp::Customer.find_by(spree_user_id: user.id)
|
48
|
+
if customer.blank?
|
49
|
+
mp_customer = create_mp_customer(payment)
|
50
|
+
if mp_customer.error.blank?
|
51
|
+
customer = SolidusMp::Customer.create(
|
52
|
+
external_id: mp_customer.external_id,
|
53
|
+
email: mp_customer.email,
|
54
|
+
first_name: mp_customer.first_name,
|
55
|
+
identification_type: mp_customer.identification_type,
|
56
|
+
tax_id: mp_customer.identification_number,
|
57
|
+
spree_user_id: user.id
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
customer
|
62
|
+
end
|
63
|
+
|
64
|
+
def save_credit_card(payment, customer)
|
65
|
+
return if customer.nil?
|
66
|
+
MpApi.configuration.access_token = preferences[:access_token]
|
67
|
+
mp_credit_card = MpApi::Card.new(token: payment.source.token, customer_id: customer.external_id).create
|
68
|
+
SolidusMp::Card.upsert(
|
69
|
+
{
|
70
|
+
external_id: mp_credit_card.external_id,
|
71
|
+
last_four_digits: mp_credit_card.last_four_digits,
|
72
|
+
mp_payment_method_id: mp_credit_card.mp_payment_method_id,
|
73
|
+
customer_id: customer.id
|
74
|
+
}, unique_by: :external_id
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_mp_customer(payment)
|
79
|
+
MpApi.configuration.access_token = preferences[:access_token]
|
80
|
+
MpApi::Customer.new(
|
81
|
+
email: payment.source.email,
|
82
|
+
first_name: payment.order.ship_address.name,
|
83
|
+
identification_type: payment.source.payer_identification_type,
|
84
|
+
identification_number: payment.source.tax_id
|
85
|
+
).create
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_mp_payment payment, customer_id
|
43
89
|
MpApi.configuration.access_token = preferences[:access_token]
|
44
|
-
MpApi::Payment.new(
|
90
|
+
MpApi::Payment.new(
|
91
|
+
amount: payment.amount.to_f,
|
92
|
+
payment_method: payment.source.credit_card_brand,
|
93
|
+
payer_email: payment.source.email,
|
94
|
+
payer_identification_type: payment.source.payer_identification_type,
|
95
|
+
payer_identification_number: payment.source.tax_id,
|
96
|
+
token: payment.source.token,
|
97
|
+
issuer_id: payment.source.issuer_id,
|
98
|
+
installments: payment.source.installments,
|
99
|
+
three_d_secure_mode: true,
|
100
|
+
statement_descriptor: payment.source.statement_descriptor,
|
101
|
+
description: payment.source.description,
|
102
|
+
items: payment.source.items,
|
103
|
+
saved_card: payment.source.saved_card,
|
104
|
+
customer_id: customer_id
|
105
|
+
).create
|
45
106
|
end
|
46
107
|
|
47
108
|
def cancel_payment payment
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateSolidusMpCustomers < ActiveRecord::Migration[7.1]
|
2
|
+
def change
|
3
|
+
create_table :solidus_mp_customers do |t|
|
4
|
+
t.string :external_id
|
5
|
+
t.string :email
|
6
|
+
t.string :first_name
|
7
|
+
t.string :identification_type
|
8
|
+
t.string :tax_id
|
9
|
+
t.integer :spree_user_id, null: false
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
t.foreign_key :spree_users, column: :spree_user_id
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index :solidus_mp_customers, :external_id, unique: true
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateSolidusMpCards < ActiveRecord::Migration[7.1]
|
2
|
+
def change
|
3
|
+
create_table :solidus_mp_cards do |t|
|
4
|
+
t.string :external_id
|
5
|
+
t.string :last_four_digits
|
6
|
+
t.string :mp_payment_method_id
|
7
|
+
t.integer :customer_id, null: false
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :solidus_mp_cards, :external_id, unique: true
|
13
|
+
end
|
14
|
+
end
|
data/lib/solidus_mp/version.rb
CHANGED
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:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- caio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -90,7 +90,9 @@ files:
|
|
90
90
|
- LICENSE
|
91
91
|
- README.md
|
92
92
|
- Rakefile
|
93
|
+
- app/models/solidus_mp/card.rb
|
93
94
|
- app/models/solidus_mp/card_payment_source.rb
|
95
|
+
- app/models/solidus_mp/customer.rb
|
94
96
|
- app/models/solidus_mp/mp_card.rb
|
95
97
|
- app/models/solidus_mp/mp_pix.rb
|
96
98
|
- app/models/solidus_mp/pix_payment_source.rb
|
@@ -115,6 +117,10 @@ files:
|
|
115
117
|
- db/migrate/20231221141935_add_items_to_mp_card.rb
|
116
118
|
- db/migrate/20240105143500_add_status_to_payment_source.rb
|
117
119
|
- db/migrate/20240109171955_add_error_message_to_payment_source.rb
|
120
|
+
- db/migrate/20240510185743_add_last_four_digits_to_credit_card_source.rb
|
121
|
+
- db/migrate/20240715124647_create_solidus_mp_customers.rb
|
122
|
+
- db/migrate/20240715125709_create_solidus_mp_cards.rb
|
123
|
+
- db/migrate/20240715131005_add_saved_card_column_to_card_source.rb
|
118
124
|
- lib/generators/solidus_mp/install/install_generator.rb
|
119
125
|
- lib/generators/solidus_mp/install/templates/app/javascript/controllers/credit_card_controller.js
|
120
126
|
- lib/generators/solidus_mp/install/templates/app/javascript/controllers/three_ds_controller.js
|
@@ -130,6 +136,8 @@ files:
|
|
130
136
|
- lib/solidus_mp/version.rb
|
131
137
|
- solidus_mp.gemspec
|
132
138
|
- spec/models/solidus_mp/card_payment_source_spec.rb
|
139
|
+
- spec/models/solidus_mp/card_spec.rb
|
140
|
+
- spec/models/solidus_mp/customer_spec.rb
|
133
141
|
- spec/models/solidus_mp/pix_payment_source_spec.rb
|
134
142
|
- spec/spec_helper.rb
|
135
143
|
homepage: https://github.com/CaioGarcia1/solidus_mp
|
@@ -157,11 +165,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
165
|
- !ruby/object:Gem::Version
|
158
166
|
version: '0'
|
159
167
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
168
|
+
rubygems_version: 3.5.11
|
161
169
|
signing_key:
|
162
170
|
specification_version: 4
|
163
171
|
summary: ''
|
164
172
|
test_files:
|
165
173
|
- spec/models/solidus_mp/card_payment_source_spec.rb
|
174
|
+
- spec/models/solidus_mp/card_spec.rb
|
175
|
+
- spec/models/solidus_mp/customer_spec.rb
|
166
176
|
- spec/models/solidus_mp/pix_payment_source_spec.rb
|
167
177
|
- spec/spec_helper.rb
|