Class: Stripe::Refund

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

Overview

Refund objects allow you to refund a previously created charge that isn't refunded yet. Funds are refunded to the credit or debit card that's initially charged.

Related guide: Refunds

Defined Under Namespace

Classes: DestinationDetails, NextAction, PresentmentDetails, TestHelpers

Constant Summary collapse

OBJECT_NAME =
"refund"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

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, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, #_get_inner_class_type, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, field_encodings, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #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 Attribute Details

#amountObject (readonly)

Amount, in cents (or local equivalent).



656
657
658
# File 'lib/stripe/resources/refund.rb', line 656

def amount
  @amount
end

#balance_transactionObject (readonly)

Balance transaction that describes the impact on your account balance.



658
659
660
# File 'lib/stripe/resources/refund.rb', line 658

def balance_transaction
  @balance_transaction
end

#chargeObject (readonly)

ID of the charge that's refunded.



660
661
662
# File 'lib/stripe/resources/refund.rb', line 660

def charge
  @charge
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



662
663
664
# File 'lib/stripe/resources/refund.rb', line 662

def created
  @created
end

#currencyObject (readonly)

Three-letter ISO currency code, in lowercase. Must be a supported currency.



664
665
666
# File 'lib/stripe/resources/refund.rb', line 664

def currency
  @currency
end

#customerObject (readonly)

ID of the customer of this refund.



666
667
668
# File 'lib/stripe/resources/refund.rb', line 666

def customer
  @customer
end

#customer_accountObject (readonly)

ID of the account of this refund.



668
669
670
# File 'lib/stripe/resources/refund.rb', line 668

def 
  @customer_account
end

#descriptionObject (readonly)

An arbitrary string attached to the object. You can use this for displaying to users (available on non-card refunds only).



670
671
672
# File 'lib/stripe/resources/refund.rb', line 670

def description
  @description
end

#destination_detailsObject (readonly)

Attribute for field destination_details



672
673
674
# File 'lib/stripe/resources/refund.rb', line 672

def destination_details
  @destination_details
end

#failure_balance_transactionObject (readonly)

After the refund fails, this balance transaction describes the adjustment made on your account balance that reverses the initial balance transaction.



674
675
676
# File 'lib/stripe/resources/refund.rb', line 674

def failure_balance_transaction
  @failure_balance_transaction
end

#failure_reasonObject (readonly)

Provides the reason for the refund failure. Possible values are: lost_or_stolen_card, expired_or_canceled_card, charge_for_pending_refund_disputed, insufficient_funds, declined, merchant_request, or unknown.



676
677
678
# File 'lib/stripe/resources/refund.rb', line 676

def failure_reason
  @failure_reason
end

#idObject (readonly)

Unique identifier for the object.



678
679
680
# File 'lib/stripe/resources/refund.rb', line 678

def id
  @id
end

#instructions_emailObject (readonly)

For payment methods without native refund support (for example, Konbini, PromptPay), provide an email address for the customer to receive refund instructions.



680
681
682
# File 'lib/stripe/resources/refund.rb', line 680

def instructions_email
  @instructions_email
end

#metadataObject (readonly)

Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



682
683
684
# File 'lib/stripe/resources/refund.rb', line 682

def 
  @metadata
end

#next_actionObject (readonly)

Attribute for field next_action



684
685
686
# File 'lib/stripe/resources/refund.rb', line 684

def next_action
  @next_action
end

#objectObject (readonly)

String representing the object's type. Objects of the same type share the same value.



686
687
688
# File 'lib/stripe/resources/refund.rb', line 686

def object
  @object
end

#payment_intentObject (readonly)

ID of the PaymentIntent that's refunded.



688
689
690
# File 'lib/stripe/resources/refund.rb', line 688

def payment_intent
  @payment_intent
end

#payment_methodObject (readonly)

ID of the payment method associated with this refund.



690
691
692
# File 'lib/stripe/resources/refund.rb', line 690

def payment_method
  @payment_method
end

#pending_reasonObject (readonly)

Provides the reason for why the refund is pending. Possible values are: processing, insufficient_funds, or charge_pending.



692
693
694
# File 'lib/stripe/resources/refund.rb', line 692

def pending_reason
  @pending_reason
end

#presentment_detailsObject (readonly)

Attribute for field presentment_details



694
695
696
# File 'lib/stripe/resources/refund.rb', line 694

def presentment_details
  @presentment_details
end

#reasonObject (readonly)

Reason for the refund, which is either user-provided (duplicate, fraudulent, or requested_by_customer) or generated by Stripe internally (expired_uncaptured_charge).



696
697
698
# File 'lib/stripe/resources/refund.rb', line 696

def reason
  @reason
end

#receipt_numberObject (readonly)

This is the transaction number that appears on email receipts sent for this refund.



698
699
700
# File 'lib/stripe/resources/refund.rb', line 698

def receipt_number
  @receipt_number
end

#source_transfer_reversalObject (readonly)

The transfer reversal that's associated with the refund. Only present if the charge came from another Stripe account.



700
701
702
# File 'lib/stripe/resources/refund.rb', line 700

def source_transfer_reversal
  @source_transfer_reversal
end

#statusObject (readonly)

Status of the refund. This can be pending, requires_action, succeeded, failed, or canceled. Learn more about failed refunds.



702
703
704
# File 'lib/stripe/resources/refund.rb', line 702

def status
  @status
end

#transfer_reversalObject (readonly)

This refers to the transfer reversal object if the accompanying transfer reverses. This is only applicable if the charge was created using the destination parameter.



704
705
706
# File 'lib/stripe/resources/refund.rb', line 704

def transfer_reversal
  @transfer_reversal
end

Class Method Details

.cancel(refund, params = {}, opts = {}) ⇒ Object

Cancels a refund with a status of requires_action.

You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.



721
722
723
724
725
726
727
728
# File 'lib/stripe/resources/refund.rb', line 721

def self.cancel(refund, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/refunds/%<refund>s/cancel", { refund: CGI.escape(refund) }),
    params: params,
    opts: opts
  )
end

.create(params = {}, opts = {}) ⇒ Object

When you create a new refund, you must specify a Charge or a PaymentIntent object on which to create it.

Creating a new refund will refund a charge that has previously been created but not yet refunded. Funds will be refunded to the credit or debit card that was originally charged.

You can optionally refund only part of a charge. You can do so multiple times, until the entire charge has been refunded.

Once entirely refunded, a charge can't be refunded again. This method will raise an error when called on an already-refunded charge, or when trying to refund more money than is left on a charge.



741
742
743
# File 'lib/stripe/resources/refund.rb', line 741

def self.create(params = {}, opts = {})
  request_stripe_object(method: :post, path: "/v1/refunds", params: params, opts: opts)
end

.field_remappingsObject



801
802
803
# File 'lib/stripe/resources/refund.rb', line 801

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



793
794
795
796
797
798
799
# File 'lib/stripe/resources/refund.rb', line 793

def self.inner_class_types
  @inner_class_types = {
    destination_details: DestinationDetails,
    next_action: NextAction,
    presentment_details: PresentmentDetails,
  }
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of all refunds you created. We return the refunds in sorted order, with the most recent refunds appearing first. The 10 most recent refunds are always available by default on the Charge object.



746
747
748
# File 'lib/stripe/resources/refund.rb', line 746

def self.list(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/refunds", params: params, opts: opts)
end

.object_nameObject



16
17
18
# File 'lib/stripe/resources/refund.rb', line 16

def self.object_name
  "refund"
end

.update(refund, params = {}, opts = {}) ⇒ Object

Updates the refund that you specify by setting the values of the passed parameters. Any parameters that you don't provide remain unchanged.

This request only accepts metadata as an argument.



753
754
755
756
757
758
759
760
# File 'lib/stripe/resources/refund.rb', line 753

def self.update(refund, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/refunds/%<refund>s", { refund: CGI.escape(refund) }),
    params: params,
    opts: opts
  )
end

Instance Method Details

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

Cancels a refund with a status of requires_action.

You can't cancel refunds in other states. Only refunds for payment methods that require customer action can enter the requires_action state.



709
710
711
712
713
714
715
716
# File 'lib/stripe/resources/refund.rb', line 709

def cancel(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/refunds/%<refund>s/cancel", { refund: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end

#test_helpersObject



762
763
764
# File 'lib/stripe/resources/refund.rb', line 762

def test_helpers
  TestHelpers.new(self)
end