stripe 4.11.0 → 4.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +4 -0
  4. data/VERSION +1 -1
  5. data/lib/stripe.rb +1 -0
  6. data/lib/stripe/account.rb +2 -0
  7. data/lib/stripe/api_operations/delete.rb +24 -0
  8. data/lib/stripe/api_resource.rb +24 -0
  9. data/lib/stripe/charge.rb +2 -0
  10. data/lib/stripe/customer.rb +2 -0
  11. data/lib/stripe/discount.rb +7 -0
  12. data/lib/stripe/dispute.rb +2 -0
  13. data/lib/stripe/invoice.rb +6 -0
  14. data/lib/stripe/issuing/authorization.rb +3 -0
  15. data/lib/stripe/issuing/card.rb +2 -0
  16. data/lib/stripe/order.rb +3 -0
  17. data/lib/stripe/payment_intent.rb +4 -0
  18. data/lib/stripe/payment_method.rb +3 -0
  19. data/lib/stripe/payout.rb +2 -0
  20. data/lib/stripe/review.rb +2 -0
  21. data/lib/stripe/source.rb +2 -0
  22. data/lib/stripe/subscription.rb +2 -0
  23. data/lib/stripe/subscription_schedule.rb +3 -0
  24. data/lib/stripe/topup.rb +2 -0
  25. data/lib/stripe/transfer.rb +2 -0
  26. data/lib/stripe/util.rb +1 -0
  27. data/lib/stripe/version.rb +1 -1
  28. data/test/stripe/account_test.rb +26 -13
  29. data/test/stripe/apple_pay_domain_test.rb +17 -4
  30. data/test/stripe/charge_test.rb +21 -0
  31. data/test/stripe/coupon_test.rb +15 -5
  32. data/test/stripe/customer_test.rb +27 -9
  33. data/test/stripe/dispute_test.rb +9 -0
  34. data/test/stripe/ephemeral_key_test.rb +7 -0
  35. data/test/stripe/invoice_item_test.rb +17 -6
  36. data/test/stripe/invoice_test.rb +60 -6
  37. data/test/stripe/issuing/authorization_test.rb +32 -10
  38. data/test/stripe/issuing/card_test.rb +14 -5
  39. data/test/stripe/order_test.rb +20 -2
  40. data/test/stripe/payment_intent_test.rb +27 -0
  41. data/test/stripe/payment_method_test.rb +18 -0
  42. data/test/stripe/payout_test.rb +7 -0
  43. data/test/stripe/plan_test.rb +21 -15
  44. data/test/stripe/product_test.rb +15 -5
  45. data/test/stripe/radar/value_list_item_test.rb +15 -5
  46. data/test/stripe/radar/value_list_test.rb +15 -5
  47. data/test/stripe/recipient_test.rb +17 -4
  48. data/test/stripe/sku_test.rb +15 -5
  49. data/test/stripe/source_test.rb +13 -0
  50. data/test/stripe/subscription_item_test.rb +15 -5
  51. data/test/stripe/subscription_schedule_test.rb +29 -0
  52. data/test/stripe/subscription_test.rb +26 -6
  53. data/test/stripe/terminal/location_test.rb +15 -5
  54. data/test/stripe/terminal/reader_test.rb +15 -5
  55. data/test/stripe/topup_test.rb +8 -0
  56. data/test/stripe/webhook_endpoint_test.rb +17 -0
  57. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81c34bec9bdd939d6ebe5a63c4a14e617e609fceaba92275168bd57b5f5f4f9d
4
- data.tar.gz: 34365a8cd2d1a662984a387dba59891205a5a5e26bf4f7b7688d87340c210655
3
+ metadata.gz: a30c5b27bb9161913905e0ada304efcef00519446eb64cbf2e7c3d0d625a2810
4
+ data.tar.gz: d8503b19941c67e68c75b7b4e1c24cae2bd7a4c80a5b91e5c4e81058d23b658d
5
5
  SHA512:
6
- metadata.gz: 1cb0774d3e51ac40a97ff62dd16543cc5782ceeca4f4b38922867a3d3635f7aee5581fb454025f4672b4b40e22d685a81265f3f8a4367907f6050ba010a0564c
7
- data.tar.gz: 568a35c534b30e8d47be7a44f74401c590613e5f266746e4dc6214374350e3f7a855202d47e5846d0d787040548c3c2a6e11c027013dd421ecfd728453cf2e8c
6
+ metadata.gz: a3a0ecd3172c802dc16bacab0be7f3d34373ed2230d18e5a89b84814d3705568e6f0ca261fb576492c1ec3ef39132b17a9b9126ba69f3941e45a4b3f851a3f07
7
+ data.tar.gz: 7a6d70ebe915abe5774a4f5e55815e43ea24d6db4f4553ce77f18394b93aca8eeae051f9fd557d74bdda4d3e4d77112b821dca22a62c7284fc942392fc797638
@@ -2,7 +2,7 @@ inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
4
  DisplayCopNames: true
5
- TargetRubyVersion: 2.0
5
+ TargetRubyVersion: 2.1
6
6
 
7
7
  Layout/CaseIndentation:
8
8
  EnforcedStyle: end
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.12.0 - 2019-04-02
4
+ * [#752](https://github.com/stripe/stripe-ruby/pull/752) Add `.delete` class method on deletable API resources
5
+ * [#754](https://github.com/stripe/stripe-ruby/pull/754) Add class methods for all custom API requests (e.g. `Charge.capture`)
6
+
3
7
  ## 4.11.0 - 2019-03-26
4
8
  * [#753](https://github.com/stripe/stripe-ruby/pull/753) Add a global proxy configuration parameter
5
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.11.0
1
+ 4.12.0
@@ -53,6 +53,7 @@ require "stripe/checkout/session"
53
53
  require "stripe/country_spec"
54
54
  require "stripe/coupon"
55
55
  require "stripe/customer"
56
+ require "stripe/discount"
56
57
  require "stripe/dispute"
57
58
  require "stripe/ephemeral_key"
58
59
  require "stripe/event"
@@ -11,6 +11,8 @@ module Stripe
11
11
 
12
12
  OBJECT_NAME = "account".freeze
13
13
 
14
+ custom_method :reject, http_verb: :post
15
+
14
16
  save_nested_resource :external_account
15
17
  nested_resource_class_methods :external_account,
16
18
  operations: %i[create retrieve update delete list]
@@ -3,11 +3,35 @@
3
3
  module Stripe
4
4
  module APIOperations
5
5
  module Delete
6
+ module ClassMethods
7
+ # Deletes an API resource
8
+ #
9
+ # Deletes the identified resource with the passed in parameters.
10
+ #
11
+ # ==== Attributes
12
+ #
13
+ # * +id+ - ID of the resource to delete.
14
+ # * +params+ - A hash of parameters to pass to the API
15
+ # * +opts+ - A Hash of additional options (separate from the params /
16
+ # object values) to be added to the request. E.g. to allow for an
17
+ # idempotency_key to be passed in the request headers, or for the
18
+ # api_key to be overwritten. See {APIOperations::Request.request}.
19
+ def delete(id, params = {}, opts = {})
20
+ opts = Util.normalize_opts(opts)
21
+ resp, opts = request(:delete, "#{resource_url}/#{id}", params, opts)
22
+ Util.convert_to_stripe_object(resp.data, opts)
23
+ end
24
+ end
25
+
6
26
  def delete(params = {}, opts = {})
7
27
  opts = Util.normalize_opts(opts)
8
28
  resp, opts = request(:delete, resource_url, params, opts)
9
29
  initialize_from(resp.data, opts)
10
30
  end
31
+
32
+ def self.included(base)
33
+ base.extend(ClassMethods)
34
+ end
11
35
  end
12
36
  end
13
37
  end
@@ -48,6 +48,30 @@ module Stripe
48
48
  end
49
49
  end
50
50
 
51
+ # Adds a custom method to a resource class. This is used to add support for
52
+ # non-CRUDL API requests, e.g. capturing charges. custom_method takes the
53
+ # following parameters:
54
+ # - name: the name of the custom method to create (as a symbol)
55
+ # - http_verb: the HTTP verb for the API request (:get, :post, or :delete)
56
+ # - http_path: the path to append to the resource's URL. If not provided,
57
+ # the name is used as the path
58
+ #
59
+ # For example, this call:
60
+ # custom_method :capture, http_verb: post
61
+ # adds a `capture` class method to the resource class that, when called,
62
+ # will send a POST request to `/v1/<object_name>/capture`.
63
+ def self.custom_method(name, http_verb:, http_path: nil)
64
+ unless %i[get post delete].include?(http_verb)
65
+ raise ArgumentError, "Invalid http_verb value: #{http_verb.inspect}. Should be one of :get, :post or :delete."
66
+ end
67
+ http_path ||= name.to_s
68
+ define_singleton_method(name) do |id, params = {}, opts = {}|
69
+ url = "#{resource_url}/#{CGI.escape(id)}/#{CGI.escape(http_path)}"
70
+ resp, opts = request(http_verb, url, params, opts)
71
+ Util.convert_to_stripe_object(resp.data, opts)
72
+ end
73
+ end
74
+
51
75
  def resource_url
52
76
  unless (id = self["id"])
53
77
  raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", "id")
@@ -8,6 +8,8 @@ module Stripe
8
8
 
9
9
  OBJECT_NAME = "charge".freeze
10
10
 
11
+ custom_method :capture, http_verb: :post
12
+
11
13
  def refund(params = {}, opts = {})
12
14
  # Old versions of charge objects included a `refunds` field that was just
13
15
  # a vanilla array instead of a Stripe list object.
@@ -10,6 +10,8 @@ module Stripe
10
10
 
11
11
  OBJECT_NAME = "customer".freeze
12
12
 
13
+ custom_method :delete_discount, http_verb: :delete, http_path: "discount"
14
+
13
15
  save_nested_resource :source
14
16
  nested_resource_class_methods :source,
15
17
  operations: %i[create retrieve update delete list]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stripe
4
+ class Discount < StripeObject
5
+ OBJECT_NAME = "discount".freeze
6
+ end
7
+ end
@@ -7,6 +7,8 @@ module Stripe
7
7
 
8
8
  OBJECT_NAME = "dispute".freeze
9
9
 
10
+ custom_method :close, http_verb: :post
11
+
10
12
  def close(params = {}, opts = {})
11
13
  resp, opts = request(:post, close_url, params, opts)
12
14
  initialize_from(resp.data, opts)
@@ -9,6 +9,12 @@ module Stripe
9
9
 
10
10
  OBJECT_NAME = "invoice".freeze
11
11
 
12
+ custom_method :finalize_invoice, http_verb: :post, http_path: "finalize"
13
+ custom_method :mark_uncollectible, http_verb: :post
14
+ custom_method :pay, http_verb: :post
15
+ custom_method :send_invoice, http_verb: :post, http_path: "send"
16
+ custom_method :void_invoice, http_verb: :post, http_path: "void"
17
+
12
18
  def finalize_invoice(params = {}, opts = {})
13
19
  url = resource_url + "/finalize"
14
20
  resp, opts = request(:post, url, params, opts)
@@ -8,6 +8,9 @@ module Stripe
8
8
 
9
9
  OBJECT_NAME = "issuing.authorization".freeze
10
10
 
11
+ custom_method :approve, http_verb: :post
12
+ custom_method :decline, http_verb: :post
13
+
11
14
  def approve(params = {}, opts = {})
12
15
  resp, opts = request(:post, resource_url + "/approve", params, opts)
13
16
  initialize_from(resp.data, opts)
@@ -9,6 +9,8 @@ module Stripe
9
9
 
10
10
  OBJECT_NAME = "issuing.card".freeze
11
11
 
12
+ custom_method :details, http_verb: :get
13
+
12
14
  def details(params = {}, opts = {})
13
15
  resp, opts = request(:get, resource_url + "/details", params, opts)
14
16
  Util.convert_to_stripe_object(resp.data, opts)
@@ -8,6 +8,9 @@ module Stripe
8
8
 
9
9
  OBJECT_NAME = "order".freeze
10
10
 
11
+ custom_method :pay, http_verb: :post
12
+ custom_method :return_order, http_verb: :post, http_path: "returns"
13
+
11
14
  def pay(params, opts = {})
12
15
  resp, opts = request(:post, pay_url, params, opts)
13
16
  initialize_from(resp.data, opts)
@@ -8,6 +8,10 @@ module Stripe
8
8
 
9
9
  OBJECT_NAME = "payment_intent".freeze
10
10
 
11
+ custom_method :cancel, http_verb: :post
12
+ custom_method :capture, http_verb: :post
13
+ custom_method :confirm, http_verb: :post
14
+
11
15
  def cancel(params = {}, opts = {})
12
16
  resp, opts = request(:post, resource_url + "/cancel", params, opts)
13
17
  initialize_from(resp.data, opts)
@@ -8,6 +8,9 @@ module Stripe
8
8
 
9
9
  OBJECT_NAME = "payment_method".freeze
10
10
 
11
+ custom_method :attach, http_verb: :post
12
+ custom_method :detach, http_verb: :post
13
+
11
14
  def attach(params = {}, opts = {})
12
15
  url = resource_url + "/attach"
13
16
  resp, opts = request(:post, url, params, opts)
@@ -8,6 +8,8 @@ module Stripe
8
8
 
9
9
  OBJECT_NAME = "payout".freeze
10
10
 
11
+ custom_method :cancel, http_verb: :post
12
+
11
13
  def cancel
12
14
  resp, api_key = request(:post, cancel_url)
13
15
  initialize_from(resp.data, api_key)
@@ -6,6 +6,8 @@ module Stripe
6
6
 
7
7
  OBJECT_NAME = "review".freeze
8
8
 
9
+ custom_method :approve, http_verb: :post
10
+
9
11
  def approve(params = {}, opts = {})
10
12
  resp, opts = request(:post, resource_url + "/approve", params, opts)
11
13
  initialize_from(resp.data, opts)
@@ -7,6 +7,8 @@ module Stripe
7
7
 
8
8
  OBJECT_NAME = "source".freeze
9
9
 
10
+ custom_method :verify, http_verb: :post
11
+
10
12
  def detach(params = {}, opts = {})
11
13
  if !respond_to?(:customer) || customer.nil? || customer.empty?
12
14
  raise NotImplementedError,
@@ -9,6 +9,8 @@ module Stripe
9
9
 
10
10
  OBJECT_NAME = "subscription".freeze
11
11
 
12
+ custom_method :delete_discount, http_verb: :delete, http_path: "discount"
13
+
12
14
  save_nested_resource :source
13
15
 
14
16
  def delete_discount
@@ -9,6 +9,9 @@ module Stripe
9
9
 
10
10
  OBJECT_NAME = "subscription_schedule".freeze
11
11
 
12
+ custom_method :cancel, http_verb: :post
13
+ custom_method :release, http_verb: :post
14
+
12
15
  nested_resource_class_methods :revision,
13
16
  operations: %i[retrieve list]
14
17
 
@@ -8,6 +8,8 @@ module Stripe
8
8
 
9
9
  OBJECT_NAME = "topup".freeze
10
10
 
11
+ custom_method :cancel, http_verb: :post
12
+
11
13
  def cancel
12
14
  resp, api_key = request(:post, resource_url + "/cancel")
13
15
  initialize_from(resp.data, api_key)
@@ -9,6 +9,8 @@ module Stripe
9
9
 
10
10
  OBJECT_NAME = "transfer".freeze
11
11
 
12
+ custom_method :cancel, http_verb: :post
13
+
12
14
  nested_resource_class_methods :reversal, operations: %i[create retrieve update list]
13
15
 
14
16
  def cancel
@@ -62,6 +62,7 @@ module Stripe
62
62
  CountrySpec::OBJECT_NAME => CountrySpec,
63
63
  Coupon::OBJECT_NAME => Coupon,
64
64
  Customer::OBJECT_NAME => Customer,
65
+ Discount::OBJECT_NAME => Discount,
65
66
  Dispute::OBJECT_NAME => Dispute,
66
67
  EphemeralKey::OBJECT_NAME => EphemeralKey,
67
68
  Event::OBJECT_NAME => Event,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stripe
4
- VERSION = "4.11.0".freeze
4
+ VERSION = "4.12.0".freeze
5
5
  end
@@ -24,15 +24,18 @@ module Stripe
24
24
  end
25
25
 
26
26
  should "be rejectable" do
27
- account_data = { id: "acct_foo" }
28
- stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo")
29
- .to_return(body: JSON.generate(account_data))
30
-
31
- stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo/reject")
32
- .to_return(body: JSON.generate(account_data))
33
-
34
27
  account = Stripe::Account.retrieve("acct_foo")
35
- account.reject(reason: "fraud")
28
+ account = account.reject(reason: "fraud")
29
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{account.id}/reject"
30
+ assert account.is_a?(Stripe::Account)
31
+ end
32
+
33
+ context ".reject" do
34
+ should "reject the account" do
35
+ account = Stripe::Account.reject("acct_foo", reason: "fraud")
36
+ assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{account.id}/reject"
37
+ assert account.is_a?(Stripe::Account)
38
+ end
36
39
  end
37
40
 
38
41
  should "be creatable" do
@@ -54,11 +57,21 @@ module Stripe
54
57
  assert account.is_a?(Stripe::Account)
55
58
  end
56
59
 
57
- should "be deletable" do
58
- account = Stripe::Account.retrieve("acct_123")
59
- account = account.delete
60
- assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{account.id}"
61
- assert account.is_a?(Stripe::Account)
60
+ context "#delete" do
61
+ should "be deletable" do
62
+ account = Stripe::Account.retrieve("acct_123")
63
+ account = account.delete
64
+ assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{account.id}"
65
+ assert account.is_a?(Stripe::Account)
66
+ end
67
+ end
68
+
69
+ context ".delete" do
70
+ should "be deletable" do
71
+ account = Stripe::Account.delete("acct_123")
72
+ assert_requested :delete, "#{Stripe.api_base}/v1/accounts/acct_123"
73
+ assert account.is_a?(Stripe::Account)
74
+ end
62
75
  end
63
76
 
64
77
  should "be able to list Persons" do
@@ -24,10 +24,23 @@ module Stripe
24
24
  end
25
25
 
26
26
  should "be deletable" do
27
- domain = Stripe::ApplePayDomain.retrieve("apwc_123")
28
- domain = domain.delete
29
- assert_requested :delete, "#{Stripe.api_base}/v1/apple_pay/domains/#{domain.id}"
30
- assert domain.is_a?(Stripe::ApplePayDomain)
27
+ end
28
+
29
+ context "#delete" do
30
+ should "be deletable" do
31
+ domain = Stripe::ApplePayDomain.retrieve("apwc_123")
32
+ domain = domain.delete
33
+ assert_requested :delete, "#{Stripe.api_base}/v1/apple_pay/domains/#{domain.id}"
34
+ assert domain.is_a?(Stripe::ApplePayDomain)
35
+ end
36
+ end
37
+
38
+ context ".delete" do
39
+ should "be deletable" do
40
+ domain = Stripe::ApplePayDomain.delete("apwc_123")
41
+ assert_requested :delete, "#{Stripe.api_base}/v1/apple_pay/domains/apwc_123"
42
+ assert domain.is_a?(Stripe::ApplePayDomain)
43
+ end
31
44
  end
32
45
  end
33
46
  end
@@ -40,6 +40,27 @@ module Stripe
40
40
  assert charge.is_a?(Stripe::Charge)
41
41
  end
42
42
 
43
+ context "#capture" do
44
+ should "capture the charge" do
45
+ charge = Stripe::Charge.retrieve("ch_123")
46
+ charge = charge.capture(amount: 100)
47
+ assert_requested :post,
48
+ "#{Stripe.api_base}/v1/charges/ch_123/capture",
49
+ body: { amount: 100 }
50
+ assert charge.is_a?(Stripe::Charge)
51
+ end
52
+ end
53
+
54
+ context ".capture" do
55
+ should "capture the charge" do
56
+ charge = Stripe::Charge.capture("ch_123", amount: 100)
57
+ assert_requested :post,
58
+ "#{Stripe.api_base}/v1/charges/ch_123/capture",
59
+ body: { amount: 100 }
60
+ assert charge.is_a?(Stripe::Charge)
61
+ end
62
+ end
63
+
43
64
  context "#mark_as_fraudulent" do
44
65
  should "charges should be able to be marked as fraudulent" do
45
66
  charge = Stripe::Charge.retrieve("ch_123")
@@ -41,11 +41,21 @@ module Stripe
41
41
  assert coupon.is_a?(Stripe::Coupon)
42
42
  end
43
43
 
44
- should "be deletable" do
45
- coupon = Stripe::Coupon.retrieve("25OFF")
46
- coupon = coupon.delete
47
- assert_requested :delete, "#{Stripe.api_base}/v1/coupons/#{coupon.id}"
48
- assert coupon.is_a?(Stripe::Coupon)
44
+ context "#delete" do
45
+ should "be deletable" do
46
+ coupon = Stripe::Coupon.delete("25OFF")
47
+ assert_requested :delete, "#{Stripe.api_base}/v1/coupons/#{coupon.id}"
48
+ assert coupon.is_a?(Stripe::Coupon)
49
+ end
50
+ end
51
+
52
+ context ".delete" do
53
+ should "be deletable" do
54
+ coupon = Stripe::Coupon.retrieve("25OFF")
55
+ coupon = coupon.delete
56
+ assert_requested :delete, "#{Stripe.api_base}/v1/coupons/25OFF"
57
+ assert coupon.is_a?(Stripe::Coupon)
58
+ end
49
59
  end
50
60
  end
51
61
  end