Class: Stripe::Charge

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Includes:
APIOperations::Save
Defined in:
lib/stripe/resources/charge.rb

Constant Summary collapse

OBJECT_NAME =
"charge".freeze

Instance Attribute Summary

Attributes inherited from APIResource

#save_with_parent

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Save

included, #save

Methods inherited from APIResource

class_name, custom_method, #refresh, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #refresh_from, serialize_params, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Method Details

#capture(params = {}, opts = {}) ⇒ Object



34
35
36
37
# File 'lib/stripe/resources/charge.rb', line 34

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

#close_dispute(params = {}, opts = {}) ⇒ Object



45
46
47
48
# File 'lib/stripe/resources/charge.rb', line 45

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

#mark_as_fraudulentObject



50
51
52
53
54
55
56
# File 'lib/stripe/resources/charge.rb', line 50

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

#mark_as_safeObject



58
59
60
61
62
63
64
# File 'lib/stripe/resources/charge.rb', line 58

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

#refund(params = {}, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stripe/resources/charge.rb', line 13

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

#update_dispute(params = {}, opts = {}) ⇒ Object



39
40
41
42
43
# File 'lib/stripe/resources/charge.rb', line 39

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