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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b62140364ec1902babb154c57b6e60d777665ea
4
- data.tar.gz: 95342be1b6a025b524b9c453579e52658af51900
3
+ metadata.gz: ce27e8a5d557978e575039cd3e730948df9540e4
4
+ data.tar.gz: c4259d4e5148d81e212532490dbce6f225c333cf
5
5
  SHA512:
6
- metadata.gz: 4236a76e0a2c535d61c5789409ad880bbb0e5dc97f50c2471a5f3b00baace6a9324ad0b41898df8de13a5867bc87c361d99a0d2d0b7c9acdf5b615849d8d75fd
7
- data.tar.gz: ecfb188dc890dc7bad24cda90f1dd13feadf5acb706e441c82a654bc92da6159c35d053f4c415ea9bc698407145d08c1cd483365684acf1fe0422fa69f0ae02b
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
- @token = create_params[:token]
15
- @use_case = CreateCreditCard.perform(customer, @token)
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 :customer_id, presence: true
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
@@ -5,8 +5,8 @@ module Magnetik
5
5
  attr_reader :local_card
6
6
 
7
7
  def initialize(card, params)
8
- @card = card
9
- @params = params
8
+ @card = card
9
+ @params = params
10
10
  end
11
11
 
12
12
  def perform
@@ -10,6 +10,7 @@ class MagnetikCreateCreditCards < ActiveRecord::Migration
10
10
  t.integer :customer_id
11
11
  t.string :customer_type
12
12
  t.index [:customer_id, :customer_id]
13
+ t.string :name
13
14
 
14
15
  t.timestamps null: false
15
16
  end
@@ -4,4 +4,7 @@ Magnetik.setup do |config|
4
4
 
5
5
  # Magnetik will call this within CreditCardsController to return the current logged in user.
6
6
  config.current_user_method = :current_user
7
+
8
+ # Maximum length of card names:
9
+ config.max_name_length = 255
7
10
  end
@@ -16,6 +16,10 @@ module Magnetik
16
16
  mattr_accessor :current_user_method
17
17
  @@current_user_method = nil
18
18
 
19
+ # Maximum length of card names:
20
+ mattr_accessor :max_name_length
21
+ @@max_name_length = 255
22
+
19
23
  private
20
24
 
21
25
  # Default way to setup Magnetik:
@@ -1,3 +1,3 @@
1
1
  module Magnetik
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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.5
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-04 00:00:00.000000000 Z
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.