Class: Stripe::CreditNoteService

Inherits:
StripeService show all
Defined in:
lib/stripe/services/credit_note_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from StripeService

#request, #request_stream

Constructor Details

#initialize(requestor) ⇒ CreditNoteService

Returns a new instance of CreditNoteService.



8
9
10
11
12
# File 'lib/stripe/services/credit_note_service.rb', line 8

def initialize(requestor)
  super
  @line_items = Stripe::CreditNoteLineItemService.new(@requestor)
  @preview_lines = Stripe::CreditNotePreviewLinesService.new(@requestor)
end

Instance Attribute Details

#line_itemsObject (readonly)

Returns the value of attribute line_items.



6
7
8
# File 'lib/stripe/services/credit_note_service.rb', line 6

def line_items
  @line_items
end

#preview_linesObject (readonly)

Returns the value of attribute preview_lines.



6
7
8
# File 'lib/stripe/services/credit_note_service.rb', line 6

def preview_lines
  @preview_lines
end

Instance Method Details

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

Issue a credit note to adjust the amount of a finalized invoice. A credit note will first reduce the invoice’s amount_remaining (and amount_due), but not below zero. This amount is indicated by the credit note’s pre_payment_amount. The excess amount is indicated by post_payment_amount, and it can result in any combination of the following:

Refunds: create a new refund (using refund_amount) or link existing refunds (using refunds). Customer balance credit: credit the customer’s balance (using credit_amount) which will be automatically applied to their next invoice when it’s finalized. Outside of Stripe credit: record the amount that is or will be credited outside of Stripe (using out_of_band_amount).

The sum of refunds, customer balance credits, and outside of Stripe credits must equal the post_payment_amount.

You may issue multiple credit notes for an invoice. Each credit note may increment the invoice’s pre_payment_credit_notes_amount, post_payment_credit_notes_amount, or both, depending on the invoice’s amount_remaining at the time of credit note creation.

For invoices that also have refunds created through the [Refund API](docs.stripe.com/docs/api/refunds), the credit note API subtracts those refund amounts from the maximum creditable amount. This prevents the combined credit notes and refunds from exceeding the invoice amount. If you use both, ensure the combined total does not exceed the invoice’s paid amount.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/stripe/services/credit_note_service.rb', line 29

def create(params = {}, opts = {})
  params = ::Stripe::CreditNoteCreateParams.coerce_params(params) unless params.is_a?(Stripe::RequestParams)

  request(
    method: :post,
    path: "/v1/credit_notes",
    params: params,
    opts: opts,
    base_address: :api
  )
end

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

Returns a list of credit notes.



42
43
44
45
46
47
48
49
50
# File 'lib/stripe/services/credit_note_service.rb', line 42

def list(params = {}, opts = {})
  request(
    method: :get,
    path: "/v1/credit_notes",
    params: params,
    opts: opts,
    base_address: :api
  )
end

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

Get a preview of a credit note without creating it.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/stripe/services/credit_note_service.rb', line 53

def preview(params = {}, opts = {})
  params = ::Stripe::CreditNotePreviewParams.coerce_params(params) unless params.is_a?(Stripe::RequestParams)

  request(
    method: :get,
    path: "/v1/credit_notes/preview",
    params: params,
    opts: opts,
    base_address: :api
  )
end

#retrieve(id, params = {}, opts = {}) ⇒ Object

Retrieves the credit note object with the given identifier.



66
67
68
69
70
71
72
73
74
# File 'lib/stripe/services/credit_note_service.rb', line 66

def retrieve(id, params = {}, opts = {})
  request(
    method: :get,
    path: format("/v1/credit_notes/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

#update(id, params = {}, opts = {}) ⇒ Object

Updates an existing credit note.



77
78
79
80
81
82
83
84
85
# File 'lib/stripe/services/credit_note_service.rb', line 77

def update(id, params = {}, opts = {})
  request(
    method: :post,
    path: format("/v1/credit_notes/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

#void_credit_note(id, params = {}, opts = {}) ⇒ Object

Marks a credit note as void. Learn more about [voiding credit notes](docs.stripe.com/docs/billing/invoices/credit-notes#voiding).



88
89
90
91
92
93
94
95
96
# File 'lib/stripe/services/credit_note_service.rb', line 88

def void_credit_note(id, params = {}, opts = {})
  request(
    method: :post,
    path: format("/v1/credit_notes/%<id>s/void", { id: CGI.escape(id) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end