stripe 1.31.0 → 1.58.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +5 -0
- data/.travis.yml +2 -12
- data/Gemfile +29 -4
- data/History.txt +168 -0
- data/README.md +134 -0
- data/Rakefile +10 -0
- data/VERSION +1 -1
- data/bin/stripe-console +12 -5
- data/lib/data/ca-certificates.crt +3868 -5114
- data/lib/stripe/account.rb +41 -21
- data/lib/stripe/alipay_account.rb +20 -0
- data/lib/stripe/api_operations/create.rb +1 -1
- data/lib/stripe/api_operations/delete.rb +1 -1
- data/lib/stripe/api_operations/list.rb +1 -2
- data/lib/stripe/api_operations/save.rb +87 -0
- data/lib/stripe/api_resource.rb +37 -4
- data/lib/stripe/apple_pay_domain.rb +12 -0
- data/lib/stripe/application_fee.rb +8 -8
- data/lib/stripe/application_fee_refund.rb +7 -3
- data/lib/stripe/balance_transaction.rb +1 -1
- data/lib/stripe/bank_account.rb +9 -5
- data/lib/stripe/bitcoin_receiver.rb +6 -6
- data/lib/stripe/bitcoin_transaction.rb +1 -1
- data/lib/stripe/card.rb +9 -5
- data/lib/stripe/charge.rb +30 -12
- data/lib/stripe/country_spec.rb +9 -0
- data/lib/stripe/coupon.rb +1 -1
- data/lib/stripe/customer.rb +6 -4
- data/lib/stripe/dispute.rb +2 -2
- data/lib/stripe/errors.rb +82 -0
- data/lib/stripe/file_upload.rb +1 -1
- data/lib/stripe/invoice.rb +3 -3
- data/lib/stripe/invoice_item.rb +1 -1
- data/lib/stripe/list_object.rb +7 -6
- data/lib/stripe/order.rb +10 -2
- data/lib/stripe/order_return.rb +9 -0
- data/lib/stripe/plan.rb +1 -1
- data/lib/stripe/product.rb +2 -10
- data/lib/stripe/recipient.rb +1 -1
- data/lib/stripe/refund.rb +1 -1
- data/lib/stripe/reversal.rb +7 -3
- data/lib/stripe/singleton_api_resource.rb +3 -3
- data/lib/stripe/sku.rb +2 -2
- data/lib/stripe/source.rb +11 -0
- data/lib/stripe/stripe_object.rb +167 -91
- data/lib/stripe/subscription.rb +15 -9
- data/lib/stripe/subscription_item.rb +12 -0
- data/lib/stripe/three_d_secure.rb +9 -0
- data/lib/stripe/transfer.rb +3 -4
- data/lib/stripe/util.rb +100 -28
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe.rb +283 -140
- data/stripe.gemspec +5 -18
- data/test/stripe/account_test.rb +55 -9
- data/test/stripe/alipay_account_test.rb +11 -0
- data/test/stripe/api_operations_test.rb +31 -0
- data/test/stripe/api_resource_test.rb +204 -10
- data/test/stripe/apple_pay_domain_test.rb +34 -0
- data/test/stripe/application_fee_test.rb +8 -5
- data/test/stripe/bitcoin_receiver_test.rb +2 -2
- data/test/stripe/charge_refund_test.rb +12 -0
- data/test/stripe/charge_test.rb +32 -4
- data/test/stripe/country_spec_test.rb +43 -0
- data/test/stripe/coupon_test.rb +9 -1
- data/test/stripe/customer_card_test.rb +2 -2
- data/test/stripe/customer_test.rb +24 -1
- data/test/stripe/dispute_test.rb +8 -0
- data/test/stripe/errors_test.rb +18 -0
- data/test/stripe/invoice_item_test.rb +19 -0
- data/test/stripe/invoice_test.rb +27 -1
- data/test/stripe/list_object_test.rb +36 -15
- data/test/stripe/order_return_test.rb +25 -0
- data/test/stripe/order_test.rb +21 -1
- data/test/stripe/plan_test.rb +31 -0
- data/test/stripe/product_test.rb +17 -7
- data/test/stripe/recipient_card_test.rb +2 -2
- data/test/stripe/recipient_test.rb +21 -0
- data/test/stripe/refund_test.rb +10 -1
- data/test/stripe/sku_test.rb +15 -6
- data/test/stripe/source_test.rb +83 -0
- data/test/stripe/stripe_object_test.rb +180 -11
- data/test/stripe/subscription_item_test.rb +76 -0
- data/test/stripe/subscription_test.rb +161 -37
- data/test/stripe/three_d_secure_test.rb +22 -0
- data/test/stripe/transfer_test.rb +8 -0
- data/test/stripe/util_test.rb +48 -16
- data/test/stripe_test.rb +58 -0
- data/test/test_data.rb +337 -27
- data/test/test_helper.rb +7 -3
- metadata +47 -133
- data/README.rdoc +0 -68
- data/gemfiles/default-with-activesupport.gemfile +0 -10
- data/gemfiles/json.gemfile +0 -12
- data/gemfiles/yajl.gemfile +0 -12
- data/lib/stripe/api_operations/update.rb +0 -58
- data/lib/stripe/errors/api_connection_error.rb +0 -4
- data/lib/stripe/errors/api_error.rb +0 -4
- data/lib/stripe/errors/authentication_error.rb +0 -4
- data/lib/stripe/errors/card_error.rb +0 -12
- data/lib/stripe/errors/invalid_request_error.rb +0 -11
- data/lib/stripe/errors/rate_limit_error.rb +0 -4
- data/lib/stripe/errors/stripe_error.rb +0 -26
data/lib/stripe/account.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Account < APIResource
|
3
|
+
extend Gem::Deprecate
|
3
4
|
extend Stripe::APIOperations::Create
|
4
|
-
include Stripe::APIOperations::Delete
|
5
5
|
extend Stripe::APIOperations::List
|
6
|
-
include Stripe::APIOperations::
|
6
|
+
include Stripe::APIOperations::Delete
|
7
|
+
include Stripe::APIOperations::Save
|
8
|
+
|
9
|
+
save_nested_resource :external_account
|
7
10
|
|
8
|
-
|
11
|
+
# This method is deprecated. Please use `#external_account=` instead.
|
12
|
+
save_nested_resource :bank_account
|
13
|
+
deprecate :bank_account=, "#external_account=", 2017, 8
|
14
|
+
|
15
|
+
def resource_url
|
9
16
|
if self['id']
|
10
17
|
super
|
11
18
|
else
|
@@ -25,10 +32,15 @@ module Stripe
|
|
25
32
|
opts = id
|
26
33
|
id = nil
|
27
34
|
end
|
28
|
-
|
29
35
|
super(id, opts)
|
30
36
|
end
|
31
37
|
|
38
|
+
def reject(params={}, opts={})
|
39
|
+
opts = Util.normalize_opts(opts)
|
40
|
+
response, opts = request(:post, resource_url + '/reject', params, opts)
|
41
|
+
initialize_from(response, opts)
|
42
|
+
end
|
43
|
+
|
32
44
|
# Somewhat unfortunately, we attempt to do a special encoding trick when
|
33
45
|
# serializing `additional_owners` under an account: when updating a value,
|
34
46
|
# we actually send the update parameters up as an integer-indexed hash
|
@@ -52,21 +64,22 @@ module Stripe
|
|
52
64
|
#
|
53
65
|
# We're trying to get this overturned on the server side, but for now,
|
54
66
|
# patch in a special allowance.
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
67
|
+
def serialize_params(options = {})
|
68
|
+
serialize_params_account(self, super)
|
69
|
+
end
|
70
|
+
|
71
|
+
def serialize_params_account(obj, update_hash)
|
72
|
+
if entity = @values[:legal_entity]
|
73
|
+
if owners = entity[:additional_owners]
|
74
|
+
entity_update = update_hash[:legal_entity] ||= {}
|
75
|
+
entity_update[:additional_owners] =
|
76
|
+
serialize_additional_owners(entity, owners)
|
64
77
|
end
|
65
78
|
end
|
66
79
|
update_hash
|
67
80
|
end
|
68
81
|
|
69
|
-
def protected_fields
|
82
|
+
def self.protected_fields
|
70
83
|
[:legal_entity]
|
71
84
|
end
|
72
85
|
|
@@ -89,9 +102,9 @@ module Stripe
|
|
89
102
|
|
90
103
|
private
|
91
104
|
|
92
|
-
def
|
93
|
-
original_value =
|
94
|
-
if original_value && original_value.length >
|
105
|
+
def serialize_additional_owners(legal_entity, additional_owners)
|
106
|
+
original_value = legal_entity.instance_variable_get(:@original_values)[:additional_owners]
|
107
|
+
if original_value && original_value.length > additional_owners.length
|
95
108
|
# url params provide no mechanism for deleting an item in an array,
|
96
109
|
# just overwriting the whole array or adding new items. So let's not
|
97
110
|
# allow deleting without a full overwrite until we have a solution.
|
@@ -101,10 +114,17 @@ module Stripe
|
|
101
114
|
end
|
102
115
|
|
103
116
|
update_hash = {}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
117
|
+
additional_owners.each_with_index do |v, i|
|
118
|
+
# We will almost always see a StripeObject except in the case of a Hash
|
119
|
+
# that's been appended to an array of `additional_owners`. We may be
|
120
|
+
# able to normalize that ugliness by using an array proxy object with
|
121
|
+
# StripeObjects that can detect appends and replace a hash with a
|
122
|
+
# StripeObject.
|
123
|
+
update = v.is_a?(StripeObject) ? v.serialize_params : v
|
124
|
+
|
125
|
+
if update != {} && (!original_value ||
|
126
|
+
update != legal_entity.serialize_params_value(original_value[i], nil, false, true))
|
127
|
+
update_hash[i.to_s] = update
|
108
128
|
end
|
109
129
|
end
|
110
130
|
update_hash
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Stripe
|
2
|
+
class AlipayAccount < APIResource
|
3
|
+
include Stripe::APIOperations::Save
|
4
|
+
include Stripe::APIOperations::Delete
|
5
|
+
|
6
|
+
def resource_url
|
7
|
+
if respond_to?(:customer) && !self.customer.nil?
|
8
|
+
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.update(id, params=nil, opts=nil)
|
13
|
+
raise NotImplementedError.new("Alipay accounts cannot be updated without a customer ID. Update an Alipay account by `a = customer.sources.retrieve('alipay_account_id'); a.save`")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.retrieve(id, opts=nil)
|
17
|
+
raise NotImplementedError.new("Alipay accounts cannot be retrieved without a customer ID. Retrieve an Alipay account using customer.sources.retrieve('alipay_account_id')")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -3,9 +3,8 @@ module Stripe
|
|
3
3
|
module List
|
4
4
|
def list(filters={}, opts={})
|
5
5
|
opts = Util.normalize_opts(opts)
|
6
|
-
opts = @opts.merge(opts) if @opts
|
7
6
|
|
8
|
-
response, opts = request(:get,
|
7
|
+
response, opts = request(:get, resource_url, filters, opts)
|
9
8
|
obj = ListObject.construct_from(response, opts)
|
10
9
|
|
11
10
|
# set filters so that we can fetch the same limit, expansions, and
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Stripe
|
2
|
+
module APIOperations
|
3
|
+
module Save
|
4
|
+
module ClassMethods
|
5
|
+
# Updates an API resource
|
6
|
+
#
|
7
|
+
# Updates the identified resource with the passed in parameters.
|
8
|
+
#
|
9
|
+
# ==== Attributes
|
10
|
+
#
|
11
|
+
# * +id+ - ID of the resource to update.
|
12
|
+
# * +params+ - A hash of parameters to pass to the API
|
13
|
+
# * +opts+ - A Hash of additional options (separate from the params /
|
14
|
+
# object values) to be added to the request. E.g. to allow for an
|
15
|
+
# idempotency_key to be passed in the request headers, or for the
|
16
|
+
# api_key to be overwritten. See {APIOperations::Request.request}.
|
17
|
+
def update(id, params={}, opts={})
|
18
|
+
params.each do |k, v|
|
19
|
+
if self.protected_fields.include?(k)
|
20
|
+
raise ArgumentError, "Cannot update protected field: #{k}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
response, opts = request(:post, "#{resource_url}/#{id}", params, opts)
|
25
|
+
Util.convert_to_stripe_object(response, opts)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creates or updates an API resource.
|
30
|
+
#
|
31
|
+
# If the resource doesn't yet have an assigned ID and the resource is one
|
32
|
+
# that can be created, then the method attempts to create the resource.
|
33
|
+
# The resource is updated otherwise.
|
34
|
+
#
|
35
|
+
# ==== Attributes
|
36
|
+
#
|
37
|
+
# * +params+ - Overrides any parameters in the resource's serialized data
|
38
|
+
# and includes them in the create or update. If +:req_url:+ is included
|
39
|
+
# in the list, it overrides the update URL used for the create or
|
40
|
+
# update.
|
41
|
+
# * +opts+ - A Hash of additional options (separate from the params /
|
42
|
+
# object values) to be added to the request. E.g. to allow for an
|
43
|
+
# idempotency_key to be passed in the request headers, or for the
|
44
|
+
# api_key to be overwritten. See {APIOperations::Request.request}.
|
45
|
+
def save(params={}, opts={})
|
46
|
+
# We started unintentionally (sort of) allowing attributes sent to
|
47
|
+
# +save+ to override values used during the update. So as not to break
|
48
|
+
# the API, this makes that official here.
|
49
|
+
update_attributes(params)
|
50
|
+
|
51
|
+
# Now remove any parameters that look like object attributes.
|
52
|
+
params = params.reject { |k, _| respond_to?(k) }
|
53
|
+
|
54
|
+
values = self.serialize_params(self).merge(params)
|
55
|
+
|
56
|
+
# note that id gets removed here our call to #url above has already
|
57
|
+
# generated a uri for this object with an identifier baked in
|
58
|
+
values.delete(:id)
|
59
|
+
|
60
|
+
response, opts = request(:post, save_url, values, opts)
|
61
|
+
initialize_from(response, opts)
|
62
|
+
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.included(base)
|
67
|
+
base.extend(ClassMethods)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def save_url
|
73
|
+
# This switch essentially allows us "upsert"-like functionality. If the
|
74
|
+
# API resource doesn't have an ID set (suggesting that it's new) and
|
75
|
+
# its class responds to .create (which comes from
|
76
|
+
# Stripe::APIOperations::Create), then use the URL to create a new
|
77
|
+
# resource. Otherwise, generate a URL based on the object's identifier
|
78
|
+
# for a normal update.
|
79
|
+
if self[:id] == nil && self.class.respond_to?(:create)
|
80
|
+
self.class.resource_url
|
81
|
+
else
|
82
|
+
resource_url
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/stripe/api_resource.rb
CHANGED
@@ -2,26 +2,59 @@ module Stripe
|
|
2
2
|
class APIResource < StripeObject
|
3
3
|
include Stripe::APIOperations::Request
|
4
4
|
|
5
|
+
# A flag that can be set a behavior that will cause this resource to be
|
6
|
+
# encoded and sent up along with an update of its parent resource. This is
|
7
|
+
# usually not desirable because resources are updated individually on their
|
8
|
+
# own endpoints, but there are certain cases, replacing a customer's source
|
9
|
+
# for example, where this is allowed.
|
10
|
+
attr_accessor :save_with_parent
|
11
|
+
|
5
12
|
def self.class_name
|
6
13
|
self.name.split('::')[-1]
|
7
14
|
end
|
8
15
|
|
9
|
-
def self.
|
16
|
+
def self.resource_url
|
10
17
|
if self == APIResource
|
11
18
|
raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Charge, Customer, etc.)')
|
12
19
|
end
|
13
20
|
"/v1/#{CGI.escape(class_name.downcase)}s"
|
14
21
|
end
|
15
22
|
|
16
|
-
|
23
|
+
# A metaprogramming call that specifies that a field of a resource can be
|
24
|
+
# its own type of API resource (say a nested card under an account for
|
25
|
+
# example), and if that resource is set, it should be transmitted to the
|
26
|
+
# API on a create or update. Doing so is not the default behavior because
|
27
|
+
# API resources should normally be persisted on their own RESTful
|
28
|
+
# endpoints.
|
29
|
+
def self.save_nested_resource(name)
|
30
|
+
define_method(:"#{name}=") do |value|
|
31
|
+
super(value)
|
32
|
+
|
33
|
+
# The parent setter will perform certain useful operations like
|
34
|
+
# converting to an APIResource if appropriate. Refresh our argument
|
35
|
+
# value to whatever it mutated to.
|
36
|
+
value = send(name)
|
37
|
+
|
38
|
+
# Note that the value may be subresource, but could also be a scalar
|
39
|
+
# (like a tokenized card's ID for example), so we check the type before
|
40
|
+
# setting #save_with_parent here.
|
41
|
+
if value.is_a?(APIResource)
|
42
|
+
value.save_with_parent = true
|
43
|
+
end
|
44
|
+
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def resource_url
|
17
50
|
unless id = self['id']
|
18
51
|
raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id')
|
19
52
|
end
|
20
|
-
"#{self.class.
|
53
|
+
"#{self.class.resource_url}/#{CGI.escape(id)}"
|
21
54
|
end
|
22
55
|
|
23
56
|
def refresh
|
24
|
-
response, opts = request(:get,
|
57
|
+
response, opts = request(:get, resource_url, @retrieve_params)
|
25
58
|
initialize_from(response, opts)
|
26
59
|
end
|
27
60
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Stripe
|
2
|
+
# Domains registered for Apple Pay on the Web
|
3
|
+
class ApplePayDomain < APIResource
|
4
|
+
extend Stripe::APIOperations::Create
|
5
|
+
include Stripe::APIOperations::Delete
|
6
|
+
extend Stripe::APIOperations::List
|
7
|
+
|
8
|
+
def self.resource_url
|
9
|
+
'/v1/apple_pay/domains'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -2,19 +2,19 @@ module Stripe
|
|
2
2
|
class ApplicationFee < APIResource
|
3
3
|
extend Stripe::APIOperations::List
|
4
4
|
|
5
|
-
def self.
|
5
|
+
def self.resource_url
|
6
6
|
'/v1/application_fees'
|
7
7
|
end
|
8
8
|
|
9
|
+
# If you don't need access to an updated fee object after the refund, it's
|
10
|
+
# more performant to just call `fee.refunds.create` directly.
|
9
11
|
def refund(params={}, opts={})
|
10
|
-
|
11
|
-
initialize_from(response, opts)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
12
|
+
self.refunds.create(params, opts)
|
15
13
|
|
16
|
-
|
17
|
-
|
14
|
+
# now that a refund has been created, we expect the state of this object
|
15
|
+
# to change as well (i.e. `refunded` will now be `true`) so refresh it
|
16
|
+
# from the server
|
17
|
+
self.refresh
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module Stripe
|
2
2
|
class ApplicationFeeRefund < APIResource
|
3
|
-
include Stripe::APIOperations::
|
3
|
+
include Stripe::APIOperations::Save
|
4
4
|
extend Stripe::APIOperations::List
|
5
5
|
|
6
|
-
def
|
7
|
-
"#{ApplicationFee.
|
6
|
+
def resource_url
|
7
|
+
"#{ApplicationFee.resource_url}/#{CGI.escape(fee)}/refunds/#{CGI.escape(id)}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.update(id, params=nil, opts=nil)
|
11
|
+
raise NotImplementedError.new("Refunds cannot be updated without an application fee ID. Update a refund by using `a = appfee.refunds.retrieve('refund_id'); a.save`")
|
8
12
|
end
|
9
13
|
|
10
14
|
def self.retrieve(id, api_key=nil)
|
data/lib/stripe/bank_account.rb
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
module Stripe
|
2
2
|
class BankAccount < APIResource
|
3
|
-
include Stripe::APIOperations::
|
3
|
+
include Stripe::APIOperations::Save
|
4
4
|
include Stripe::APIOperations::Delete
|
5
5
|
extend Stripe::APIOperations::List
|
6
6
|
|
7
7
|
def verify(params={}, opts={})
|
8
|
-
response, opts = request(:post,
|
8
|
+
response, opts = request(:post, resource_url + '/verify', params, opts)
|
9
9
|
initialize_from(response, opts)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def resource_url
|
13
13
|
if respond_to?(:customer)
|
14
|
-
"#{Customer.
|
14
|
+
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
|
15
15
|
elsif respond_to?(:account)
|
16
|
-
"#{Account.
|
16
|
+
"#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
def self.update(id, params=nil, opts=nil)
|
21
|
+
raise NotImplementedError.new("Bank accounts cannot be updated without an account ID. Update a bank account by using `a = account.external_accounts.retrieve('card_id'); a.save`")
|
22
|
+
end
|
23
|
+
|
20
24
|
def self.retrieve(id, opts=nil)
|
21
25
|
raise NotImplementedError.new("Bank accounts cannot be retrieved without an account ID. Retrieve a bank account using account.external_accounts.retrieve('card_id')")
|
22
26
|
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Stripe
|
2
2
|
class BitcoinReceiver < APIResource
|
3
3
|
extend Stripe::APIOperations::Create
|
4
|
-
include Stripe::APIOperations::
|
4
|
+
include Stripe::APIOperations::Save
|
5
5
|
include Stripe::APIOperations::Delete
|
6
6
|
extend Stripe::APIOperations::List
|
7
7
|
|
8
|
-
def self.
|
8
|
+
def self.resource_url
|
9
9
|
"/v1/bitcoin/receivers"
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
if respond_to?(:customer)
|
14
|
-
"#{Customer.
|
12
|
+
def resource_url
|
13
|
+
if respond_to?(:customer) && !self.customer.nil?
|
14
|
+
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
|
15
15
|
else
|
16
|
-
"#{self.class.
|
16
|
+
"#{self.class.resource_url}/#{CGI.escape(id)}"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/stripe/card.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Card < APIResource
|
3
|
-
include Stripe::APIOperations::
|
3
|
+
include Stripe::APIOperations::Save
|
4
4
|
include Stripe::APIOperations::Delete
|
5
5
|
extend Stripe::APIOperations::List
|
6
6
|
|
7
|
-
def
|
7
|
+
def resource_url
|
8
8
|
if respond_to?(:recipient)
|
9
|
-
"#{Recipient.
|
9
|
+
"#{Recipient.resource_url}/#{CGI.escape(recipient)}/cards/#{CGI.escape(id)}"
|
10
10
|
elsif respond_to?(:customer)
|
11
|
-
"#{Customer.
|
11
|
+
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
|
12
12
|
elsif respond_to?(:account)
|
13
|
-
"#{Account.
|
13
|
+
"#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.update(id, params=nil, opts=nil)
|
18
|
+
raise NotImplementedError.new("Cards cannot be updated without a customer ID. Update a card using `c = customer.sources.retrieve('card_id'); c.save`")
|
19
|
+
end
|
20
|
+
|
17
21
|
def self.retrieve(id, opts=nil)
|
18
22
|
raise NotImplementedError.new("Cards cannot be retrieved without a customer ID. Retrieve a card using customer.sources.retrieve('card_id')")
|
19
23
|
end
|
data/lib/stripe/charge.rb
CHANGED
@@ -2,11 +2,27 @@ module Stripe
|
|
2
2
|
class Charge < APIResource
|
3
3
|
extend Stripe::APIOperations::List
|
4
4
|
extend Stripe::APIOperations::Create
|
5
|
-
include Stripe::APIOperations::
|
5
|
+
include Stripe::APIOperations::Save
|
6
6
|
|
7
7
|
def refund(params={}, opts={})
|
8
|
-
|
9
|
-
|
8
|
+
# Old versions of charge objects included a `refunds` field that was just
|
9
|
+
# a vanilla array instead of a Stripe list object.
|
10
|
+
#
|
11
|
+
# Where possible, we'd still like to use the new refund endpoint (thus
|
12
|
+
# `self.refunds.create`), but detect the old API version by looking for
|
13
|
+
# an `Array` and fall back to the old refund URL if necessary so as to
|
14
|
+
# maintain internal compatibility.
|
15
|
+
unless self.refunds.is_a?(Array)
|
16
|
+
self.refunds.create(params, opts)
|
17
|
+
|
18
|
+
# now that a refund has been created, we expect the state of this object
|
19
|
+
# to change as well (i.e. `refunded` will now be `true`) so refresh it
|
20
|
+
# from the server
|
21
|
+
self.refresh
|
22
|
+
else
|
23
|
+
response, opts = request(:post, refund_url, params, opts)
|
24
|
+
initialize_from(response, opts)
|
25
|
+
end
|
10
26
|
end
|
11
27
|
|
12
28
|
def capture(params={}, opts={})
|
@@ -29,7 +45,7 @@ module Stripe
|
|
29
45
|
params = {
|
30
46
|
:fraud_details => { :user_report => 'fraudulent' }
|
31
47
|
}
|
32
|
-
response, opts = request(:post,
|
48
|
+
response, opts = request(:post, resource_url, params)
|
33
49
|
initialize_from(response, opts)
|
34
50
|
end
|
35
51
|
|
@@ -37,26 +53,28 @@ module Stripe
|
|
37
53
|
params = {
|
38
54
|
:fraud_details => { :user_report => 'safe' }
|
39
55
|
}
|
40
|
-
response, opts = request(:post,
|
56
|
+
response, opts = request(:post, resource_url, params)
|
41
57
|
initialize_from(response, opts)
|
42
58
|
end
|
43
59
|
|
44
60
|
private
|
45
61
|
|
46
|
-
def refund_url
|
47
|
-
url + '/refund'
|
48
|
-
end
|
49
|
-
|
50
62
|
def capture_url
|
51
|
-
|
63
|
+
resource_url + '/capture'
|
52
64
|
end
|
53
65
|
|
54
66
|
def dispute_url
|
55
|
-
|
67
|
+
resource_url + '/dispute'
|
56
68
|
end
|
57
69
|
|
58
70
|
def close_dispute_url
|
59
|
-
|
71
|
+
resource_url + '/dispute/close'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Note that this is actually the *old* refund URL and its use is no longer
|
75
|
+
# preferred.
|
76
|
+
def refund_url
|
77
|
+
resource_url + '/refund'
|
60
78
|
end
|
61
79
|
end
|
62
80
|
end
|
data/lib/stripe/coupon.rb
CHANGED
data/lib/stripe/customer.rb
CHANGED
@@ -2,9 +2,11 @@ module Stripe
|
|
2
2
|
class Customer < APIResource
|
3
3
|
extend Stripe::APIOperations::Create
|
4
4
|
include Stripe::APIOperations::Delete
|
5
|
-
include Stripe::APIOperations::
|
5
|
+
include Stripe::APIOperations::Save
|
6
6
|
extend Stripe::APIOperations::List
|
7
7
|
|
8
|
+
save_nested_resource :source
|
9
|
+
|
8
10
|
def add_invoice_item(params, opts={})
|
9
11
|
opts = @opts.merge(Util.normalize_opts(opts))
|
10
12
|
InvoiceItem.create(params.merge(:customer => id), opts)
|
@@ -61,15 +63,15 @@ module Stripe
|
|
61
63
|
private
|
62
64
|
|
63
65
|
def discount_url
|
64
|
-
|
66
|
+
resource_url + '/discount'
|
65
67
|
end
|
66
68
|
|
67
69
|
def subscription_url
|
68
|
-
|
70
|
+
resource_url + '/subscription'
|
69
71
|
end
|
70
72
|
|
71
73
|
def subscriptions_url
|
72
|
-
|
74
|
+
resource_url + '/subscriptions'
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|
data/lib/stripe/dispute.rb
CHANGED
@@ -2,7 +2,7 @@ module Stripe
|
|
2
2
|
class Dispute < APIResource
|
3
3
|
extend Stripe::APIOperations::List
|
4
4
|
extend Stripe::APIOperations::Create
|
5
|
-
include Stripe::APIOperations::
|
5
|
+
include Stripe::APIOperations::Save
|
6
6
|
|
7
7
|
def close(params={}, opts={})
|
8
8
|
response, opts = request(:post, close_url, params, opts)
|
@@ -10,7 +10,7 @@ module Stripe
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def close_url
|
13
|
-
|
13
|
+
resource_url + '/close'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|