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 +4 -4
- data/lib/at-stripe/customer.rb +33 -16
- data/lib/at-stripe/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82538efd7b2e032249592dc032bc5d1c42ee3300
|
4
|
+
data.tar.gz: a4bc66f498a6363f8e53d78c21d93fd70f1d6212
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7d02c9805c1a4051ad8a03b944c2d7f1481610754877c037cc92585b180641e56c0ddf8ddb298a2de0fc1c249bce8daa8daeb3bbf7b490f4c84139cb2c4e478
|
7
|
+
data.tar.gz: ca50863785d2c2c70d8dcde6e2c74f31b856be3ed101b3c8c8649f2325091f115f8b5caa6b45eb6613ebf23d12d8cf8d45ec6706621716acadc38dd34f0e9acb
|
data/lib/at-stripe/customer.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
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.
|
59
|
-
|
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
|
-
|
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
|
data/lib/at-stripe/version.rb
CHANGED
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.
|
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-
|
13
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|