capture() function to capture payment on an invoice. This returns a
Transaction object if it is successful or reports an error if the request cannot be handled. See the guide page about capturing a payment for examples and for more detail about how capturing fits into the payment flow.
Note that when
capture() returns the
Transaction object, this does not necessarily mean that the payment has succeeded immediately. You should check the
status field of the object for
completed status to confirm the payment. We recommend that you use webhooks to receive updates about the status of the transaction because it can change even after the
capture() call has returned.
You must provide a payment source for the capture (
Token, or gateway request) unless it has been Authorizing an invoice previously. You can also pass an
options object as a second parameter to enable extra features on Payment Service Providers (PSPs) that support them. The options include:
capture_amount: Some PSPs support partial captures, where the amount you eventually capture is less than the amount you originally specified in the invoice. Use
capture_amountto choose the amount for a partial capture, if your PSPs provide this feature. For PSPs that do not support partial captures, you can get the same effect by capturing the full amount and then issuing a partial refund later.
capture_statement_descriptor: When you create an invoice, you can supply a statement descriptor, which is the text that will appear on the customer's bank statement for the payment. Some PSPs let you change the statement descriptor during capture. Set
capture_statement_descriptorto the new text you want to use for the descriptor or omit this option to use the original descriptor from the invoice.
invoice_detail_ids: When you create an invoice, you can supply a set of invoice details to represent separate items being purchased (which might be items in a shopping cart, say). Some PSPs let you restrict the purchase to just a subset of these items during capture. Set
invoice_detail_idswith an array that contains the
idvalues of the
InvoiceDetailobjects that you want to include. If you omit this option (or the PSP does not support it) then the full list from the
detailsfield of the invoice will be used.
Note that if you do authorize the payment before capture then you can simply call the
capture() function without any parameters.