stripe 1.8.3 → 1.8.4
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.
- data/History.txt +4 -0
- data/VERSION +1 -1
- data/gemfiles/default-with-activesupport.gemfile +1 -1
- data/gemfiles/json.gemfile +1 -1
- data/gemfiles/yajl.gemfile +1 -1
- data/lib/stripe.rb +1 -0
- data/lib/stripe/card.rb +14 -0
- data/lib/stripe/list_object.rb +23 -2
- data/lib/stripe/util.rb +11 -8
- data/lib/stripe/version.rb +1 -1
- data/stripe.gemspec +2 -2
- data/test/test_helper.rb +17 -15
- data/test/test_stripe.rb +44 -7
- metadata +11 -11
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.8.
|
1
|
+
1.8.4
|
data/gemfiles/json.gemfile
CHANGED
data/gemfiles/yajl.gemfile
CHANGED
data/lib/stripe.rb
CHANGED
data/lib/stripe/card.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Stripe
|
2
|
+
class Card < APIResource
|
3
|
+
include Stripe::APIOperations::Update
|
4
|
+
include Stripe::APIOperations::Delete
|
5
|
+
|
6
|
+
def url
|
7
|
+
"#{Customer.url}/#{CGI.escape(customer)}/cards/#{CGI.escape(id)}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.retrieve(id, api_key=nil)
|
11
|
+
raise NotImplementedError.new("Cards cannot be retrieved without a customer ID. Retrieve a card using customer.cards.retrieve('card_id')")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/stripe/list_object.rb
CHANGED
@@ -1,14 +1,35 @@
|
|
1
1
|
module Stripe
|
2
2
|
class ListObject < StripeObject
|
3
3
|
|
4
|
+
def [](k)
|
5
|
+
case k
|
6
|
+
when String, Symbol
|
7
|
+
super
|
8
|
+
else
|
9
|
+
raise ArgumentError.new("You tried to access the #{k.inspect} index, but ListObject types only support String keys. (HINT: List calls return an object with a 'data' (which is the data array). You likely want to call #data[#{k.inspect}])")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
def each(&blk)
|
5
14
|
self.data.each(&blk)
|
6
15
|
end
|
7
16
|
|
8
|
-
def
|
9
|
-
|
17
|
+
def retrieve(id, api_key=nil)
|
18
|
+
api_key ||= @api_key
|
19
|
+
response, api_key = Stripe.request(:get,"#{url}/#{CGI.escape(id)}", api_key)
|
10
20
|
Util.convert_to_stripe_object(response, api_key)
|
11
21
|
end
|
12
22
|
|
23
|
+
def create(params={}, api_key=nil)
|
24
|
+
api_key ||= @api_key
|
25
|
+
response, api_key = Stripe.request(:post, url, api_key, params)
|
26
|
+
Util.convert_to_stripe_object(response, api_key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def all(params={}, api_key=nil)
|
30
|
+
api_key ||= @api_key
|
31
|
+
response, api_key = Stripe.request(:get, url, api_key, params)
|
32
|
+
Util.convert_to_stripe_object(response, api_key)
|
33
|
+
end
|
13
34
|
end
|
14
35
|
end
|
data/lib/stripe/util.rb
CHANGED
@@ -15,8 +15,8 @@ module Stripe
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.
|
19
|
-
|
18
|
+
def self.object_classes
|
19
|
+
@object_classes ||= {
|
20
20
|
'charge' => Charge,
|
21
21
|
'customer' => Customer,
|
22
22
|
'invoiceitem' => InvoiceItem,
|
@@ -26,24 +26,27 @@ module Stripe
|
|
26
26
|
'event' => Event,
|
27
27
|
'transfer' => Transfer,
|
28
28
|
'recipient' => Recipient,
|
29
|
+
'card' => Card,
|
29
30
|
'list' => ListObject
|
30
31
|
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.convert_to_stripe_object(resp, api_key)
|
31
35
|
case resp
|
32
36
|
when Array
|
33
37
|
resp.map { |i| convert_to_stripe_object(i, api_key) }
|
34
38
|
when Hash
|
35
|
-
# Try converting to a known object class. If none available, fall back to generic
|
36
|
-
|
37
|
-
klass = types[klass_name]
|
38
|
-
end
|
39
|
-
klass ||= StripeObject
|
40
|
-
klass.construct_from(resp, api_key)
|
39
|
+
# Try converting to a known object class. If none available, fall back to generic StripeObject
|
40
|
+
object_classes.fetch(resp[:object], StripeObject).construct_from(resp, api_key)
|
41
41
|
else
|
42
42
|
resp
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.file_readable(file)
|
47
|
+
# This is nominally equivalent to File.readable?, but that can
|
48
|
+
# report incorrect results on some more oddball filesystems
|
49
|
+
# (such as AFS)
|
47
50
|
begin
|
48
51
|
File.open(file) { |f| }
|
49
52
|
rescue
|
data/lib/stripe/version.rb
CHANGED
data/stripe.gemspec
CHANGED
@@ -16,8 +16,8 @@ spec = Gem::Specification.new do |s|
|
|
16
16
|
s.add_dependency('rest-client', '~> 1.4')
|
17
17
|
s.add_dependency('multi_json', '>= 1.0.4', '< 2')
|
18
18
|
|
19
|
-
s.add_development_dependency('mocha')
|
20
|
-
s.add_development_dependency('shoulda')
|
19
|
+
s.add_development_dependency('mocha', '~> 0.13.2')
|
20
|
+
s.add_development_dependency('shoulda', '~> 3.4.0')
|
21
21
|
s.add_development_dependency('test-unit')
|
22
22
|
s.add_development_dependency('rake')
|
23
23
|
|
data/test/test_helper.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
require 'test/unit'
|
3
3
|
require 'stripe'
|
4
|
-
require 'mocha'
|
4
|
+
require 'mocha/setup'
|
5
5
|
include Mocha
|
6
6
|
|
7
7
|
#monkeypatch request methods
|
8
|
-
module Stripe
|
8
|
+
module Stripe
|
9
9
|
@mock_rest_client = nil
|
10
10
|
|
11
11
|
def self.mock_rest_client=(mock_client)
|
@@ -42,16 +42,9 @@ def test_customer(params={})
|
|
42
42
|
:livemode => false,
|
43
43
|
:object => "customer",
|
44
44
|
:id => "c_test_customer",
|
45
|
-
:
|
46
|
-
|
47
|
-
|
48
|
-
:exp_month => 11,
|
49
|
-
:country => "US",
|
50
|
-
:exp_year => 2012,
|
51
|
-
:id => "cc_test_card",
|
52
|
-
:object => "card"
|
53
|
-
},
|
54
|
-
:created => 1304114758
|
45
|
+
:default_card => "cc_test_card",
|
46
|
+
:created => 1304114758,
|
47
|
+
:cards => test_card_array('c_test_customer')
|
55
48
|
}.merge(params)
|
56
49
|
end
|
57
50
|
|
@@ -88,12 +81,20 @@ end
|
|
88
81
|
|
89
82
|
def test_charge_array
|
90
83
|
{
|
91
|
-
:data => [test_charge, test_charge, test_charge],
|
84
|
+
:data => [test_charge, test_charge, test_charge],
|
92
85
|
:object => 'list',
|
93
86
|
:url => '/v1/charges'
|
94
87
|
}
|
95
88
|
end
|
96
89
|
|
90
|
+
def test_card_array(customer_id)
|
91
|
+
{
|
92
|
+
:data => [test_card, test_card, test_card],
|
93
|
+
:object => 'list',
|
94
|
+
:url => '/v1/customers/' + customer_id + '/cards'
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
97
98
|
def test_card(params={})
|
98
99
|
{
|
99
100
|
:type => "Visa",
|
@@ -102,7 +103,8 @@ def test_card(params={})
|
|
102
103
|
:country => "US",
|
103
104
|
:exp_year => 2012,
|
104
105
|
:id => "cc_test_card",
|
105
|
-
:
|
106
|
+
:customer => 'c_test_customer',
|
107
|
+
:object => "card"
|
106
108
|
}.merge(params)
|
107
109
|
end
|
108
110
|
|
@@ -112,7 +114,7 @@ def test_coupon(params={})
|
|
112
114
|
:duration_in_months => 3,
|
113
115
|
:percent_off => 25,
|
114
116
|
:id => "co_test_coupon",
|
115
|
-
:object => "coupon"
|
117
|
+
:object => "coupon"
|
116
118
|
}.merge(params)
|
117
119
|
end
|
118
120
|
|
data/test/test_stripe.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.expand_path('../test_helper', __FILE__)
|
3
3
|
require 'test/unit'
|
4
4
|
require 'shoulda'
|
5
|
-
require 'mocha'
|
5
|
+
require 'mocha/setup'
|
6
6
|
require 'pp'
|
7
7
|
require 'rest-client'
|
8
8
|
require 'cgi'
|
@@ -454,12 +454,6 @@ class TestStripeRuby < Test::Unit::TestCase
|
|
454
454
|
assert_equal c.mnemonic, "bar"
|
455
455
|
end
|
456
456
|
|
457
|
-
should "customers should have Card objects associated with their active_ard property" do
|
458
|
-
@mock.expects(:get).once.returns(test_response(test_customer))
|
459
|
-
c = Stripe::Customer.retrieve("test_customer")
|
460
|
-
assert c.active_card.kind_of?(Stripe::StripeObject) && c.active_card.object == 'card'
|
461
|
-
end
|
462
|
-
|
463
457
|
should "create should return a new customer" do
|
464
458
|
@mock.expects(:post).once.returns(test_response(test_customer))
|
465
459
|
c = Stripe::Customer.create
|
@@ -512,8 +506,51 @@ class TestStripeRuby < Test::Unit::TestCase
|
|
512
506
|
end
|
513
507
|
|
514
508
|
context "card tests" do
|
509
|
+
should "be able to create a new card for a customer" do
|
510
|
+
@mock.expects(:get).once.returns(test_response(test_customer))
|
511
|
+
customer = Stripe::Customer.retrieve("test_customer")
|
512
|
+
|
513
|
+
@mock.expects(:post).once.returns(test_response(test_card))
|
514
|
+
card = customer.cards.create(:card => 'card')
|
515
|
+
assert card.kind_of? Stripe::Card
|
516
|
+
end
|
517
|
+
|
518
|
+
should "be able to retrieve a card for a customer" do
|
519
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/c_test_customer", nil, nil).returns(test_response(test_customer))
|
520
|
+
customer = Stripe::Customer.retrieve("c_test_customer")
|
521
|
+
|
522
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/cards/cc_test_card", nil, nil).returns(test_response(test_card))
|
523
|
+
card = customer.cards.retrieve("cc_test_card")
|
524
|
+
assert card.kind_of? Stripe::Card
|
525
|
+
end
|
526
|
+
|
527
|
+
should "be able to list all cards for a customer" do
|
528
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/c_test_customer", nil, nil).returns(test_response(test_customer))
|
529
|
+
customer = Stripe::Customer.retrieve("c_test_customer")
|
530
|
+
|
531
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/cards", nil, nil).returns(test_response(test_card_array("c_test_customer")))
|
532
|
+
cards = customer.cards.all()
|
533
|
+
assert cards.data.kind_of? Array
|
534
|
+
cards.each do |card|
|
535
|
+
assert card.kind_of?(Stripe::Card)
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
should "be able to update a card for a customer" do
|
540
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/c_test_customer", nil, nil).returns(test_response(test_customer))
|
541
|
+
customer = Stripe::Customer.retrieve("c_test_customer")
|
542
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/cards/cc_test_card", nil, nil).returns(test_response(test_card))
|
543
|
+
card = customer.cards.retrieve("cc_test_card")
|
544
|
+
|
545
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/cards/cc_test_card", nil, "address_zip=zippy").returns(test_response(test_card(:address_zip => 'zippy')))
|
546
|
+
card.address_zip = "zippy"
|
547
|
+
card.save
|
548
|
+
|
549
|
+
assert_equal "zippy", card.address_zip
|
550
|
+
end
|
515
551
|
end
|
516
552
|
|
553
|
+
|
517
554
|
context "coupon tests" do
|
518
555
|
should "create should return a new coupon" do
|
519
556
|
@mock.expects(:post).once.returns(test_response(test_coupon))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -55,33 +55,33 @@ dependencies:
|
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ~>
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 0.13.2
|
61
61
|
type: :development
|
62
62
|
prerelease: false
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.13.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: shoulda
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ~>
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: 3.4.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
none: false
|
81
81
|
requirements:
|
82
|
-
- -
|
82
|
+
- - ~>
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
84
|
+
version: 3.4.0
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: test-unit
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/stripe/api_operations/list.rb
|
146
146
|
- lib/stripe/api_operations/update.rb
|
147
147
|
- lib/stripe/api_resource.rb
|
148
|
+
- lib/stripe/card.rb
|
148
149
|
- lib/stripe/charge.rb
|
149
150
|
- lib/stripe/coupon.rb
|
150
151
|
- lib/stripe/customer.rb
|
@@ -199,4 +200,3 @@ test_files:
|
|
199
200
|
- test/test_helper.rb
|
200
201
|
- test/test_stripe.rb
|
201
202
|
- test/test_stripe_with_active_support.rb
|
202
|
-
has_rdoc:
|