Skip to content

Commit

Permalink
Remove old deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Aug 6, 2019
1 parent 28e98bc commit 8bf0269
Show file tree
Hide file tree
Showing 18 changed files with 6 additions and 361 deletions.
4 changes: 0 additions & 4 deletions lib/stripe/resources/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ def reject(params = {}, opts = {})

nested_resource_class_methods :login_link, operations: %i[create]

# This method is deprecated. Please use `#external_account=` instead.
save_nested_resource :bank_account
deprecate :bank_account=, "#external_account=", 2017, 8

def resource_url
if self["id"]
super
Expand Down
11 changes: 0 additions & 11 deletions lib/stripe/resources/application_fee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,5 @@ class ApplicationFee < APIResource

nested_resource_class_methods :refund,
operations: %i[create retrieve update list]

# If you don't need access to an updated fee object after the refund, it's
# more performant to just call `fee.refunds.create` directly.
def refund(params = {}, opts = {})
refunds.create(params, opts)

# now that a refund has been created, we expect the state of this object
# to change as well (i.e. `refunded` will now be `true`) so refresh it
# from the server
refresh
end
end
end
68 changes: 1 addition & 67 deletions lib/stripe/resources/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,9 @@ class Charge < APIResource

custom_method :capture, http_verb: :post

def refund(params = {}, opts = {})
# Old versions of charge objects included a `refunds` field that was just
# a vanilla array instead of a Stripe list object.
#
# Where possible, we'd still like to use the new refund endpoint (thus
# `self.refunds.create`), but detect the old API version by looking for
# an `Array` and fall back to the old refund URL if necessary so as to
# maintain internal compatibility.
if refunds.is_a?(Array)
resp, opts = request(:post, refund_url, params, opts)
initialize_from(resp.data, opts)
else
refunds.create(params, opts)

# now that a refund has been created, we expect the state of this object
# to change as well (i.e. `refunded` will now be `true`) so refresh it
# from the server
refresh
end
end

def capture(params = {}, opts = {})
resp, opts = request(:post, capture_url, params, opts)
initialize_from(resp.data, opts)
end

def update_dispute(params = {}, opts = {})
resp, opts = request(:post, dispute_url, params, opts)
initialize_from({ dispute: resp.data }, opts, true)
dispute
end

def close_dispute(params = {}, opts = {})
resp, opts = request(:post, close_dispute_url, params, opts)
initialize_from(resp.data, opts)
end

def mark_as_fraudulent
params = {
fraud_details: { user_report: "fraudulent" },
}
resp, opts = request(:post, resource_url, params)
resp, opts = request(:post, resource_url + "/capture", params, opts)
initialize_from(resp.data, opts)
end

def mark_as_safe
params = {
fraud_details: { user_report: "safe" },
}
resp, opts = request(:post, resource_url, params)
initialize_from(resp.data, opts)
end

private def capture_url
resource_url + "/capture"
end

private def dispute_url
resource_url + "/dispute"
end

private def close_dispute_url
resource_url + "/dispute/close"
end

# Note that this is actually the *old* refund URL and its use is no longer
# preferred.
private def refund_url
resource_url + "/refund"
end
end
end
64 changes: 2 additions & 62 deletions lib/stripe/resources/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,9 @@ class << self
alias detach_source delete_source
end

def add_invoice_item(params, opts = {})
opts = @opts.merge(Util.normalize_opts(opts))
InvoiceItem.create(params.merge(customer: id), opts)
end

def invoices(params = {}, opts = {})
opts = @opts.merge(Util.normalize_opts(opts))
Invoice.all(params.merge(customer: id), opts)
end

def invoice_items(params = {}, opts = {})
opts = @opts.merge(Util.normalize_opts(opts))
InvoiceItem.all(params.merge(customer: id), opts)
end

def upcoming_invoice(params = {}, opts = {})
opts = @opts.merge(Util.normalize_opts(opts))
Invoice.upcoming(params.merge(customer: id), opts)
end

def charges(params = {}, opts = {})
opts = @opts.merge(Util.normalize_opts(opts))
Charge.all(params.merge(customer: id), opts)
end

def create_upcoming_invoice(params = {}, opts = {})
opts = @opts.merge(Util.normalize_opts(opts))
Invoice.create(params.merge(customer: id), opts)
end

def cancel_subscription(params = {}, opts = {})
resp, opts = request(:delete, subscription_url, params, opts)
initialize_from({ subscription: resp.data }, opts, true)
subscription
end

def update_subscription(params = {}, opts = {})
resp, opts = request(:post, subscription_url, params, opts)
initialize_from({ subscription: resp.data }, opts, true)
subscription
end

def create_subscription(params = {}, opts = {})
resp, opts = request(:post, subscriptions_url, params, opts)
initialize_from({ subscription: resp.data }, opts, true)
subscription
end

def delete_discount
_, opts = request(:delete, discount_url)
initialize_from({ discount: nil }, opts, true)
end

private def discount_url
resource_url + "/discount"
end

private def subscription_url
resource_url + "/subscription"
end

private def subscriptions_url
resource_url + "/subscriptions"
resp, opts = request(:delete, resource_url + "/discount")
initialize_from(resp.data, opts, true)
end
end
end
6 changes: 0 additions & 6 deletions lib/stripe/resources/dispute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,5 @@ def close(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/close", params, opts)
initialize_from(resp.data, opts)
end

def close_url
resource_url + "/close"
end
extend Gem::Deprecate
deprecate :close_url, :none, 2019, 11
end
end
5 changes: 0 additions & 5 deletions lib/stripe/resources/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,3 @@ def self.create(params = {}, opts = {})
end
end
end

module Stripe
# For backwards compatibility, the `File` class is aliased to `FileUpload`.
FileUpload = File
end
8 changes: 0 additions & 8 deletions lib/stripe/resources/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,5 @@ def return_order(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/returns", params, opts)
Util.convert_to_stripe_object(resp.data, opts)
end

private def pay_url
resource_url + "/pay"
end

private def returns_url
resource_url + "/returns"
end
end
end
6 changes: 0 additions & 6 deletions lib/stripe/resources/payout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,5 @@ def cancel(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/cancel", params, opts)
initialize_from(resp.data, opts)
end

def cancel_url
resource_url + "/cancel"
end
extend Gem::Deprecate
deprecate :cancel_url, :none, 2019, 11
end
end
4 changes: 0 additions & 4 deletions lib/stripe/resources/recipient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ class Recipient < APIResource
include Stripe::APIOperations::Save

OBJECT_NAME = "recipient"

def transfers
Transfer.all({ recipient: id }, @api_key)
end
end
end
6 changes: 0 additions & 6 deletions lib/stripe/resources/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ def detach(params = {}, opts = {})
initialize_from(resp.data, opts)
end

def delete(params = {}, opts = {})
detach(params, opts)
end
extend Gem::Deprecate
deprecate :delete, "#detach", 2017, 10

def source_transactions(params = {}, opts = {})
resp, opts = request(:get, resource_url + "/source_transactions", params,
opts)
Expand Down
8 changes: 2 additions & 6 deletions lib/stripe/resources/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ class Subscription < APIResource
save_nested_resource :source

def delete_discount
_, opts = request(:delete, discount_url)
initialize_from({ discount: nil }, opts, true)
end

private def discount_url
resource_url + "/discount"
resp, opts = request(:delete, resource_url + "/discount")
initialize_from(resp.data, opts, true)
end
end
end
5 changes: 0 additions & 5 deletions lib/stripe/resources/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@ def cancel(params = {}, opts = {})
resp, opts = request(:post, resource_url + "/cancel", params, opts)
initialize_from(resp.data, opts)
end

def cancel_url
resource_url + "/cancel"
end
deprecate :cancel_url, :none, 2019, 11
end
end
16 changes: 0 additions & 16 deletions test/stripe/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,6 @@ class AccountTest < Test::Unit::TestCase
assert persons.data[0].is_a?(Stripe::Person)
end

context "#bank_account=" do
should "warn that #bank_account= is deprecated" do
old_stderr = $stderr
$stderr = StringIO.new
begin
account = Stripe::Account.retrieve("acct_123")
account.bank_account = "tok_123"
message = "NOTE: Stripe::Account#bank_account= is " \
"deprecated; use #external_account= instead"
assert_match Regexp.new(message), $stderr.string
ensure
$stderr = old_stderr
end
end
end

context "#deauthorize" do
should "deauthorize an account" do
account = Stripe::Account.retrieve("acct_123")
Expand Down
8 changes: 0 additions & 8 deletions test/stripe/api_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,6 @@ class NestedTestAPIResource < APIResource
assert_equal c.created, 12_345
end

should "accessing a property other than id or parent on an unfetched object should fetch it" do
stub_request(:get, "#{Stripe.api_base}/v1/charges")
.with(query: { customer: "cus_123" })
.to_return(body: JSON.generate(customer_fixture))
c = Stripe::Customer.new("cus_123")
c.charges
end

should "updating an object should issue a POST request with only the changed properties" do
stub_request(:post, "#{Stripe.api_base}/v1/customers/cus_123")
.with(body: { "description" => "another_mn" })
Expand Down
16 changes: 0 additions & 16 deletions test/stripe/charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,5 @@ class ChargeTest < Test::Unit::TestCase
assert charge.is_a?(Stripe::Charge)
end
end

context "#mark_as_fraudulent" do
should "charges should be able to be marked as fraudulent" do
charge = Stripe::Charge.retrieve("ch_123")
charge = charge.mark_as_fraudulent
assert charge.is_a?(Stripe::Charge)
end
end

context "#mark_as_safe" do
should "charges should be able to be marked as safe" do
charge = Stripe::Charge.retrieve("ch_123")
charge = charge.mark_as_safe
assert charge.is_a?(Stripe::Charge)
end
end
end
end
45 changes: 1 addition & 44 deletions test/stripe/customer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,50 +53,6 @@ class CustomerTest < Test::Unit::TestCase
end
end

context "#create_subscription" do
should "create a new subscription" do
customer = Stripe::Customer.retrieve("cus_123")
subscription = customer.create_subscription(items: [{ plan: "silver" }])
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscriptions"
assert subscription.is_a?(Stripe::Subscription)
end
end

context "#create_upcoming_invoice" do
should "create a new invoice" do
customer = Stripe::Customer.retrieve("cus_123")
invoice = customer.create_upcoming_invoice
assert_requested :post, "#{Stripe.api_base}/v1/invoices"
assert invoice.is_a?(Stripe::Invoice)
end
end

context "#update_subscription" do
should "update a subscription" do
customer = Stripe::Customer.retrieve("cus_123")

# deprecated API and not in schema
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription")
.with(body: { plan: "silver" })
.to_return(body: JSON.generate(object: "subscription"))
subscription = customer.update_subscription(plan: "silver")
assert subscription.is_a?(Stripe::Subscription)
end
end

context "#cancel_subscription" do
should "cancel a subscription" do
customer = Stripe::Customer.retrieve("cus_123")

# deprecated API and not in schema
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription")
.with(query: { at_period_end: "true" })
.to_return(body: JSON.generate(object: "subscription"))
subscription = customer.cancel_subscription(at_period_end: "true")
assert subscription.is_a?(Stripe::Subscription)
end
end

context "#delete_discount" do
should "delete a discount" do
customer = Stripe::Customer.retrieve("cus_123")
Expand All @@ -113,6 +69,7 @@ class CustomerTest < Test::Unit::TestCase
assert discount.is_a?(Stripe::Discount)
end
end

context "#create_source" do
should "create a source" do
Stripe::Customer.create_source(
Expand Down
Loading

0 comments on commit 8bf0269

Please sign in to comment.