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/subscription.rb
CHANGED
@@ -1,25 +1,31 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Subscription < APIResource
|
3
|
-
|
3
|
+
extend Stripe::APIOperations::List
|
4
|
+
extend Stripe::APIOperations::Create
|
5
|
+
include Stripe::APIOperations::Save
|
4
6
|
include Stripe::APIOperations::Delete
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
save_nested_resource :source
|
9
|
+
|
10
|
+
def delete_discount
|
11
|
+
_, opts = request(:delete, discount_url)
|
12
|
+
initialize_from({ :discount => nil }, opts, true)
|
8
13
|
end
|
9
14
|
|
10
|
-
def self.
|
11
|
-
|
15
|
+
def self.update(id, params={}, opts={})
|
16
|
+
params[:items] = Util.array_to_hash(params[:items]) if params[:items]
|
17
|
+
super(id, params, opts)
|
12
18
|
end
|
13
19
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
20
|
+
def self.create(params={}, opts={})
|
21
|
+
params[:items] = Util.array_to_hash(params[:items]) if params[:items]
|
22
|
+
super(params, opts)
|
17
23
|
end
|
18
24
|
|
19
25
|
private
|
20
26
|
|
21
27
|
def discount_url
|
22
|
-
|
28
|
+
resource_url + '/discount'
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Stripe
|
2
|
+
class SubscriptionItem < APIResource
|
3
|
+
extend Stripe::APIOperations::Create
|
4
|
+
include Stripe::APIOperations::Delete
|
5
|
+
extend Stripe::APIOperations::List
|
6
|
+
include Stripe::APIOperations::Save
|
7
|
+
|
8
|
+
def self.resource_url
|
9
|
+
'/v1/subscription_items'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/stripe/transfer.rb
CHANGED
@@ -2,16 +2,15 @@ module Stripe
|
|
2
2
|
class Transfer < 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 cancel
|
8
|
-
response, api_key =
|
8
|
+
response, api_key = self.request(:post, cancel_url)
|
9
9
|
initialize_from(response, api_key)
|
10
10
|
end
|
11
11
|
|
12
12
|
def cancel_url
|
13
|
-
|
13
|
+
resource_url + '/cancel'
|
14
14
|
end
|
15
|
-
|
16
15
|
end
|
17
16
|
end
|
data/lib/stripe/util.rb
CHANGED
@@ -23,36 +23,54 @@ module Stripe
|
|
23
23
|
'list' => ListObject,
|
24
24
|
|
25
25
|
# business objects
|
26
|
-
'account'
|
27
|
-
'
|
28
|
-
'
|
29
|
-
'
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
33
|
-
'
|
34
|
-
'
|
35
|
-
'
|
36
|
-
'
|
37
|
-
'
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
'
|
43
|
-
'file_upload'
|
44
|
-
'
|
45
|
-
'
|
46
|
-
'
|
47
|
-
'
|
48
|
-
'
|
49
|
-
'
|
50
|
-
'
|
51
|
-
'
|
52
|
-
'
|
26
|
+
'account' => Account,
|
27
|
+
'alipay_account' => AlipayAccount,
|
28
|
+
'apple_pay_domain' => ApplePayDomain,
|
29
|
+
'application_fee' => ApplicationFee,
|
30
|
+
'balance' => Balance,
|
31
|
+
'balance_transaction' => BalanceTransaction,
|
32
|
+
'bank_account' => BankAccount,
|
33
|
+
'bitcoin_receiver' => BitcoinReceiver,
|
34
|
+
'bitcoin_transaction' => BitcoinTransaction,
|
35
|
+
'card' => Card,
|
36
|
+
'charge' => Charge,
|
37
|
+
'country_spec' => CountrySpec,
|
38
|
+
'coupon' => Coupon,
|
39
|
+
'customer' => Customer,
|
40
|
+
'dispute' => Dispute,
|
41
|
+
'event' => Event,
|
42
|
+
'fee_refund' => ApplicationFeeRefund,
|
43
|
+
'file_upload' => FileUpload,
|
44
|
+
'invoice' => Invoice,
|
45
|
+
'invoiceitem' => InvoiceItem,
|
46
|
+
'order' => Order,
|
47
|
+
'order_return' => OrderReturn,
|
48
|
+
'plan' => Plan,
|
49
|
+
'product' => Product,
|
50
|
+
'recipient' => Recipient,
|
51
|
+
'refund' => Refund,
|
52
|
+
'sku' => SKU,
|
53
|
+
'subscription' => Subscription,
|
54
|
+
'subscription_item' => SubscriptionItem,
|
55
|
+
'three_d_secure' => ThreeDSecure,
|
56
|
+
'token' => Token,
|
57
|
+
'transfer' => Transfer,
|
58
|
+
'transfer_reversal' => Reversal,
|
53
59
|
}
|
54
60
|
end
|
55
61
|
|
62
|
+
# Converts a hash of fields or an array of hashes into a +StripeObject+ or
|
63
|
+
# array of +StripeObject+s. These new objects will be created as a concrete
|
64
|
+
# type as dictated by their `object` field (e.g. an `object` value of
|
65
|
+
# `charge` would create an instance of +Charge+), but if `object` is not
|
66
|
+
# present or of an unknown type, the newly created instance will fall back
|
67
|
+
# to being a +StripeObject+.
|
68
|
+
#
|
69
|
+
# ==== Attributes
|
70
|
+
#
|
71
|
+
# * +resp+ - Hash of fields and values to be converted into a StripeObject.
|
72
|
+
# * +opts+ - Options for +StripeObject+ like an API key that will be reused
|
73
|
+
# on subsequent API calls.
|
56
74
|
def self.convert_to_stripe_object(resp, opts)
|
57
75
|
case resp
|
58
76
|
when Array
|
@@ -103,6 +121,20 @@ module Stripe
|
|
103
121
|
map { |k,v| "#{url_encode(k)}=#{url_encode(v)}" }.join('&')
|
104
122
|
end
|
105
123
|
|
124
|
+
# Transforms an array into a hash with integer keys. Used for a small
|
125
|
+
# number of API endpoints. If the argument is not an Array, return it
|
126
|
+
# unchanged. Example: [{foo: 'bar'}] => {"0" => {foo: "bar"}}
|
127
|
+
def self.array_to_hash(array)
|
128
|
+
case array
|
129
|
+
when Array
|
130
|
+
hash = {}
|
131
|
+
array.each_with_index { |v,i| hash[i.to_s] = v }
|
132
|
+
hash
|
133
|
+
else
|
134
|
+
array
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
106
138
|
# Encodes a string in a way that makes it suitable for use in a set of
|
107
139
|
# query parameters in a URI or in a set of form parameters in a request
|
108
140
|
# body.
|
@@ -119,11 +151,12 @@ module Stripe
|
|
119
151
|
|
120
152
|
# do not sort the final output because arrays (and arrays of hashes
|
121
153
|
# especially) can be order sensitive, but do sort incoming parameters
|
122
|
-
params.
|
154
|
+
params.each do |key, value|
|
123
155
|
calculated_key = parent_key ? "#{parent_key}[#{key}]" : "#{key}"
|
124
156
|
if value.is_a?(Hash)
|
125
157
|
result += flatten_params(value, calculated_key)
|
126
158
|
elsif value.is_a?(Array)
|
159
|
+
check_array_of_maps_start_keys!(value)
|
127
160
|
result += flatten_params_array(value, calculated_key)
|
128
161
|
else
|
129
162
|
result << [calculated_key, value]
|
@@ -180,5 +213,44 @@ module Stripe
|
|
180
213
|
raise TypeError.new("api_key must be a string") unless key.is_a?(String)
|
181
214
|
key
|
182
215
|
end
|
216
|
+
|
217
|
+
private
|
218
|
+
|
219
|
+
# We use a pretty janky version of form encoding (Rack's) that supports
|
220
|
+
# more complex data structures like maps and arrays through the use of
|
221
|
+
# specialized syntax. To encode an array of maps like:
|
222
|
+
#
|
223
|
+
# [{a: 1, b: 2}, {a: 3, b: 4}]
|
224
|
+
#
|
225
|
+
# We have to produce something that looks like this:
|
226
|
+
#
|
227
|
+
# arr[][a]=1&arr[][b]=2&arr[][a]=3&arr[][b]=4
|
228
|
+
#
|
229
|
+
# The only way for the server to recognize that this is a two item array is
|
230
|
+
# that it notices the repetition of element "a", so it's key that these
|
231
|
+
# repeated elements are encoded first.
|
232
|
+
#
|
233
|
+
# This method is invoked for any arrays being encoded and checks that if
|
234
|
+
# the array contains all non-empty maps, that each of those maps must start
|
235
|
+
# with the same key so that their boundaries can be properly encoded.
|
236
|
+
def self.check_array_of_maps_start_keys!(arr)
|
237
|
+
expected_key = nil
|
238
|
+
arr.each do |item|
|
239
|
+
return if !item.is_a?(Hash)
|
240
|
+
return if item.count == 0
|
241
|
+
|
242
|
+
first_key = item.first[0]
|
243
|
+
|
244
|
+
if expected_key
|
245
|
+
if expected_key != first_key
|
246
|
+
raise ArgumentError,
|
247
|
+
"All maps nested in an array should start with the same key " +
|
248
|
+
"(expected starting key '#{expected_key}', got '#{first_key}')"
|
249
|
+
end
|
250
|
+
else
|
251
|
+
expected_key = first_key
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
183
255
|
end
|
184
256
|
end
|
data/lib/stripe/version.rb
CHANGED