The capture toggle if enabled will capture the payment immediately, if you are wishing to have the capture occur in response to an order changing status then this would need to be done in an event handler.
In the most recent versions of Vendr there is a new IPaymentService (also available on the IVendrApi facade) which you could inject into an event handler and call it's CaptureOrderPayment method.
You're event handler would look something like this
public class CapturePaymentOnOrderStatusChangeHandler : NotificationEventHandlerBase<OrderStatusChangingNotification>
{
private IVendrApi _vendrApi;
public CapturePaymentOnOrderStatusChangeHandler(IVendrApi vendrApi)
{
_vendrApi = vendrApi;
}
public override void Handle(OrderStatusChangingNotification evt)
{
// Only proceed if the order is currently authorized
if (evt.Order.TransactionInfo.PaymentStatus == PaymentStatus.Authorized)
{
// Check the order status is changing to completed
var completedOrderStatus = _vendrApi.GetOrderStatus(evt.Order.StoreId, "completed");
if (evt.OrderStatusId.To.HasValue && evt.OrderStatusId.To.Value == completedOrderStatus.Id)
{
// Attempt to capture the payment
var paymentResult = _vendrApi.CaptureOrderPayment(evt.Order);
if (result.Success)
{
// Apply the changes to the order
// --
// NB: Because this is a `Changing` event handler
// the evt.Order is already writable so not need to
// convert it, and also no need to save it as this
// will occur automatically.
evt.Order.ApplyPaymentChanges(result);
}
}
}
}
}
Capture payment on completed status
Hi Matt.
Is it possible to request to capture a payment when the order change status to completed?
Or is the auto capture boolean on payment providers used for the completed status?
Hi Bo,
The
capture
toggle if enabled will capture the payment immediately, if you are wishing to have the capture occur in response to an order changing status then this would need to be done in an event handler.In the most recent versions of Vendr there is a new
IPaymentService
(also available on theIVendrApi
facade) which you could inject into an event handler and call it'sCaptureOrderPayment
method.You're event handler would look something like this
Which you'd need to hook up in a composer as documented here https://vendr.net/docs/core/1.8.0/key-concepts/events/#registering-a-notification-event-handler
Hope this helps
Matt
Thanks for a quick reply.
We are using Vendr version 1.8.6.
But I can not find the
CaptureOrderPayment
in theIVendrApi
. Do i miss a using?It's on the web version of the API facade so you'll need
using Vendr.Core.Web.Api
And now it works.
Thanks alot Matt :)
is working on a reply...