mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-04 00:00:47 -04:00
Adds the magic `frozen_string_literal: true` comment to every file and enables a Rubocop rule to make sure that it's always going to be there going forward as well. See here for more background [1], but the basic idea is that unlike many other languages, static strings in code are mutable by default. This has since been acknowledged as not a particularly good idea, and the intention is to rectify the mistake when Ruby 3 comes out, where all string literals will be frozen. The `frozen_string_literal` magic comment was introduced in Ruby 2.3 as a way of easing the transition, and allows libraries and projects to freeze their literals in advance. I don't think this is breaking in any way: it's possible that users might've been pulling out one of are literals somehow and mutating it, but that would probably not have been useful for anything and would certainly not be recommended, so I'm quite comfortable pushing this change through as a minor version. As discussed in #641. [1] https://stackoverflow.com/a/37799399
85 lines
2.3 KiB
Ruby
85 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Stripe
|
|
class Charge < APIResource
|
|
extend Stripe::APIOperations::List
|
|
extend Stripe::APIOperations::Create
|
|
include Stripe::APIOperations::Save
|
|
|
|
OBJECT_NAME = "charge".freeze
|
|
|
|
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)
|
|
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
|
|
|
|
def dispute_url
|
|
resource_url + "/dispute"
|
|
end
|
|
|
|
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.
|
|
def refund_url
|
|
resource_url + "/refund"
|
|
end
|
|
end
|
|
end
|