stripe 1.30.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +4 -0
- data/.github/ISSUE_TEMPLATE.md +5 -0
- data/.travis.yml +3 -14
- data/Gemfile +28 -4
- data/History.txt +180 -0
- data/README.md +147 -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 +43 -23
- data/lib/stripe/alipay_account.rb +20 -0
- data/lib/stripe/api_operations/create.rb +2 -2
- data/lib/stripe/api_operations/delete.rb +2 -2
- data/lib/stripe/api_operations/list.rb +2 -3
- data/lib/stripe/api_operations/request.rb +9 -3
- data/lib/stripe/api_operations/save.rb +85 -0
- data/lib/stripe/api_resource.rb +38 -5
- 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 +13 -4
- 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 +38 -20
- data/lib/stripe/country_spec.rb +9 -0
- data/lib/stripe/coupon.rb +1 -1
- data/lib/stripe/customer.rb +12 -10
- data/lib/stripe/dispute.rb +4 -5
- data/lib/stripe/errors.rb +92 -0
- data/lib/stripe/file_upload.rb +1 -1
- data/lib/stripe/invoice.rb +7 -7
- data/lib/stripe/invoice_item.rb +1 -1
- data/lib/stripe/list_object.rb +8 -7
- data/lib/stripe/order.rb +12 -4
- 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_client.rb +396 -0
- data/lib/stripe/stripe_object.rb +167 -91
- data/lib/stripe/stripe_response.rb +48 -0
- 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 +4 -5
- data/lib/stripe/util.rb +105 -33
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe.rb +69 -266
- data/spec/fixtures.json +1409 -0
- data/spec/fixtures.yaml +1153 -0
- data/spec/spec.json +19949 -0
- data/spec/spec.yaml +15504 -0
- data/stripe.gemspec +5 -18
- data/test/api_fixtures.rb +29 -0
- data/test/api_stub_helpers.rb +125 -0
- data/test/stripe/account_test.rb +163 -211
- data/test/stripe/alipay_account_test.rb +19 -0
- data/test/stripe/api_operations_test.rb +31 -0
- data/test/stripe/api_resource_test.rb +174 -340
- data/test/stripe/apple_pay_domain_test.rb +33 -0
- data/test/stripe/application_fee_refund_test.rb +22 -31
- data/test/stripe/application_fee_test.rb +6 -14
- data/test/stripe/balance_test.rb +3 -3
- data/test/stripe/bank_account_test.rb +41 -0
- data/test/stripe/bitcoin_receiver_test.rb +51 -42
- data/test/stripe/bitcoin_transaction_test.rb +11 -19
- data/test/stripe/charge_test.rb +39 -98
- data/test/stripe/country_spec_test.rb +20 -0
- data/test/stripe/coupon_test.rb +35 -11
- data/test/stripe/customer_card_test.rb +25 -46
- data/test/stripe/customer_test.rb +89 -61
- data/test/stripe/dispute_test.rb +28 -31
- data/test/stripe/errors_test.rb +18 -0
- data/test/stripe/file_upload_test.rb +32 -24
- data/test/stripe/invoice_item_test.rb +55 -0
- data/test/stripe/invoice_test.rb +50 -24
- data/test/stripe/list_object_test.rb +57 -45
- data/test/stripe/order_return_test.rb +21 -0
- data/test/stripe/order_test.rb +41 -34
- data/test/stripe/plan_test.rb +52 -0
- data/test/stripe/product_test.rb +31 -25
- data/test/stripe/recipient_card_test.rb +23 -40
- data/test/stripe/recipient_test.rb +50 -0
- data/test/stripe/refund_test.rb +20 -36
- data/test/stripe/reversal_test.rb +27 -31
- data/test/stripe/sku_test.rb +39 -13
- data/test/stripe/source_test.rb +43 -0
- data/test/stripe/stripe_client_test.rb +428 -0
- data/test/stripe/stripe_object_test.rb +186 -13
- data/test/stripe/stripe_response_test.rb +46 -0
- data/test/stripe/subscription_item_test.rb +54 -0
- data/test/stripe/subscription_test.rb +40 -52
- data/test/stripe/three_d_secure_test.rb +23 -0
- data/test/stripe/transfer_test.rb +38 -13
- data/test/stripe/util_test.rb +48 -16
- data/test/stripe_test.rb +25 -0
- data/test/test_data.rb +5 -621
- data/test/test_helper.rb +24 -24
- metadata +60 -139
- 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/test/stripe/charge_refund_test.rb +0 -55
- data/test/stripe/metadata_test.rb +0 -129
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
|
+
resp, opts = request(:post, resource_url + '/reject', params, opts)
|
41
|
+
initialize_from(resp.data, 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
|
|
@@ -80,18 +93,18 @@ module Stripe
|
|
80
93
|
|
81
94
|
def deauthorize(client_id, opts={})
|
82
95
|
opts = {:api_base => Stripe.connect_base}.merge(Util.normalize_opts(opts))
|
83
|
-
|
96
|
+
resp, opts = request(:post, '/oauth/deauthorize', { 'client_id' => client_id, 'stripe_user_id' => self.id }, opts)
|
84
97
|
opts.delete(:api_base) # the api_base here is a one-off, don't persist it
|
85
|
-
Util.convert_to_stripe_object(
|
98
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
86
99
|
end
|
87
100
|
|
88
101
|
ARGUMENT_NOT_PROVIDED = Object.new
|
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
|
@@ -2,8 +2,8 @@ module Stripe
|
|
2
2
|
module APIOperations
|
3
3
|
module Create
|
4
4
|
def create(params={}, opts={})
|
5
|
-
|
6
|
-
Util.convert_to_stripe_object(
|
5
|
+
resp, opts = request(:post, resource_url, params, opts)
|
6
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -3,8 +3,8 @@ module Stripe
|
|
3
3
|
module Delete
|
4
4
|
def delete(params={}, opts={})
|
5
5
|
opts = Util.normalize_opts(opts)
|
6
|
-
|
7
|
-
initialize_from(
|
6
|
+
resp, opts = request(:delete, resource_url, params, opts)
|
7
|
+
initialize_from(resp.data, opts)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -3,10 +3,9 @@ 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
|
-
|
9
|
-
obj = ListObject.construct_from(
|
7
|
+
resp, opts = request(:get, resource_url, filters, opts)
|
8
|
+
obj = ListObject.construct_from(resp.data, opts)
|
10
9
|
|
11
10
|
# set filters so that we can fetch the same limit, expansions, and
|
12
11
|
# predicates when accessing the next and previous pages
|
@@ -2,17 +2,23 @@ module Stripe
|
|
2
2
|
module APIOperations
|
3
3
|
module Request
|
4
4
|
module ClassMethods
|
5
|
-
OPTS_KEYS_TO_PERSIST = Set[:api_key, :api_base, :stripe_account, :stripe_version]
|
5
|
+
OPTS_KEYS_TO_PERSIST = Set[:api_key, :api_base, :client, :stripe_account, :stripe_version]
|
6
6
|
|
7
7
|
def request(method, url, params={}, opts={})
|
8
8
|
opts = Util.normalize_opts(opts)
|
9
|
+
opts[:client] ||= StripeClient.active_client
|
9
10
|
|
10
11
|
headers = opts.clone
|
11
12
|
api_key = headers.delete(:api_key)
|
12
13
|
api_base = headers.delete(:api_base)
|
14
|
+
client = headers.delete(:client)
|
13
15
|
# Assume all remaining opts must be headers
|
14
16
|
|
15
|
-
|
17
|
+
resp, opts[:api_key] = client.execute_request(
|
18
|
+
method, url,
|
19
|
+
api_base: api_base, api_key: api_key,
|
20
|
+
headers: headers, params: params
|
21
|
+
)
|
16
22
|
|
17
23
|
# Hash#select returns an array before 1.9
|
18
24
|
opts_to_persist = {}
|
@@ -22,7 +28,7 @@ module Stripe
|
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
25
|
-
[
|
31
|
+
[resp, opts_to_persist]
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
@@ -0,0 +1,85 @@
|
|
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
|
+
resp, opts = request(:post, "#{resource_url}/#{id}", params, opts)
|
25
|
+
Util.convert_to_stripe_object(resp.data, 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
|
+
resp, opts = request(:post, save_url, values, opts)
|
61
|
+
initialize_from(resp.data, opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.included(base)
|
65
|
+
base.extend(ClassMethods)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def save_url
|
71
|
+
# This switch essentially allows us "upsert"-like functionality. If the
|
72
|
+
# API resource doesn't have an ID set (suggesting that it's new) and
|
73
|
+
# its class responds to .create (which comes from
|
74
|
+
# Stripe::APIOperations::Create), then use the URL to create a new
|
75
|
+
# resource. Otherwise, generate a URL based on the object's identifier
|
76
|
+
# for a normal update.
|
77
|
+
if self[:id] == nil && self.class.respond_to?(:create)
|
78
|
+
self.class.resource_url
|
79
|
+
else
|
80
|
+
resource_url
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/stripe/api_resource.rb
CHANGED
@@ -2,27 +2,60 @@ 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
|
-
|
25
|
-
initialize_from(
|
57
|
+
resp, opts = request(:get, resource_url, @retrieve_params)
|
58
|
+
initialize_from(resp.data, opts)
|
26
59
|
end
|
27
60
|
|
28
61
|
def self.retrieve(id, opts={})
|
@@ -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,17 +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
|
-
def
|
7
|
+
def verify(params={}, opts={})
|
8
|
+
resp, opts = request(:post, resource_url + '/verify', params, opts)
|
9
|
+
initialize_from(resp.data, opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def resource_url
|
8
13
|
if respond_to?(:customer)
|
9
|
-
"#{Customer.
|
14
|
+
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
|
10
15
|
elsif respond_to?(:account)
|
11
|
-
"#{Account.
|
16
|
+
"#{Account.resource_url}/#{CGI.escape(account)}/external_accounts/#{CGI.escape(id)}"
|
12
17
|
end
|
13
18
|
end
|
14
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
|
+
|
15
24
|
def self.retrieve(id, opts=nil)
|
16
25
|
raise NotImplementedError.new("Bank accounts cannot be retrieved without an account ID. Retrieve a bank account using account.external_accounts.retrieve('card_id')")
|
17
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? && self.customer != ""
|
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,61 +2,79 @@ 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
|
+
resp, opts = request(:post, refund_url, params, opts)
|
24
|
+
initialize_from(resp.data, opts)
|
25
|
+
end
|
10
26
|
end
|
11
27
|
|
12
28
|
def capture(params={}, opts={})
|
13
|
-
|
14
|
-
initialize_from(
|
29
|
+
resp, opts = request(:post, capture_url, params, opts)
|
30
|
+
initialize_from(resp.data, opts)
|
15
31
|
end
|
16
32
|
|
17
33
|
def update_dispute(params={}, opts={})
|
18
|
-
|
19
|
-
initialize_from({ :dispute =>
|
34
|
+
resp, opts = request(:post, dispute_url, params, opts)
|
35
|
+
initialize_from({ :dispute => resp.data }, opts, true)
|
20
36
|
dispute
|
21
37
|
end
|
22
38
|
|
23
39
|
def close_dispute(params={}, opts={})
|
24
|
-
|
25
|
-
initialize_from(
|
40
|
+
resp, opts = request(:post, close_dispute_url, params, opts)
|
41
|
+
initialize_from(resp.data, opts)
|
26
42
|
end
|
27
43
|
|
28
44
|
def mark_as_fraudulent
|
29
45
|
params = {
|
30
46
|
:fraud_details => { :user_report => 'fraudulent' }
|
31
47
|
}
|
32
|
-
|
33
|
-
initialize_from(
|
48
|
+
resp, opts = request(:post, resource_url, params)
|
49
|
+
initialize_from(resp.data, opts)
|
34
50
|
end
|
35
51
|
|
36
52
|
def mark_as_safe
|
37
53
|
params = {
|
38
54
|
:fraud_details => { :user_report => 'safe' }
|
39
55
|
}
|
40
|
-
|
41
|
-
initialize_from(
|
56
|
+
resp, opts = request(:post, resource_url, params)
|
57
|
+
initialize_from(resp.data, 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