stripe 1.30.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/.github/ISSUE_TEMPLATE.md +5 -0
  4. data/.travis.yml +3 -14
  5. data/Gemfile +28 -4
  6. data/History.txt +180 -0
  7. data/README.md +147 -0
  8. data/Rakefile +10 -0
  9. data/VERSION +1 -1
  10. data/bin/stripe-console +12 -5
  11. data/lib/data/ca-certificates.crt +3868 -5114
  12. data/lib/stripe/account.rb +43 -23
  13. data/lib/stripe/alipay_account.rb +20 -0
  14. data/lib/stripe/api_operations/create.rb +2 -2
  15. data/lib/stripe/api_operations/delete.rb +2 -2
  16. data/lib/stripe/api_operations/list.rb +2 -3
  17. data/lib/stripe/api_operations/request.rb +9 -3
  18. data/lib/stripe/api_operations/save.rb +85 -0
  19. data/lib/stripe/api_resource.rb +38 -5
  20. data/lib/stripe/apple_pay_domain.rb +12 -0
  21. data/lib/stripe/application_fee.rb +8 -8
  22. data/lib/stripe/application_fee_refund.rb +7 -3
  23. data/lib/stripe/balance_transaction.rb +1 -1
  24. data/lib/stripe/bank_account.rb +13 -4
  25. data/lib/stripe/bitcoin_receiver.rb +6 -6
  26. data/lib/stripe/bitcoin_transaction.rb +1 -1
  27. data/lib/stripe/card.rb +9 -5
  28. data/lib/stripe/charge.rb +38 -20
  29. data/lib/stripe/country_spec.rb +9 -0
  30. data/lib/stripe/coupon.rb +1 -1
  31. data/lib/stripe/customer.rb +12 -10
  32. data/lib/stripe/dispute.rb +4 -5
  33. data/lib/stripe/errors.rb +92 -0
  34. data/lib/stripe/file_upload.rb +1 -1
  35. data/lib/stripe/invoice.rb +7 -7
  36. data/lib/stripe/invoice_item.rb +1 -1
  37. data/lib/stripe/list_object.rb +8 -7
  38. data/lib/stripe/order.rb +12 -4
  39. data/lib/stripe/order_return.rb +9 -0
  40. data/lib/stripe/plan.rb +1 -1
  41. data/lib/stripe/product.rb +2 -10
  42. data/lib/stripe/recipient.rb +1 -1
  43. data/lib/stripe/refund.rb +1 -1
  44. data/lib/stripe/reversal.rb +7 -3
  45. data/lib/stripe/singleton_api_resource.rb +3 -3
  46. data/lib/stripe/sku.rb +2 -2
  47. data/lib/stripe/source.rb +11 -0
  48. data/lib/stripe/stripe_client.rb +396 -0
  49. data/lib/stripe/stripe_object.rb +167 -91
  50. data/lib/stripe/stripe_response.rb +48 -0
  51. data/lib/stripe/subscription.rb +15 -9
  52. data/lib/stripe/subscription_item.rb +12 -0
  53. data/lib/stripe/three_d_secure.rb +9 -0
  54. data/lib/stripe/transfer.rb +4 -5
  55. data/lib/stripe/util.rb +105 -33
  56. data/lib/stripe/version.rb +1 -1
  57. data/lib/stripe.rb +69 -266
  58. data/spec/fixtures.json +1409 -0
  59. data/spec/fixtures.yaml +1153 -0
  60. data/spec/spec.json +19949 -0
  61. data/spec/spec.yaml +15504 -0
  62. data/stripe.gemspec +5 -18
  63. data/test/api_fixtures.rb +29 -0
  64. data/test/api_stub_helpers.rb +125 -0
  65. data/test/stripe/account_test.rb +163 -211
  66. data/test/stripe/alipay_account_test.rb +19 -0
  67. data/test/stripe/api_operations_test.rb +31 -0
  68. data/test/stripe/api_resource_test.rb +174 -340
  69. data/test/stripe/apple_pay_domain_test.rb +33 -0
  70. data/test/stripe/application_fee_refund_test.rb +22 -31
  71. data/test/stripe/application_fee_test.rb +6 -14
  72. data/test/stripe/balance_test.rb +3 -3
  73. data/test/stripe/bank_account_test.rb +41 -0
  74. data/test/stripe/bitcoin_receiver_test.rb +51 -42
  75. data/test/stripe/bitcoin_transaction_test.rb +11 -19
  76. data/test/stripe/charge_test.rb +39 -98
  77. data/test/stripe/country_spec_test.rb +20 -0
  78. data/test/stripe/coupon_test.rb +35 -11
  79. data/test/stripe/customer_card_test.rb +25 -46
  80. data/test/stripe/customer_test.rb +89 -61
  81. data/test/stripe/dispute_test.rb +28 -31
  82. data/test/stripe/errors_test.rb +18 -0
  83. data/test/stripe/file_upload_test.rb +32 -24
  84. data/test/stripe/invoice_item_test.rb +55 -0
  85. data/test/stripe/invoice_test.rb +50 -24
  86. data/test/stripe/list_object_test.rb +57 -45
  87. data/test/stripe/order_return_test.rb +21 -0
  88. data/test/stripe/order_test.rb +41 -34
  89. data/test/stripe/plan_test.rb +52 -0
  90. data/test/stripe/product_test.rb +31 -25
  91. data/test/stripe/recipient_card_test.rb +23 -40
  92. data/test/stripe/recipient_test.rb +50 -0
  93. data/test/stripe/refund_test.rb +20 -36
  94. data/test/stripe/reversal_test.rb +27 -31
  95. data/test/stripe/sku_test.rb +39 -13
  96. data/test/stripe/source_test.rb +43 -0
  97. data/test/stripe/stripe_client_test.rb +428 -0
  98. data/test/stripe/stripe_object_test.rb +186 -13
  99. data/test/stripe/stripe_response_test.rb +46 -0
  100. data/test/stripe/subscription_item_test.rb +54 -0
  101. data/test/stripe/subscription_test.rb +40 -52
  102. data/test/stripe/three_d_secure_test.rb +23 -0
  103. data/test/stripe/transfer_test.rb +38 -13
  104. data/test/stripe/util_test.rb +48 -16
  105. data/test/stripe_test.rb +25 -0
  106. data/test/test_data.rb +5 -621
  107. data/test/test_helper.rb +24 -24
  108. metadata +60 -139
  109. data/README.rdoc +0 -68
  110. data/gemfiles/default-with-activesupport.gemfile +0 -10
  111. data/gemfiles/json.gemfile +0 -12
  112. data/gemfiles/yajl.gemfile +0 -12
  113. data/lib/stripe/api_operations/update.rb +0 -58
  114. data/lib/stripe/errors/api_connection_error.rb +0 -4
  115. data/lib/stripe/errors/api_error.rb +0 -4
  116. data/lib/stripe/errors/authentication_error.rb +0 -4
  117. data/lib/stripe/errors/card_error.rb +0 -12
  118. data/lib/stripe/errors/invalid_request_error.rb +0 -11
  119. data/lib/stripe/errors/rate_limit_error.rb +0 -4
  120. data/lib/stripe/errors/stripe_error.rb +0 -26
  121. data/test/stripe/charge_refund_test.rb +0 -55
  122. data/test/stripe/metadata_test.rb +0 -129
@@ -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::Update
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)
@@ -36,20 +38,20 @@ module Stripe
36
38
  end
37
39
 
38
40
  def cancel_subscription(params={}, opts={})
39
- response, opts = request(:delete, subscription_url, params, opts)
40
- initialize_from({ :subscription => response }, opts, true)
41
+ resp, opts = request(:delete, subscription_url, params, opts)
42
+ initialize_from({ :subscription => resp.data }, opts, true)
41
43
  subscription
42
44
  end
43
45
 
44
46
  def update_subscription(params={}, opts={})
45
- response, opts = request(:post, subscription_url, params, opts)
46
- initialize_from({ :subscription => response }, opts, true)
47
+ resp, opts = request(:post, subscription_url, params, opts)
48
+ initialize_from({ :subscription => resp.data }, opts, true)
47
49
  subscription
48
50
  end
49
51
 
50
52
  def create_subscription(params={}, opts={})
51
- response, opts = request(:post, subscriptions_url, params, opts)
52
- initialize_from({ :subscription => response }, opts, true)
53
+ resp, opts = request(:post, subscriptions_url, params, opts)
54
+ initialize_from({ :subscription => resp.data }, opts, true)
53
55
  subscription
54
56
  end
55
57
 
@@ -61,15 +63,15 @@ module Stripe
61
63
  private
62
64
 
63
65
  def discount_url
64
- url + '/discount'
66
+ resource_url + '/discount'
65
67
  end
66
68
 
67
69
  def subscription_url
68
- url + '/subscription'
70
+ resource_url + '/subscription'
69
71
  end
70
72
 
71
73
  def subscriptions_url
72
- url + '/subscriptions'
74
+ resource_url + '/subscriptions'
73
75
  end
74
76
  end
75
77
  end
@@ -1,16 +1,15 @@
1
1
  module Stripe
2
2
  class Dispute < APIResource
3
3
  extend Stripe::APIOperations::List
4
- extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
4
+ include Stripe::APIOperations::Save
6
5
 
7
6
  def close(params={}, opts={})
8
- response, opts = request(:post, close_url, params, opts)
9
- initialize_from(response, opts)
7
+ resp, opts = request(:post, close_url, params, opts)
8
+ initialize_from(resp.data, opts)
10
9
  end
11
10
 
12
11
  def close_url
13
- url + '/close'
12
+ resource_url + '/close'
14
13
  end
15
14
  end
16
15
  end
@@ -0,0 +1,92 @@
1
+ module Stripe
2
+ # StripeError is the base error from which all other more specific Stripe
3
+ # errors derive.
4
+ class StripeError < StandardError
5
+ attr_reader :message
6
+
7
+ # Response contains a StripeResponse object that has some basic information
8
+ # about the response that conveyed the error.
9
+ attr_accessor :response
10
+
11
+ # These fields are now available as part of #response and that usage should
12
+ # be preferred.
13
+ attr_reader :http_body
14
+ attr_reader :http_headers
15
+ attr_reader :http_status
16
+ attr_reader :json_body # equivalent to #data
17
+ attr_reader :request_id
18
+
19
+ # Initializes a StripeError.
20
+ def initialize(message=nil, http_status: nil, http_body: nil, json_body: nil,
21
+ http_headers: nil)
22
+ @message = message
23
+ @http_status = http_status
24
+ @http_body = http_body
25
+ @http_headers = http_headers || {}
26
+ @json_body = json_body
27
+ @request_id = @http_headers[:request_id]
28
+ end
29
+
30
+ def to_s
31
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
32
+ id_string = @request_id.nil? ? "" : "(Request #{@request_id}) "
33
+ "#{status_string}#{id_string}#{@message}"
34
+ end
35
+ end
36
+
37
+ # AuthenticationError is raised when invalid credentials are used to connect
38
+ # to Stripe's servers.
39
+ class AuthenticationError < StripeError
40
+ end
41
+
42
+ # APIConnectionError is raised in the event that the SDK can't connect to
43
+ # Stripe's servers. That can be for a variety of different reasons from a
44
+ # downed network to a bad TLS certificate.
45
+ class APIConnectionError < StripeError
46
+ end
47
+
48
+ # APIError is a generic error that may be raised in cases where none of the
49
+ # other named errors cover the problem. It could also be raised in the case
50
+ # that a new error has been introduced in the API, but this version of the
51
+ # Ruby SDK doesn't know how to handle it.
52
+ class APIError < StripeError
53
+ end
54
+
55
+ # CardError is raised when a user enters a card that can't be charged for
56
+ # some reason.
57
+ class CardError < StripeError
58
+ attr_reader :param, :code
59
+
60
+ def initialize(message, param, code, http_status: nil, http_body: nil, json_body: nil,
61
+ http_headers: nil)
62
+ super(message, http_status: http_status, http_body: http_body,
63
+ json_body: json_body, http_headers: http_headers)
64
+ @param = param
65
+ @code = code
66
+ end
67
+ end
68
+
69
+ # InvalidRequestError is raised when a request is initiated with invalid
70
+ # parameters.
71
+ class InvalidRequestError < StripeError
72
+ attr_accessor :param
73
+
74
+ def initialize(message, param, http_status: nil, http_body: nil, json_body: nil,
75
+ http_headers: nil)
76
+ super(message, http_status: http_status, http_body: http_body,
77
+ json_body: json_body, http_headers: http_headers)
78
+ @param = param
79
+ end
80
+ end
81
+
82
+ # PermissionError is raised in cases where access was attempted on a resource
83
+ # that wasn't allowed.
84
+ class PermissionError < StripeError
85
+ end
86
+
87
+ # RateLimitError is raised in cases where an account is putting too much load
88
+ # on Stripe's API servers (usually by performing too many requests). Please
89
+ # back off on request rate.
90
+ class RateLimitError < StripeError
91
+ end
92
+ end
@@ -3,7 +3,7 @@ module Stripe
3
3
  extend Stripe::APIOperations::Create
4
4
  extend Stripe::APIOperations::List
5
5
 
6
- def self.url
6
+ def self.resource_url
7
7
  "/v1/files"
8
8
  end
9
9
 
@@ -1,27 +1,27 @@
1
1
  module Stripe
2
2
  class Invoice < APIResource
3
3
  extend Stripe::APIOperations::List
4
- include Stripe::APIOperations::Update
4
+ include Stripe::APIOperations::Save
5
5
  extend Stripe::APIOperations::Create
6
6
 
7
7
  def self.upcoming(params, opts={})
8
- response, opts = request(:get, upcoming_url, params, opts)
9
- Util.convert_to_stripe_object(response, opts)
8
+ resp, opts = request(:get, upcoming_url, params, opts)
9
+ Util.convert_to_stripe_object(resp.data, opts)
10
10
  end
11
11
 
12
12
  def pay(opts={})
13
- response, opts = request(:post, pay_url, {}, opts)
14
- initialize_from(response, opts)
13
+ resp, opts = request(:post, pay_url, {}, opts)
14
+ initialize_from(resp.data, opts)
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def self.upcoming_url
20
- url + '/upcoming'
20
+ resource_url + '/upcoming'
21
21
  end
22
22
 
23
23
  def pay_url
24
- url + '/pay'
24
+ resource_url + '/pay'
25
25
  end
26
26
  end
27
27
  end
@@ -3,6 +3,6 @@ module Stripe
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Delete
6
- include Stripe::APIOperations::Update
6
+ include Stripe::APIOperations::Save
7
7
  end
8
8
  end
@@ -3,6 +3,7 @@ module Stripe
3
3
  include Enumerable
4
4
  include Stripe::APIOperations::List
5
5
  include Stripe::APIOperations::Request
6
+ include Stripe::APIOperations::Create
6
7
 
7
8
  # This accessor allows a `ListObject` to inherit various filters that were
8
9
  # given to a predecessor. This allows for things like consistent limits,
@@ -63,13 +64,8 @@ module Stripe
63
64
 
64
65
  def retrieve(id, opts={})
65
66
  id, retrieve_params = Util.normalize_id(id)
66
- response, opts = request(:get,"#{url}/#{CGI.escape(id)}", retrieve_params, opts)
67
- Util.convert_to_stripe_object(response, opts)
68
- end
69
-
70
- def create(params={}, opts={})
71
- response, opts = request(:post, url, params, opts)
72
- Util.convert_to_stripe_object(response, opts)
67
+ resp, opts = request(:get,"#{resource_url}/#{CGI.escape(id)}", retrieve_params, opts)
68
+ Util.convert_to_stripe_object(resp.data, opts)
73
69
  end
74
70
 
75
71
  # Fetches the next page in the resource list (if there is one).
@@ -100,5 +96,10 @@ module Stripe
100
96
 
101
97
  list(params, opts)
102
98
  end
99
+
100
+ def resource_url
101
+ self.url ||
102
+ raise(ArgumentError, "List object does not contain a 'url' field.")
103
+ end
103
104
  end
104
105
  end
data/lib/stripe/order.rb CHANGED
@@ -2,18 +2,26 @@ module Stripe
2
2
  class Order < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
 
7
7
  def pay(params, opts={})
8
- response, opts = request(:post, pay_url, params, opts)
9
- initialize_from(response, opts)
8
+ resp, opts = request(:post, pay_url, params, opts)
9
+ initialize_from(resp.data, opts)
10
+ end
11
+
12
+ def return_order(params, opts={})
13
+ resp, opts = request(:post, returns_url, params, opts)
14
+ Util.convert_to_stripe_object(resp.data, opts)
10
15
  end
11
16
 
12
17
  private
13
18
 
14
19
  def pay_url
15
- url + "/pay"
20
+ resource_url + '/pay'
16
21
  end
17
22
 
23
+ def returns_url
24
+ resource_url + '/returns'
25
+ end
18
26
  end
19
27
  end
@@ -0,0 +1,9 @@
1
+ module Stripe
2
+ class OrderReturn < APIResource
3
+ extend Stripe::APIOperations::List
4
+
5
+ def self.resource_url
6
+ "/v1/order_returns"
7
+ end
8
+ end
9
+ end
data/lib/stripe/plan.rb CHANGED
@@ -3,6 +3,6 @@ module Stripe
3
3
  extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
5
  extend Stripe::APIOperations::List
6
- include Stripe::APIOperations::Update
6
+ include Stripe::APIOperations::Save
7
7
  end
8
8
  end
@@ -2,15 +2,7 @@ module Stripe
2
2
  class Product < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
6
-
7
- # Keep APIResource#url as `api_url` to avoid letting the external URL
8
- # replace the Stripe URL.
9
- alias_method :api_url, :url
10
-
11
- # Override Stripe::APIOperations::Update#save to explicitly pass URL.
12
- def save
13
- super(:req_url => api_url)
14
- end
5
+ include Stripe::APIOperations::Save
6
+ include Stripe::APIOperations::Delete
15
7
  end
16
8
  end
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Recipient < APIResource
3
3
  extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
  extend Stripe::APIOperations::List
7
7
 
8
8
  def transfers
data/lib/stripe/refund.rb CHANGED
@@ -2,6 +2,6 @@ module Stripe
2
2
  class Refund < APIResource
3
3
  extend Stripe::APIOperations::Create
4
4
  extend Stripe::APIOperations::List
5
- include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Save
6
6
  end
7
7
  end
@@ -1,10 +1,14 @@
1
1
  module Stripe
2
2
  class Reversal < APIResource
3
- include Stripe::APIOperations::Update
4
3
  extend Stripe::APIOperations::List
4
+ include Stripe::APIOperations::Save
5
5
 
6
- def url
7
- "#{Transfer.url}/#{CGI.escape(transfer)}/reversals/#{CGI.escape(id)}"
6
+ def resource_url
7
+ "#{Transfer.resource_url}/#{CGI.escape(transfer)}/reversals/#{CGI.escape(id)}"
8
+ end
9
+
10
+ def self.update(id, params=nil, opts=nil)
11
+ raise NotImplementedError.new("Reversals cannot be updated without a transfer ID. Update a reversal using `r = transfer.reversals.retrieve('reversal_id'); r.save`")
8
12
  end
9
13
 
10
14
  def self.retrieve(id, opts={})
@@ -1,14 +1,14 @@
1
1
  module Stripe
2
2
  class SingletonAPIResource < APIResource
3
- def self.url
3
+ def self.resource_url
4
4
  if self == SingletonAPIResource
5
5
  raise NotImplementedError.new('SingletonAPIResource is an abstract class. You should perform actions on its subclasses (Account, etc.)')
6
6
  end
7
7
  "/v1/#{CGI.escape(class_name.downcase)}"
8
8
  end
9
9
 
10
- def url
11
- self.class.url
10
+ def resource_url
11
+ self.class.resource_url
12
12
  end
13
13
 
14
14
  def self.retrieve(opts={})
data/lib/stripe/sku.rb CHANGED
@@ -2,7 +2,7 @@ module Stripe
2
2
  class SKU < APIResource
3
3
  extend Stripe::APIOperations::List
4
4
  extend Stripe::APIOperations::Create
5
- include Stripe::APIOperations::Update
6
-
5
+ include Stripe::APIOperations::Save
6
+ include Stripe::APIOperations::Delete
7
7
  end
8
8
  end
@@ -0,0 +1,11 @@
1
+ module Stripe
2
+ class Source < APIResource
3
+ extend Stripe::APIOperations::Create
4
+ include Stripe::APIOperations::Save
5
+
6
+ def verify(params={}, opts={})
7
+ resp, opts = request(:post, resource_url + '/verify', params, opts)
8
+ initialize_from(resp.data, opts)
9
+ end
10
+ end
11
+ end