magnetik 0.0.8 → 0.1.0

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: 9965f19fa824060e3ba20bd98269bb1feeef2bfe
4
- data.tar.gz: d41dc1c54d2677c22f20985cf66d970c0151273c
3
+ metadata.gz: dee2ddf0cd6087b8a54e77348a23d19a7c416b41
4
+ data.tar.gz: baebd3d15a965daefdddef655e1ca371e1ee8555
5
5
  SHA512:
6
- metadata.gz: 8c4cb83bafcb454764d38381d1f7224f49db5704d4ae48b72ae9899ddf182c7d2eb166195aafbb9af4dfd3a169f09be112a73f2c9bd049a1710a6bc4156b4b52
7
- data.tar.gz: d5a9050449f088b96b167ae5d074d97600a0dbcb3178cb7321c6e16f0f8566305e6e66bbac771e8f687b2c31f6fbc013d11ce631f5b0246383b9cf9656d8c3a7
6
+ metadata.gz: 82fee18060c34aae7603672fcd3be2c830ce87993050a1426f38b93c8733591c581179612f1e09a8470af434b261567798fc344ecad3527a39f484b941544272
7
+ data.tar.gz: 75cd497839e9a6047fda0c313ee79f75a75077da5bf44ca0c46d91d20efec12cc1f3514c1ca5d9f4ee54e04d42c5617cfca6d4fc0ac3c528014bba94f3998eef
@@ -11,5 +11,11 @@ module Magnetik
11
11
  validates :exp_year, presence: true
12
12
  validates :brand, presence: true
13
13
  validates :name, length: { maximum: Magnetik.max_name_length }
14
+
15
+ def requires_revalidation?
16
+ return false if Magnetik.validation_interval.nil?
17
+
18
+ Magnetik.validation_interval.ago > last_validated_at
19
+ end
14
20
  end
15
21
  end
@@ -37,18 +37,21 @@ module Magnetik
37
37
  email: @actor.try(:email),
38
38
  description: @actor.try(:stripe_description)
39
39
  })
40
+ rescue Stripe::StripeError => e
41
+ errors.add(:credit_card, "failed to save for the following reasons: #{e.message}")
42
+ false
40
43
  end
41
44
 
42
45
  def create_local_customer
43
46
  @actor.update_attributes(stripe_customer_id: remote_customer.id).tap do |success|
44
- errors.add(:base, "User failed to save") unless success
47
+ errors.add(:user, "failed to save") unless success
45
48
  end
46
49
  end
47
50
 
48
51
  def create_remote_card
49
52
  @remote_card = remote_customer.sources.create(source: @token)
50
53
  rescue Stripe::CardError => e
51
- errors.add(:base, "Credit card failed to save")
54
+ errors.add(:credit_card, "failed to save for the following reasons: #{e.message}")
52
55
  return false
53
56
  end
54
57
 
@@ -59,11 +62,12 @@ module Magnetik
59
62
  last_4_digits: remote_card[:last4],
60
63
  exp_month: remote_card[:exp_month],
61
64
  exp_year: remote_card[:exp_year],
62
- brand: remote_card[:brand]
65
+ brand: remote_card[:brand],
66
+ last_validated_at: Time.current,
63
67
  }))
64
68
 
65
69
  @local_card.save.tap do |success|
66
- errors.add(:base, "Credit card failed to save") unless success
70
+ errors.add(:credit_card, "failed to save") unless success
67
71
  end
68
72
  end
69
73
 
@@ -1,17 +1,18 @@
1
1
  class MagnetikCreateCreditCards < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :magnetik_credit_cards do |t|
4
- t.string :stripe_card_id
5
- t.string :last_4_digits
6
- t.string :exp_month
7
- t.string :exp_year
8
- t.string :brand
4
+ t.string :stripe_card_id, null: false
5
+ t.string :last_4_digits, null: false
6
+ t.string :exp_month, null: false
7
+ t.string :exp_year, null: false
8
+ t.string :brand, null: false
9
9
  t.boolean :is_default
10
- t.integer :customer_id
11
- t.string :customer_type
10
+ t.integer :customer_id, null: false
11
+ t.string :customer_type, null: false
12
12
  t.index [:customer_id, :customer_id]
13
13
  t.string :name
14
14
 
15
+ t.timestamp :last_validated_at, null: false
15
16
  t.timestamps null: false
16
17
  end
17
18
  end
@@ -7,4 +7,7 @@ Magnetik.setup do |config|
7
7
 
8
8
  # Maximum length of card names:
9
9
  config.max_name_length = 255
10
+
11
+ # Time between card validations via pre-auth:
12
+ config.validation_interval = 3.months
10
13
  end
data/lib/magnetik.rb CHANGED
@@ -20,6 +20,10 @@ module Magnetik
20
20
  mattr_accessor :max_name_length
21
21
  @@max_name_length = 255
22
22
 
23
+ # Time between card validations via pre-auth:
24
+ mattr_accessor :validation_interval
25
+ @@validation_interval = 3.months
26
+
23
27
  private
24
28
 
25
29
  # Default way to setup Magnetik:
@@ -1,3 +1,3 @@
1
1
  module Magnetik
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
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.8
4
+ version: 0.1.0
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-25 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: timecop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: Magnetik is a mountable rails engine that allows a model to be turned
154
168
  into a vessel for a Stripe customer, as well as providing routes for credit card
155
169
  management via Stripe, including creating, updating and deleting credit cards.
@@ -211,4 +225,3 @@ signing_key:
211
225
  specification_version: 4
212
226
  summary: Rails engine for credit card management via Stripe.
213
227
  test_files: []
214
- has_rdoc: