magnetik 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/magnetik/credit_cards_controller.rb +6 -3
- data/app/models/magnetik/credit_card.rb +3 -3
- data/app/use_cases/magnetik/create_credit_card.rb +5 -4
- data/app/use_cases/magnetik/update_credit_card.rb +2 -2
- data/lib/generators/active_record/templates/migration_credit_cards.rb +1 -0
- data/lib/generators/magnetik/install/templates/initializer.rb +3 -0
- data/lib/magnetik.rb +4 -0
- data/lib/magnetik/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce27e8a5d557978e575039cd3e730948df9540e4
|
4
|
+
data.tar.gz: c4259d4e5148d81e212532490dbce6f225c333cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c953c575a2dd738519b40a1e99981399907fff292caf5099b06b818cbac3b6965e45c3b9d899be5f00e9f4ed04e0bdeef0be63c1b3c723e34b8e40c8f339b62
|
7
|
+
data.tar.gz: 16df83ebafbc6dc45b81ddb5b06bafcb7e3068fe6fcaad23aa2f64a60b9486d469c17282802be53bb53897f291601445a6fad0842ae3920e55b122c0bcd13480
|
@@ -11,8 +11,9 @@ module Magnetik
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def create
|
14
|
-
|
15
|
-
|
14
|
+
token = create_params[:token]
|
15
|
+
card_params = create_params.except(:token)
|
16
|
+
@use_case = CreateCreditCard.perform(customer, token, card_params)
|
16
17
|
|
17
18
|
if @use_case.success?
|
18
19
|
render json: { credit_card: @use_case.local_card }, status: :ok
|
@@ -63,12 +64,14 @@ module Magnetik
|
|
63
64
|
|
64
65
|
def create_params
|
65
66
|
params.require(:credit_card).permit(
|
66
|
-
:token
|
67
|
+
:token,
|
68
|
+
:name
|
67
69
|
)
|
68
70
|
end
|
69
71
|
|
70
72
|
def update_params
|
71
73
|
params.require(:credit_card).permit(
|
74
|
+
:name,
|
72
75
|
:exp_month,
|
73
76
|
:exp_year,
|
74
77
|
:is_default
|
@@ -4,12 +4,12 @@ module Magnetik
|
|
4
4
|
belongs_to :customer, polymorphic: true
|
5
5
|
|
6
6
|
# Validations:
|
7
|
-
validates :
|
8
|
-
validates :customer_type, presence: true
|
7
|
+
validates :customer, presence: true
|
9
8
|
validates :stripe_card_id, presence: true
|
10
9
|
validates :last_4_digits, presence: true
|
11
10
|
validates :exp_month, presence: true
|
12
11
|
validates :exp_year, presence: true
|
13
12
|
validates :brand, presence: true
|
13
|
+
validates :name, length: { maximum: Magnetik.max_name_length }
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -4,9 +4,10 @@ module Magnetik
|
|
4
4
|
|
5
5
|
attr_reader :local_card
|
6
6
|
|
7
|
-
def initialize(actor, token)
|
7
|
+
def initialize(actor, token, card_params = {})
|
8
8
|
@token = token
|
9
9
|
@actor = actor
|
10
|
+
@card_params = card_params
|
10
11
|
@remote_customer = nil
|
11
12
|
end
|
12
13
|
|
@@ -25,7 +26,7 @@ module Magnetik
|
|
25
26
|
|
26
27
|
private
|
27
28
|
|
28
|
-
attr_reader :remote_customer, :remote_card
|
29
|
+
attr_reader :remote_customer, :remote_card, :card_params
|
29
30
|
|
30
31
|
def fetch_customer
|
31
32
|
@remote_customer = Stripe::Customer.retrieve(@actor.stripe_customer_id)
|
@@ -52,14 +53,14 @@ module Magnetik
|
|
52
53
|
end
|
53
54
|
|
54
55
|
def create_local_card
|
55
|
-
@local_card = CreditCard.new({
|
56
|
+
@local_card = CreditCard.new(card_params.merge({
|
56
57
|
customer: @actor,
|
57
58
|
stripe_card_id: remote_card[:id],
|
58
59
|
last_4_digits: remote_card[:last4],
|
59
60
|
exp_month: remote_card[:exp_month],
|
60
61
|
exp_year: remote_card[:exp_year],
|
61
62
|
brand: remote_card[:brand]
|
62
|
-
})
|
63
|
+
}))
|
63
64
|
|
64
65
|
@local_card.save.tap do |success|
|
65
66
|
errors.add(:base, "Credit card failed to save") unless success
|
data/lib/magnetik.rb
CHANGED
data/lib/magnetik/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magnetik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Ivanopoulos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 2.1.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: shoulda-matchers
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: Magnetik is a mountable rails engine that allows a model to be turned
|
140
154
|
into a vessel for a Stripe customer, as well as providing routes for credit card
|
141
155
|
management via Stripe, including creating, updating and deleting credit cards.
|