lib/stripe/resources/invoice.rb in stripe-10.6.0 vs lib/stripe/resources/invoice.rb in stripe-10.7.0.pre.beta.1
- old
+ new
@@ -38,13 +38,34 @@
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
extend Stripe::APIOperations::Search
include Stripe::APIOperations::Save
+ extend Stripe::APIOperations::NestedResource
OBJECT_NAME = "invoice"
+ nested_resource_class_methods :payment, operations: %i[retrieve list]
+
+ # Attaches a PaymentIntent to the invoice, adding it to the list of payments.
+ # When the PaymentIntent's status changes to succeeded, the payment is credited
+ # to the invoice, increasing its amount_paid. When the invoice is fully paid, the
+ # invoice's status becomes paid.
+ #
+ # If the PaymentIntent's status is already succeeded when it is attached, it is
+ # credited to the invoice immediately.
+ #
+ # Related guide: [Create an invoice payment](https://stripe.com/docs/invoicing/payments/create)
+ def attach_payment_intent(params = {}, opts = {})
+ request_stripe_object(
+ method: :post,
+ path: format("/v1/invoices/%<invoice>s/attach_payment_intent", { invoice: CGI.escape(self["id"]) }),
+ params: params,
+ opts: opts
+ )
+ end
+
# Stripe automatically finalizes drafts before sending and attempting payment on invoices. However, if you'd like to finalize a draft invoice manually, you can do so using this method.
def finalize_invoice(params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/invoices/%<invoice>s/finalize", { invoice: CGI.escape(self["id"]) }),
@@ -88,9 +109,27 @@
# Mark a finalized invoice as void. This cannot be undone. Voiding an invoice is similar to [deletion](https://stripe.com/docs/api#delete_invoice), however it only applies to finalized invoices and maintains a papertrail where the invoice can still be found.
def void_invoice(params = {}, opts = {})
request_stripe_object(
method: :post,
path: format("/v1/invoices/%<invoice>s/void", { invoice: CGI.escape(self["id"]) }),
+ params: params,
+ opts: opts
+ )
+ end
+
+ # Attaches a PaymentIntent to the invoice, adding it to the list of payments.
+ # When the PaymentIntent's status changes to succeeded, the payment is credited
+ # to the invoice, increasing its amount_paid. When the invoice is fully paid, the
+ # invoice's status becomes paid.
+ #
+ # If the PaymentIntent's status is already succeeded when it is attached, it is
+ # credited to the invoice immediately.
+ #
+ # Related guide: [Create an invoice payment](https://stripe.com/docs/invoicing/payments/create)
+ def self.attach_payment_intent(invoice, params = {}, opts = {})
+ request_stripe_object(
+ method: :post,
+ path: format("/v1/invoices/%<invoice>s/attach_payment_intent", { invoice: CGI.escape(invoice) }),
params: params,
opts: opts
)
end