stripe 3.2.0 → 5.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +10 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +80 -0
- data/.rubocop_todo.yml +33 -0
- data/.travis.yml +9 -7
- data/.vscode/extensions.json +7 -0
- data/.vscode/settings.json +8 -0
- data/CHANGELOG.md +876 -0
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +21 -21
- data/History.txt +1 -678
- data/README.md +195 -53
- data/Rakefile +18 -12
- data/VERSION +1 -1
- data/bin/stripe-console +5 -3
- data/lib/stripe/api_operations/create.rb +3 -1
- data/lib/stripe/api_operations/delete.rb +26 -2
- data/lib/stripe/api_operations/list.rb +3 -12
- data/lib/stripe/api_operations/nested_resource.rb +72 -0
- data/lib/stripe/api_operations/request.rb +33 -15
- data/lib/stripe/api_operations/save.rb +18 -9
- data/lib/stripe/api_resource.rb +60 -10
- data/lib/stripe/connection_manager.rb +159 -0
- data/lib/stripe/error_object.rb +94 -0
- data/lib/stripe/errors.rb +39 -19
- data/lib/stripe/instrumentation.rb +82 -0
- data/lib/stripe/list_object.rb +54 -22
- data/lib/stripe/multipart_encoder.rb +131 -0
- data/lib/stripe/oauth.rb +22 -14
- data/lib/stripe/object_types.rb +96 -0
- data/lib/stripe/{account.rb → resources/account.rb} +72 -34
- data/lib/stripe/resources/account_link.rb +9 -0
- data/lib/stripe/resources/alipay_account.rb +34 -0
- data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +4 -2
- data/lib/stripe/resources/application_fee.rb +13 -0
- data/lib/stripe/resources/application_fee_refund.rb +30 -0
- data/lib/stripe/{balance.rb → resources/balance.rb} +3 -1
- data/lib/stripe/{balance_transaction.rb → resources/balance_transaction.rb} +3 -5
- data/lib/stripe/resources/bank_account.rb +42 -0
- data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +6 -5
- data/lib/stripe/resources/bitcoin_transaction.rb +15 -0
- data/lib/stripe/resources/capability.rb +33 -0
- data/lib/stripe/resources/card.rb +37 -0
- data/lib/stripe/resources/charge.rb +22 -0
- data/lib/stripe/resources/checkout/session.rb +12 -0
- data/lib/stripe/{country_spec.rb → resources/country_spec.rb} +3 -5
- data/lib/stripe/{coupon.rb → resources/coupon.rb} +4 -2
- data/lib/stripe/resources/credit_note.rb +32 -0
- data/lib/stripe/resources/credit_note_line_item.rb +7 -0
- data/lib/stripe/resources/customer.rb +35 -0
- data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
- data/lib/stripe/resources/discount.rb +7 -0
- data/lib/stripe/resources/dispute.rb +21 -0
- data/lib/stripe/resources/ephemeral_key.rb +19 -0
- data/lib/stripe/{event.rb → resources/event.rb} +3 -1
- data/lib/stripe/resources/exchange_rate.rb +9 -0
- data/lib/stripe/resources/file.rb +34 -0
- data/lib/stripe/resources/file_link.rb +11 -0
- data/lib/stripe/resources/invoice.rb +73 -0
- data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +4 -2
- data/lib/stripe/{invoice_line_item.rb → resources/invoice_line_item.rb} +3 -1
- data/lib/stripe/resources/issuing/authorization.rb +33 -0
- data/lib/stripe/resources/issuing/card.rb +24 -0
- data/lib/stripe/resources/issuing/card_details.rb +9 -0
- data/lib/stripe/resources/issuing/cardholder.rb +13 -0
- data/lib/stripe/resources/issuing/dispute.rb +13 -0
- data/lib/stripe/resources/issuing/transaction.rb +12 -0
- data/lib/stripe/resources/login_link.rb +14 -0
- data/lib/stripe/resources/mandate.rb +7 -0
- data/lib/stripe/resources/order.rb +32 -0
- data/lib/stripe/{order_return.rb → resources/order_return.rb} +3 -5
- data/lib/stripe/resources/payment_intent.rb +42 -0
- data/lib/stripe/resources/payment_method.rb +32 -0
- data/lib/stripe/resources/payout.rb +22 -0
- data/lib/stripe/resources/person.rb +31 -0
- data/lib/stripe/{plan.rb → resources/plan.rb} +3 -1
- data/lib/stripe/{product.rb → resources/product.rb} +5 -3
- data/lib/stripe/resources/radar/early_fraud_warning.rb +11 -0
- data/lib/stripe/resources/radar/value_list.rb +14 -0
- data/lib/stripe/resources/radar/value_list_item.rb +13 -0
- data/lib/stripe/{recipient.rb → resources/recipient.rb} +5 -6
- data/lib/stripe/resources/recipient_transfer.rb +7 -0
- data/lib/stripe/{refund.rb → resources/refund.rb} +3 -1
- data/lib/stripe/resources/reporting/report_run.rb +12 -0
- data/lib/stripe/resources/reporting/report_type.rb +12 -0
- data/lib/stripe/resources/reversal.rb +29 -0
- data/lib/stripe/resources/review.rb +20 -0
- data/lib/stripe/resources/setup_intent.rb +32 -0
- data/lib/stripe/resources/sigma/scheduled_query_run.rb +15 -0
- data/lib/stripe/{sku.rb → resources/sku.rb} +5 -3
- data/lib/stripe/resources/source.rb +46 -0
- data/lib/stripe/resources/source_transaction.rb +7 -0
- data/lib/stripe/resources/subscription.rb +25 -0
- data/lib/stripe/resources/subscription_item.rb +25 -0
- data/lib/stripe/resources/subscription_schedule.rb +32 -0
- data/lib/stripe/resources/tax_id.rb +26 -0
- data/lib/stripe/resources/tax_rate.rb +11 -0
- data/lib/stripe/resources/terminal/connection_token.rb +11 -0
- data/lib/stripe/resources/terminal/location.rb +14 -0
- data/lib/stripe/resources/terminal/reader.rb +14 -0
- data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +3 -1
- data/lib/stripe/{token.rb → resources/token.rb} +3 -1
- data/lib/stripe/resources/topup.rb +22 -0
- data/lib/stripe/resources/transfer.rb +26 -0
- data/lib/stripe/resources/usage_record.rb +7 -0
- data/lib/stripe/resources/usage_record_summary.rb +7 -0
- data/lib/stripe/resources/webhook_endpoint.rb +12 -0
- data/lib/stripe/resources.rb +79 -0
- data/lib/stripe/singleton_api_resource.rb +10 -4
- data/lib/stripe/stripe_client.rb +658 -337
- data/lib/stripe/stripe_object.rb +248 -126
- data/lib/stripe/stripe_response.rb +55 -21
- data/lib/stripe/util.rb +145 -187
- data/lib/stripe/version.rb +3 -1
- data/lib/stripe/webhook.rb +27 -16
- data/lib/stripe.rb +139 -90
- data/stripe.gemspec +26 -14
- data/test/openapi/README.md +9 -0
- data/test/stripe/account_link_test.rb +18 -0
- data/test/stripe/account_test.rb +311 -101
- data/test/stripe/alipay_account_test.rb +21 -1
- data/test/stripe/api_operations_test.rb +57 -8
- data/test/stripe/api_resource_test.rb +359 -271
- data/test/stripe/apple_pay_domain_test.rb +26 -11
- data/test/stripe/application_fee_refund_test.rb +10 -8
- data/test/stripe/application_fee_test.rb +49 -3
- data/test/stripe/balance_test.rb +4 -2
- data/test/stripe/balance_transaction_test.rb +20 -0
- data/test/stripe/bank_account_test.rb +11 -11
- data/test/stripe/capability_test.rb +45 -0
- data/test/stripe/charge_test.rb +25 -18
- data/test/stripe/checkout/session_test.rb +41 -0
- data/test/stripe/connection_manager_test.rb +163 -0
- data/test/stripe/country_spec_test.rb +6 -4
- data/test/stripe/coupon_test.rb +29 -10
- data/test/stripe/credit_note_test.rb +90 -0
- data/test/stripe/customer_balance_transaction_test.rb +37 -0
- data/test/stripe/customer_card_test.rb +13 -17
- data/test/stripe/customer_test.rb +161 -49
- data/test/stripe/dispute_test.rb +19 -8
- data/test/stripe/ephemeral_key_test.rb +23 -14
- data/test/stripe/errors_test.rb +32 -9
- data/test/stripe/exchange_rate_test.rb +20 -0
- data/test/stripe/file_link_test.rb +41 -0
- data/test/stripe/file_test.rb +87 -0
- data/test/stripe/instrumentation_test.rb +74 -0
- data/test/stripe/invoice_item_test.rb +31 -18
- data/test/stripe/invoice_line_item_test.rb +3 -1
- data/test/stripe/invoice_test.rb +158 -39
- data/test/stripe/issuing/authorization_test.rb +72 -0
- data/test/stripe/issuing/card_test.rb +62 -0
- data/test/stripe/issuing/cardholder_test.rb +53 -0
- data/test/stripe/issuing/dispute_test.rb +45 -0
- data/test/stripe/issuing/transaction_test.rb +48 -0
- data/test/stripe/list_object_test.rb +120 -88
- data/test/stripe/login_link_test.rb +16 -14
- data/test/stripe/mandate_test.rb +14 -0
- data/test/stripe/multipart_encoder_test.rb +130 -0
- data/test/stripe/oauth_test.rb +69 -50
- data/test/stripe/order_return_test.rb +7 -5
- data/test/stripe/order_test.rb +39 -14
- data/test/stripe/payment_intent_test.rb +107 -0
- data/test/stripe/payment_method_test.rb +84 -0
- data/test/stripe/payout_test.rb +18 -9
- data/test/stripe/person_test.rb +46 -0
- data/test/stripe/plan_test.rb +67 -19
- data/test/stripe/product_test.rb +28 -14
- data/test/stripe/radar/early_fraud_warning_test.rb +22 -0
- data/test/stripe/radar/value_list_item_test.rb +48 -0
- data/test/stripe/radar/value_list_test.rb +61 -0
- data/test/stripe/recipient_test.rb +27 -13
- data/test/stripe/refund_test.rb +11 -9
- data/test/stripe/reporting/report_run_test.rb +33 -0
- data/test/stripe/reporting/report_type_test.rb +22 -0
- data/test/stripe/reversal_test.rb +12 -10
- data/test/stripe/review_test.rb +27 -0
- data/test/stripe/setup_intent_test.rb +84 -0
- data/test/stripe/sigma/scheduled_query_run_test.rb +22 -0
- data/test/stripe/sku_test.rb +24 -12
- data/test/stripe/source_test.rb +70 -19
- data/test/stripe/stripe_client_test.rb +867 -326
- data/test/stripe/stripe_object_test.rb +284 -182
- data/test/stripe/stripe_response_test.rb +73 -24
- data/test/stripe/subscription_item_test.rb +47 -15
- data/test/stripe/subscription_schedule_test.rb +82 -0
- data/test/stripe/subscription_test.rb +41 -19
- data/test/stripe/tax_id_test.rb +31 -0
- data/test/stripe/tax_rate_test.rb +43 -0
- data/test/stripe/terminal/connection_token_test.rb +16 -0
- data/test/stripe/terminal/location_test.rb +68 -0
- data/test/stripe/terminal/reader_test.rb +62 -0
- data/test/stripe/three_d_secure_test.rb +4 -2
- data/test/stripe/topup_test.rb +62 -0
- data/test/stripe/transfer_test.rb +55 -8
- data/test/stripe/usage_record_summary_test.rb +29 -0
- data/test/stripe/util_test.rb +173 -84
- data/test/stripe/webhook_endpoint_test.rb +59 -0
- data/test/stripe/webhook_test.rb +21 -17
- data/test/stripe_mock.rb +78 -0
- data/test/stripe_test.rb +6 -15
- data/test/test_data.rb +28 -26
- data/test/test_helper.rb +48 -29
- metadata +183 -70
- data/lib/stripe/alipay_account.rb +0 -22
- data/lib/stripe/application_fee.rb +0 -22
- data/lib/stripe/application_fee_refund.rb +0 -20
- data/lib/stripe/bank_account.rb +0 -30
- data/lib/stripe/bitcoin_transaction.rb +0 -11
- data/lib/stripe/card.rb +0 -27
- data/lib/stripe/charge.rb +0 -82
- data/lib/stripe/customer.rb +0 -79
- data/lib/stripe/dispute.rb +0 -17
- data/lib/stripe/ephemeral_key.rb +0 -18
- data/lib/stripe/file_upload.rb +0 -33
- data/lib/stripe/invoice.rb +0 -29
- data/lib/stripe/login_link.rb +0 -9
- data/lib/stripe/order.rb +0 -29
- data/lib/stripe/payout.rb +0 -18
- data/lib/stripe/recipient_transfer.rb +0 -6
- data/lib/stripe/reversal.rb +0 -20
- data/lib/stripe/source.rb +0 -23
- data/lib/stripe/subscription.rb +0 -33
- data/lib/stripe/subscription_item.rb +0 -14
- data/lib/stripe/transfer.rb +0 -18
- data/test/api_stub_helpers.rb +0 -0
- data/test/stripe/bitcoin_receiver_test.rb +0 -67
- data/test/stripe/bitcoin_transaction_test.rb +0 -19
- data/test/stripe/file_upload_test.rb +0 -66
- data/test/stripe/recipient_card_test.rb +0 -44
data/lib/stripe/list_object.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Stripe
|
2
4
|
class ListObject < StripeObject
|
3
5
|
include Enumerable
|
@@ -5,7 +7,7 @@ module Stripe
|
|
5
7
|
include Stripe::APIOperations::Request
|
6
8
|
include Stripe::APIOperations::Create
|
7
9
|
|
8
|
-
OBJECT_NAME =
|
10
|
+
OBJECT_NAME = "list"
|
9
11
|
|
10
12
|
# This accessor allows a `ListObject` to inherit various filters that were
|
11
13
|
# given to a predecessor. This allows for things like consistent limits,
|
@@ -15,8 +17,8 @@ module Stripe
|
|
15
17
|
# An empty list object. This is returned from +next+ when we know that
|
16
18
|
# there isn't a next page in order to replicate the behavior of the API
|
17
19
|
# when it attempts to return a page beyond the last.
|
18
|
-
def self.empty_list(opts={})
|
19
|
-
ListObject.construct_from({ :
|
20
|
+
def self.empty_list(opts = {})
|
21
|
+
ListObject.construct_from({ data: [] }, opts)
|
20
22
|
end
|
21
23
|
|
22
24
|
def initialize(*args)
|
@@ -24,12 +26,16 @@ module Stripe
|
|
24
26
|
self.filters = {}
|
25
27
|
end
|
26
28
|
|
27
|
-
def [](
|
28
|
-
case
|
29
|
+
def [](key)
|
30
|
+
case key
|
29
31
|
when String, Symbol
|
30
32
|
super
|
31
33
|
else
|
32
|
-
raise ArgumentError
|
34
|
+
raise ArgumentError,
|
35
|
+
"You tried to access the #{key.inspect} index, but ListObject " \
|
36
|
+
"types only support String keys. (HINT: List calls return an " \
|
37
|
+
"object with a 'data' (which is the data array). You likely " \
|
38
|
+
"want to call #data[#{key.inspect}])"
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
@@ -39,12 +45,22 @@ module Stripe
|
|
39
45
|
# Note that this method makes no effort to fetch a new page when it gets to
|
40
46
|
# the end of the current page's resources. See also +auto_paging_each+.
|
41
47
|
def each(&blk)
|
42
|
-
|
48
|
+
data.each(&blk)
|
43
49
|
end
|
44
50
|
|
45
51
|
# Iterates through each resource in all pages, making additional fetches to
|
46
52
|
# the API as necessary.
|
47
53
|
#
|
54
|
+
# The default iteration direction is forwards according to Stripe's API
|
55
|
+
# "natural" ordering direction -- newer objects first, and moving towards
|
56
|
+
# older objects.
|
57
|
+
#
|
58
|
+
# However, if the initial list object was fetched using an `ending_before`
|
59
|
+
# cursor (and only `ending_before`, `starting_after` cannot also be
|
60
|
+
# included), the method assumes that the user is trying to iterate
|
61
|
+
# backwards compared to natural ordering and returns results that way --
|
62
|
+
# older objects first, and moving towards newer objects.
|
63
|
+
#
|
48
64
|
# Note that this method will make as many API calls as necessary to fetch
|
49
65
|
# all resources. For more granular control, please see +each+ and
|
50
66
|
# +next_page+.
|
@@ -53,20 +69,31 @@ module Stripe
|
|
53
69
|
|
54
70
|
page = self
|
55
71
|
loop do
|
56
|
-
|
57
|
-
|
72
|
+
# Backward iterating activates if we have an `ending_before` constraint
|
73
|
+
# and _just_ an `ending_before` constraint. If `starting_after` was
|
74
|
+
# also used, we iterate forwards normally.
|
75
|
+
if filters.include?(:ending_before) &&
|
76
|
+
!filters.include?(:starting_after)
|
77
|
+
page.reverse_each(&blk)
|
78
|
+
page = page.previous_page
|
79
|
+
else
|
80
|
+
page.each(&blk)
|
81
|
+
page = page.next_page
|
82
|
+
end
|
83
|
+
|
58
84
|
break if page.empty?
|
59
85
|
end
|
60
86
|
end
|
61
87
|
|
62
88
|
# Returns true if the page object contains no elements.
|
63
89
|
def empty?
|
64
|
-
|
90
|
+
data.empty?
|
65
91
|
end
|
66
92
|
|
67
|
-
def retrieve(id, opts={})
|
93
|
+
def retrieve(id, opts = {})
|
68
94
|
id, retrieve_params = Util.normalize_id(id)
|
69
|
-
resp, opts = request(:get,"#{resource_url}/#{CGI.escape(id)}",
|
95
|
+
resp, opts = request(:get, "#{resource_url}/#{CGI.escape(id)}",
|
96
|
+
retrieve_params, opts)
|
70
97
|
Util.convert_to_stripe_object(resp.data, opts)
|
71
98
|
end
|
72
99
|
|
@@ -74,13 +101,12 @@ module Stripe
|
|
74
101
|
#
|
75
102
|
# This method will try to respect the limit of the current page. If none
|
76
103
|
# was given, the default limit will be fetched again.
|
77
|
-
def next_page(params={}, opts={})
|
78
|
-
return self.class.empty_list(opts)
|
104
|
+
def next_page(params = {}, opts = {})
|
105
|
+
return self.class.empty_list(opts) unless has_more
|
106
|
+
|
79
107
|
last_id = data.last.id
|
80
108
|
|
81
|
-
params = filters.merge(
|
82
|
-
:starting_after => last_id,
|
83
|
-
}).merge(params)
|
109
|
+
params = filters.merge(starting_after: last_id).merge(params)
|
84
110
|
|
85
111
|
list(params, opts)
|
86
112
|
end
|
@@ -89,19 +115,25 @@ module Stripe
|
|
89
115
|
#
|
90
116
|
# This method will try to respect the limit of the current page. If none
|
91
117
|
# was given, the default limit will be fetched again.
|
92
|
-
def previous_page(params={}, opts={})
|
118
|
+
def previous_page(params = {}, opts = {})
|
119
|
+
return self.class.empty_list(opts) unless has_more
|
120
|
+
|
93
121
|
first_id = data.first.id
|
94
122
|
|
95
|
-
params = filters.merge(
|
96
|
-
:ending_before => first_id,
|
97
|
-
}).merge(params)
|
123
|
+
params = filters.merge(ending_before: first_id).merge(params)
|
98
124
|
|
99
125
|
list(params, opts)
|
100
126
|
end
|
101
127
|
|
102
128
|
def resource_url
|
103
|
-
|
129
|
+
url ||
|
104
130
|
raise(ArgumentError, "List object does not contain a 'url' field.")
|
105
131
|
end
|
132
|
+
|
133
|
+
# Iterates through each resource in the page represented by the current
|
134
|
+
# `ListObject` in reverse.
|
135
|
+
def reverse_each(&blk)
|
136
|
+
data.reverse_each(&blk)
|
137
|
+
end
|
106
138
|
end
|
107
139
|
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
require "tempfile"
|
5
|
+
|
6
|
+
module Stripe
|
7
|
+
# Encodes parameters into a `multipart/form-data` payload as described by RFC
|
8
|
+
# 2388:
|
9
|
+
#
|
10
|
+
# https://tools.ietf.org/html/rfc2388
|
11
|
+
#
|
12
|
+
# This is most useful for transferring file-like objects.
|
13
|
+
#
|
14
|
+
# Parameters should be added with `#encode`. When ready, use `#body` to get
|
15
|
+
# the encoded result and `#content_type` to get the value that should be
|
16
|
+
# placed in the `Content-Type` header of a subsequent request (which includes
|
17
|
+
# a boundary value).
|
18
|
+
class MultipartEncoder
|
19
|
+
MULTIPART_FORM_DATA = "multipart/form-data"
|
20
|
+
|
21
|
+
# A shortcut for encoding a single set of parameters and finalizing a
|
22
|
+
# result.
|
23
|
+
#
|
24
|
+
# Returns an encoded body and the value that should be set in the content
|
25
|
+
# type header of a subsequent request.
|
26
|
+
def self.encode(params)
|
27
|
+
encoder = MultipartEncoder.new
|
28
|
+
encoder.encode(params)
|
29
|
+
encoder.close
|
30
|
+
[encoder.body, encoder.content_type]
|
31
|
+
end
|
32
|
+
|
33
|
+
# Gets the object's randomly generated boundary string.
|
34
|
+
attr_reader :boundary
|
35
|
+
|
36
|
+
# Initializes a new multipart encoder.
|
37
|
+
def initialize
|
38
|
+
# Kind of weird, but required by Rubocop because the unary plus operator
|
39
|
+
# is considered faster than `Stripe.new`.
|
40
|
+
@body = +""
|
41
|
+
|
42
|
+
# Chose the same number of random bytes that Go uses in its standard
|
43
|
+
# library implementation. Easily enough entropy to ensure that it won't
|
44
|
+
# be present in a file we're sending.
|
45
|
+
@boundary = SecureRandom.hex(30)
|
46
|
+
|
47
|
+
@closed = false
|
48
|
+
@first_field = true
|
49
|
+
end
|
50
|
+
|
51
|
+
# Gets the encoded body. `#close` must be called first.
|
52
|
+
def body
|
53
|
+
raise "object must be closed before getting body" unless @closed
|
54
|
+
|
55
|
+
@body
|
56
|
+
end
|
57
|
+
|
58
|
+
# Finalizes the object by writing the final boundary.
|
59
|
+
def close
|
60
|
+
raise "object already closed" if @closed
|
61
|
+
|
62
|
+
@body << "\r\n"
|
63
|
+
@body << "--#{@boundary}--"
|
64
|
+
|
65
|
+
@closed = true
|
66
|
+
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
# Gets the value including boundary that should be put into a multipart
|
71
|
+
# request's `Content-Type`.
|
72
|
+
def content_type
|
73
|
+
"#{MULTIPART_FORM_DATA}; boundary=#{@boundary}"
|
74
|
+
end
|
75
|
+
|
76
|
+
# Encodes a set of parameters to the body.
|
77
|
+
#
|
78
|
+
# Note that parameters are expected to be a hash, but a "flat" hash such
|
79
|
+
# that complex substructures like hashes and arrays have already been
|
80
|
+
# appropriately Stripe-encoded. Pass a complex structure through
|
81
|
+
# `Util.flatten_params` first before handing it off to this method.
|
82
|
+
def encode(params)
|
83
|
+
raise "no more parameters can be written to closed object" if @closed
|
84
|
+
|
85
|
+
params.each do |name, val|
|
86
|
+
if val.is_a?(::File) || val.is_a?(::Tempfile)
|
87
|
+
write_field(name, val.read, filename: ::File.basename(val.path))
|
88
|
+
elsif val.respond_to?(:read)
|
89
|
+
write_field(name, val.read, filename: "blob")
|
90
|
+
else
|
91
|
+
write_field(name, val, filename: nil)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
nil
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# private
|
100
|
+
#
|
101
|
+
|
102
|
+
# Escapes double quotes so that the given value can be used in a
|
103
|
+
# double-quoted string and replaces any linebreak characters with spaces.
|
104
|
+
private def escape(str)
|
105
|
+
str.gsub('"', "%22").tr("\n", " ").tr("\r", " ")
|
106
|
+
end
|
107
|
+
|
108
|
+
private def write_field(name, data, filename:)
|
109
|
+
if !@first_field
|
110
|
+
@body << "\r\n"
|
111
|
+
else
|
112
|
+
@first_field = false
|
113
|
+
end
|
114
|
+
|
115
|
+
@body << "--#{@boundary}\r\n"
|
116
|
+
|
117
|
+
if filename
|
118
|
+
@body << %(Content-Disposition: form-data) +
|
119
|
+
%(; name="#{escape(name.to_s)}") +
|
120
|
+
%(; filename="#{escape(filename)}"\r\n)
|
121
|
+
@body << %(Content-Type: application/octet-stream\r\n)
|
122
|
+
else
|
123
|
+
@body << %(Content-Disposition: form-data) +
|
124
|
+
%(; name="#{escape(name.to_s)}"\r\n)
|
125
|
+
end
|
126
|
+
|
127
|
+
@body << "\r\n"
|
128
|
+
@body << data.to_s
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/lib/stripe/oauth.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Stripe
|
2
4
|
module OAuth
|
3
5
|
module OAuthOperations
|
@@ -12,43 +14,49 @@ module Stripe
|
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
def self.get_client_id(params={})
|
17
|
+
def self.get_client_id(params = {})
|
16
18
|
client_id = params[:client_id] || Stripe.client_id
|
17
19
|
unless client_id
|
18
|
-
raise AuthenticationError
|
20
|
+
raise AuthenticationError, "No client_id provided. " \
|
19
21
|
'Set your client_id using "Stripe.client_id = <CLIENT-ID>". ' \
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
"You can find your client_ids in your Stripe dashboard at " \
|
23
|
+
"https://dashboard.stripe.com/account/applications/settings, " \
|
24
|
+
"after registering your account as a platform. See " \
|
25
|
+
"https://stripe.com/docs/connect/standalone-accounts for details, " \
|
26
|
+
"or email support@stripe.com if you have any questions."
|
25
27
|
end
|
26
28
|
client_id
|
27
29
|
end
|
28
30
|
|
29
|
-
def self.authorize_url(params={}, opts={})
|
31
|
+
def self.authorize_url(params = {}, opts = {})
|
30
32
|
base = opts[:connect_base] || Stripe.connect_base
|
31
33
|
|
34
|
+
path = "/oauth/authorize"
|
35
|
+
path = "/express" + path if opts[:express]
|
36
|
+
|
32
37
|
params[:client_id] = get_client_id(params)
|
33
|
-
params[:response_type] ||=
|
38
|
+
params[:response_type] ||= "code"
|
34
39
|
query = Util.encode_parameters(params)
|
35
40
|
|
36
|
-
"#{base}
|
41
|
+
"#{base}#{path}?#{query}"
|
37
42
|
end
|
38
43
|
|
39
|
-
def self.token(params={}, opts={})
|
44
|
+
def self.token(params = {}, opts = {})
|
40
45
|
opts = Util.normalize_opts(opts)
|
46
|
+
opts[:api_key] = params[:client_secret] if params[:client_secret]
|
41
47
|
resp, opts = OAuthOperations.request(
|
42
|
-
:post,
|
48
|
+
:post, "/oauth/token", params, opts
|
49
|
+
)
|
43
50
|
# This is just going to return a generic StripeObject, but that's okay
|
44
51
|
Util.convert_to_stripe_object(resp.data, opts)
|
45
52
|
end
|
46
53
|
|
47
|
-
def self.deauthorize(params={}, opts={})
|
54
|
+
def self.deauthorize(params = {}, opts = {})
|
48
55
|
opts = Util.normalize_opts(opts)
|
49
56
|
params[:client_id] = get_client_id(params)
|
50
57
|
resp, opts = OAuthOperations.request(
|
51
|
-
:post,
|
58
|
+
:post, "/oauth/deauthorize", params, opts
|
59
|
+
)
|
52
60
|
# This is just going to return a generic StripeObject, but that's okay
|
53
61
|
Util.convert_to_stripe_object(resp.data, opts)
|
54
62
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/MethodLength
|
4
|
+
|
5
|
+
module Stripe
|
6
|
+
module ObjectTypes
|
7
|
+
def self.object_names_to_classes
|
8
|
+
{
|
9
|
+
# data structures
|
10
|
+
ListObject::OBJECT_NAME => ListObject,
|
11
|
+
|
12
|
+
# business objects
|
13
|
+
Account::OBJECT_NAME => Account,
|
14
|
+
AccountLink::OBJECT_NAME => AccountLink,
|
15
|
+
AlipayAccount::OBJECT_NAME => AlipayAccount,
|
16
|
+
ApplePayDomain::OBJECT_NAME => ApplePayDomain,
|
17
|
+
ApplicationFee::OBJECT_NAME => ApplicationFee,
|
18
|
+
ApplicationFeeRefund::OBJECT_NAME => ApplicationFeeRefund,
|
19
|
+
Balance::OBJECT_NAME => Balance,
|
20
|
+
BalanceTransaction::OBJECT_NAME => BalanceTransaction,
|
21
|
+
BankAccount::OBJECT_NAME => BankAccount,
|
22
|
+
BitcoinReceiver::OBJECT_NAME => BitcoinReceiver,
|
23
|
+
BitcoinTransaction::OBJECT_NAME => BitcoinTransaction,
|
24
|
+
Capability::OBJECT_NAME => Capability,
|
25
|
+
Card::OBJECT_NAME => Card,
|
26
|
+
Charge::OBJECT_NAME => Charge,
|
27
|
+
Checkout::Session::OBJECT_NAME => Checkout::Session,
|
28
|
+
CountrySpec::OBJECT_NAME => CountrySpec,
|
29
|
+
Coupon::OBJECT_NAME => Coupon,
|
30
|
+
CreditNote::OBJECT_NAME => CreditNote,
|
31
|
+
CreditNoteLineItem::OBJECT_NAME => CreditNoteLineItem,
|
32
|
+
Customer::OBJECT_NAME => Customer,
|
33
|
+
CustomerBalanceTransaction::OBJECT_NAME => CustomerBalanceTransaction,
|
34
|
+
Discount::OBJECT_NAME => Discount,
|
35
|
+
Dispute::OBJECT_NAME => Dispute,
|
36
|
+
EphemeralKey::OBJECT_NAME => EphemeralKey,
|
37
|
+
Event::OBJECT_NAME => Event,
|
38
|
+
ExchangeRate::OBJECT_NAME => ExchangeRate,
|
39
|
+
File::OBJECT_NAME => File,
|
40
|
+
File::OBJECT_NAME_ALT => File,
|
41
|
+
FileLink::OBJECT_NAME => FileLink,
|
42
|
+
Invoice::OBJECT_NAME => Invoice,
|
43
|
+
InvoiceItem::OBJECT_NAME => InvoiceItem,
|
44
|
+
InvoiceLineItem::OBJECT_NAME => InvoiceLineItem,
|
45
|
+
Issuing::Authorization::OBJECT_NAME => Issuing::Authorization,
|
46
|
+
Issuing::Card::OBJECT_NAME => Issuing::Card,
|
47
|
+
Issuing::CardDetails::OBJECT_NAME => Issuing::CardDetails,
|
48
|
+
Issuing::Cardholder::OBJECT_NAME => Issuing::Cardholder,
|
49
|
+
Issuing::Dispute::OBJECT_NAME => Issuing::Dispute,
|
50
|
+
Issuing::Transaction::OBJECT_NAME => Issuing::Transaction,
|
51
|
+
LoginLink::OBJECT_NAME => LoginLink,
|
52
|
+
Mandate::OBJECT_NAME => Mandate,
|
53
|
+
Order::OBJECT_NAME => Order,
|
54
|
+
OrderReturn::OBJECT_NAME => OrderReturn,
|
55
|
+
PaymentIntent::OBJECT_NAME => PaymentIntent,
|
56
|
+
PaymentMethod::OBJECT_NAME => PaymentMethod,
|
57
|
+
Payout::OBJECT_NAME => Payout,
|
58
|
+
Person::OBJECT_NAME => Person,
|
59
|
+
Plan::OBJECT_NAME => Plan,
|
60
|
+
Product::OBJECT_NAME => Product,
|
61
|
+
Radar::EarlyFraudWarning::OBJECT_NAME => Radar::EarlyFraudWarning,
|
62
|
+
Radar::ValueList::OBJECT_NAME => Radar::ValueList,
|
63
|
+
Radar::ValueListItem::OBJECT_NAME => Radar::ValueListItem,
|
64
|
+
Recipient::OBJECT_NAME => Recipient,
|
65
|
+
RecipientTransfer::OBJECT_NAME => RecipientTransfer,
|
66
|
+
Refund::OBJECT_NAME => Refund,
|
67
|
+
Reporting::ReportRun::OBJECT_NAME => Reporting::ReportRun,
|
68
|
+
Reporting::ReportType::OBJECT_NAME => Reporting::ReportType,
|
69
|
+
Reversal::OBJECT_NAME => Reversal,
|
70
|
+
Review::OBJECT_NAME => Review,
|
71
|
+
SKU::OBJECT_NAME => SKU,
|
72
|
+
SetupIntent::OBJECT_NAME => SetupIntent,
|
73
|
+
Sigma::ScheduledQueryRun::OBJECT_NAME => Sigma::ScheduledQueryRun,
|
74
|
+
Source::OBJECT_NAME => Source,
|
75
|
+
SourceTransaction::OBJECT_NAME => SourceTransaction,
|
76
|
+
Subscription::OBJECT_NAME => Subscription,
|
77
|
+
SubscriptionItem::OBJECT_NAME => SubscriptionItem,
|
78
|
+
SubscriptionSchedule::OBJECT_NAME => SubscriptionSchedule,
|
79
|
+
TaxId::OBJECT_NAME => TaxId,
|
80
|
+
TaxRate::OBJECT_NAME => TaxRate,
|
81
|
+
Terminal::ConnectionToken::OBJECT_NAME => Terminal::ConnectionToken,
|
82
|
+
Terminal::Location::OBJECT_NAME => Terminal::Location,
|
83
|
+
Terminal::Reader::OBJECT_NAME => Terminal::Reader,
|
84
|
+
ThreeDSecure::OBJECT_NAME => ThreeDSecure,
|
85
|
+
Token::OBJECT_NAME => Token,
|
86
|
+
Topup::OBJECT_NAME => Topup,
|
87
|
+
Transfer::OBJECT_NAME => Transfer,
|
88
|
+
UsageRecord::OBJECT_NAME => UsageRecord,
|
89
|
+
UsageRecordSummary::OBJECT_NAME => UsageRecordSummary,
|
90
|
+
WebhookEndpoint::OBJECT_NAME => WebhookEndpoint,
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# rubocop:enable Metrics/MethodLength
|
@@ -1,21 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Stripe
|
2
4
|
class Account < APIResource
|
3
5
|
extend Gem::Deprecate
|
4
6
|
extend Stripe::APIOperations::Create
|
5
|
-
extend Stripe::APIOperations::List
|
6
7
|
include Stripe::APIOperations::Delete
|
8
|
+
extend Stripe::APIOperations::List
|
7
9
|
include Stripe::APIOperations::Save
|
10
|
+
extend Stripe::APIOperations::NestedResource
|
11
|
+
|
12
|
+
OBJECT_NAME = "account"
|
8
13
|
|
9
|
-
|
14
|
+
custom_method :reject, http_verb: :post
|
15
|
+
|
16
|
+
nested_resource_class_methods :capability,
|
17
|
+
operations: %i[retrieve update list],
|
18
|
+
resource_plural: "capabilities"
|
19
|
+
nested_resource_class_methods :person,
|
20
|
+
operations: %i[create retrieve update delete list]
|
21
|
+
|
22
|
+
def reject(params = {}, opts = {})
|
23
|
+
request_stripe_object(
|
24
|
+
method: :post,
|
25
|
+
path: resource_url + "/reject",
|
26
|
+
params: params,
|
27
|
+
opts: opts
|
28
|
+
)
|
29
|
+
end
|
10
30
|
|
11
31
|
save_nested_resource :external_account
|
12
32
|
|
13
|
-
|
14
|
-
|
15
|
-
|
33
|
+
nested_resource_class_methods :external_account,
|
34
|
+
operations: %i[create retrieve update delete list]
|
35
|
+
|
36
|
+
nested_resource_class_methods :login_link, operations: %i[create]
|
16
37
|
|
17
38
|
def resource_url
|
18
|
-
if self[
|
39
|
+
if self["id"]
|
19
40
|
super
|
20
41
|
else
|
21
42
|
"/v1/account"
|
@@ -23,26 +44,34 @@ module Stripe
|
|
23
44
|
end
|
24
45
|
|
25
46
|
# @override To make id optional
|
26
|
-
def self.retrieve(id=ARGUMENT_NOT_PROVIDED, opts={})
|
27
|
-
id = id.equal?(ARGUMENT_NOT_PROVIDED)
|
47
|
+
def self.retrieve(id = ARGUMENT_NOT_PROVIDED, opts = {})
|
48
|
+
id = if id.equal?(ARGUMENT_NOT_PROVIDED)
|
49
|
+
nil
|
50
|
+
else
|
51
|
+
Util.check_string_argument!(id)
|
52
|
+
end
|
28
53
|
|
29
54
|
# Account used to be a singleton, where this method's signature was
|
30
55
|
# `(opts={})`. For the sake of not breaking folks who pass in an OAuth
|
31
56
|
# key in opts, let's lurkily string match for it.
|
32
|
-
if opts == {} && id.is_a?(String) && id.start_with?(
|
33
|
-
# `super` properly assumes a String opts is the apiKey and normalizes
|
57
|
+
if opts == {} && id.is_a?(String) && id.start_with?("sk_")
|
58
|
+
# `super` properly assumes a String opts is the apiKey and normalizes
|
59
|
+
# as expected.
|
34
60
|
opts = id
|
35
61
|
id = nil
|
36
62
|
end
|
37
63
|
super(id, opts)
|
38
64
|
end
|
39
65
|
|
40
|
-
def
|
41
|
-
opts =
|
42
|
-
resp, opts
|
43
|
-
initialize_from(resp.data, opts)
|
66
|
+
def persons(params = {}, opts = {})
|
67
|
+
resp, opts = request(:get, resource_url + "/persons", params, opts)
|
68
|
+
Util.convert_to_stripe_object(resp.data, opts)
|
44
69
|
end
|
45
70
|
|
71
|
+
# We are not adding a helper for capabilities here as the Account object
|
72
|
+
# already has a capabilities property which is a hash and not the sub-list
|
73
|
+
# of capabilities.
|
74
|
+
|
46
75
|
# Somewhat unfortunately, we attempt to do a special encoding trick when
|
47
76
|
# serializing `additional_owners` under an account: when updating a value,
|
48
77
|
# we actually send the update parameters up as an integer-indexed hash
|
@@ -67,17 +96,22 @@ module Stripe
|
|
67
96
|
# We're trying to get this overturned on the server side, but for now,
|
68
97
|
# patch in a special allowance.
|
69
98
|
def serialize_params(options = {})
|
70
|
-
serialize_params_account(self, super)
|
99
|
+
serialize_params_account(self, super, options)
|
71
100
|
end
|
72
101
|
|
73
|
-
def serialize_params_account(
|
74
|
-
if entity = @values[:legal_entity]
|
75
|
-
if owners = entity[:additional_owners]
|
102
|
+
def serialize_params_account(_obj, update_hash, options = {})
|
103
|
+
if (entity = @values[:legal_entity])
|
104
|
+
if (owners = entity[:additional_owners])
|
76
105
|
entity_update = update_hash[:legal_entity] ||= {}
|
77
106
|
entity_update[:additional_owners] =
|
78
107
|
serialize_additional_owners(entity, owners)
|
79
108
|
end
|
80
109
|
end
|
110
|
+
if (individual = @values[:individual])
|
111
|
+
if individual.is_a?(Person) && !update_hash.key?(:individual)
|
112
|
+
update_hash[:individual] = individual.serialize_params(options)
|
113
|
+
end
|
114
|
+
end
|
81
115
|
update_hash
|
82
116
|
end
|
83
117
|
|
@@ -86,34 +120,37 @@ module Stripe
|
|
86
120
|
end
|
87
121
|
|
88
122
|
def legal_entity
|
89
|
-
self[
|
123
|
+
self["legal_entity"]
|
90
124
|
end
|
91
125
|
|
92
|
-
def legal_entity=(
|
93
|
-
raise NoMethodError
|
126
|
+
def legal_entity=(_legal_entity)
|
127
|
+
raise NoMethodError,
|
128
|
+
"Overriding legal_entity can cause serious issues. Instead, set " \
|
129
|
+
"the individual fields of legal_entity like " \
|
130
|
+
"`account.legal_entity.first_name = 'Blah'`"
|
94
131
|
end
|
95
132
|
|
96
|
-
def deauthorize(client_id=nil, opts={})
|
133
|
+
def deauthorize(client_id = nil, opts = {})
|
97
134
|
params = {
|
98
135
|
client_id: client_id,
|
99
|
-
stripe_user_id:
|
136
|
+
stripe_user_id: id,
|
100
137
|
}
|
101
138
|
OAuth.deauthorize(params, opts)
|
102
139
|
end
|
103
140
|
|
104
141
|
ARGUMENT_NOT_PROVIDED = Object.new
|
105
142
|
|
106
|
-
private
|
107
|
-
|
108
|
-
|
109
|
-
|
143
|
+
private def serialize_additional_owners(legal_entity, additional_owners)
|
144
|
+
original_value =
|
145
|
+
legal_entity
|
146
|
+
.instance_variable_get(:@original_values)[:additional_owners]
|
110
147
|
if original_value && original_value.length > additional_owners.length
|
111
148
|
# url params provide no mechanism for deleting an item in an array,
|
112
149
|
# just overwriting the whole array or adding new items. So let's not
|
113
150
|
# allow deleting without a full overwrite until we have a solution.
|
114
|
-
raise ArgumentError
|
115
|
-
|
116
|
-
|
151
|
+
raise ArgumentError,
|
152
|
+
"You cannot delete an item from an array, you must instead " \
|
153
|
+
"set a new array"
|
117
154
|
end
|
118
155
|
|
119
156
|
update_hash = {}
|
@@ -125,10 +162,11 @@ module Stripe
|
|
125
162
|
# StripeObject.
|
126
163
|
update = v.is_a?(StripeObject) ? v.serialize_params : v
|
127
164
|
|
128
|
-
|
129
|
-
update != legal_entity.serialize_params_value(original_value[i], nil,
|
130
|
-
|
131
|
-
|
165
|
+
next unless update != {} && (!original_value ||
|
166
|
+
update != legal_entity.serialize_params_value(original_value[i], nil,
|
167
|
+
false, true))
|
168
|
+
|
169
|
+
update_hash[i.to_s] = update
|
132
170
|
end
|
133
171
|
update_hash
|
134
172
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class AlipayAccount < APIResource
|
5
|
+
include Stripe::APIOperations::Save
|
6
|
+
include Stripe::APIOperations::Delete
|
7
|
+
|
8
|
+
OBJECT_NAME = "alipay_account"
|
9
|
+
|
10
|
+
def resource_url
|
11
|
+
if !respond_to?(:customer) || customer.nil?
|
12
|
+
raise NotImplementedError,
|
13
|
+
"Alipay accounts cannot be accessed without a customer ID."
|
14
|
+
end
|
15
|
+
|
16
|
+
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources" \
|
17
|
+
"/#{CGI.escape(id)}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.update(_id, _params = nil, _opts = nil)
|
21
|
+
raise NotImplementedError,
|
22
|
+
"Alipay accounts cannot be updated without a customer ID. " \
|
23
|
+
"Update an Alipay account using `Customer.update_source(" \
|
24
|
+
"'customer_id', 'alipay_account_id', update_params)`"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.retrieve(_id, _opts = nil)
|
28
|
+
raise NotImplementedError,
|
29
|
+
"Alipay accounts cannot be retrieved without a customer ID. " \
|
30
|
+
"Retrieve an Alipay account using `Customer.retrieve_source(" \
|
31
|
+
"'customer_id', 'alipay_account_id')`"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|