at-stripe 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: df8ab09caa333ec4e8cdcdcedb7629bc9a2bbd39
4
- data.tar.gz: 8eeb019cfde52c562ed437ad8dc431725f04528e
3
+ metadata.gz: 82538efd7b2e032249592dc032bc5d1c42ee3300
4
+ data.tar.gz: a4bc66f498a6363f8e53d78c21d93fd70f1d6212
5
5
  SHA512:
6
- metadata.gz: e6094af4c3e26e04d073ac924b18af316196813ceebb5faed0062b666f317d3302e86a2d2349b8e1855bc75d687ed1e00cea3853ba9fc7efd7105d9bafd25fb0
7
- data.tar.gz: f9c799c46f247ecdc4dd7d9842a88c1093041fd3df039e8d80aa506add4e8c918d271c92a6176950e2576b63885b93a5448839af1a45a8339b2684b5838377ba
6
+ metadata.gz: c7d02c9805c1a4051ad8a03b944c2d7f1481610754877c037cc92585b180641e56c0ddf8ddb298a2de0fc1c249bce8daa8daeb3bbf7b490f4c84139cb2c4e478
7
+ data.tar.gz: ca50863785d2c2c70d8dcde6e2c74f31b856be3ed101b3c8c8649f2325091f115f8b5caa6b45eb6613ebf23d12d8cf8d45ec6706621716acadc38dd34f0e9acb
@@ -6,29 +6,34 @@ module AT
6
6
  REQUIRED_ACCESSORS = %w{email email= stripe_id stripe_id=}
7
7
 
8
8
  def self.included(base)
9
- lookup = self.method_lookup(base)
10
- REQUIRED_ACCESSORS.each do |attribute|
11
- unless base.send(lookup, attribute)
12
- raise "receiving class must have \##{attribute}"
13
- end
14
- end
9
+ self.enforce_attributes(base)
15
10
  end
16
11
 
17
- def customer
18
- ::Stripe::Customer.retrieve(self.stripe_id)
19
- end
20
12
 
21
- def create_customer
22
- if c = ::Stripe::Customer.create(email: self.email)
23
- (self.stripe_id = c.id) and c
13
+
14
+ def create_customer(options={})
15
+ options[:email] ||= self.email
16
+ if @customer = ::Stripe::Customer.create(options)
17
+ (self.stripe_id = @customer.id) and @customer
24
18
  end
25
19
  end
26
20
 
21
+ def retrieve_customer
22
+ @customer ||= ::Stripe::Customer.retrieve(self.stripe_id)
23
+ end
24
+ alias_method :customer, :retrieve_customer
25
+
26
+
27
+
27
28
  def create_card(card_token)
28
29
  customer.sources.create(source: card_token)
29
30
  end
30
31
 
31
- def fetch_card(card_token)
32
+ def retrieve_card(card_token=nil)
33
+ card_token ||= unless (card = list_cards.data.first).nil?
34
+ card.id
35
+ end
36
+ return if card_token.nil?
32
37
  customer.sources.retrieve(card_token)
33
38
  end
34
39
 
@@ -40,6 +45,8 @@ module AT
40
45
  customer.sources.all(object: 'card', limit: limit)
41
46
  end
42
47
 
48
+
49
+
43
50
  def create_charge(options)
44
51
  unless options.key?(:source) || options.key?(:customer)
45
52
  options[:customer] = self.stripe_id
@@ -55,10 +62,20 @@ module AT
55
62
 
56
63
  private
57
64
 
58
- def self.method_lookup(some_class)
59
- key = some_class.superclass.to_s
65
+ def self.enforce_attributes(base)
66
+ lookup = self.method_lookup(base)
67
+ REQUIRED_ACCESSORS.each do |attribute|
68
+ unless base.send(lookup, attribute)
69
+ raise "receiving class must have \##{attribute}"
70
+ end
71
+ end
72
+ end
73
+
74
+ def self.method_lookup(base)
60
75
  # more stupid special cases coming soon
61
- { 'ActiveRecord::Base' => :attribute_method?,
76
+ key = base.superclass.to_s
77
+ {
78
+ 'ActiveRecord::Base' => :attribute_method?
62
79
  }.fetch(key, :public_method_defined?)
63
80
  end
64
81
  end
@@ -1,5 +1,5 @@
1
1
  module AT
2
2
  module Stripe
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: at-stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kennedy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-18 00:00:00.000000000 Z
13
+ date: 2015-11-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails