PaymentCaptureExtension reference
This article provides reference material about PaymentCaptureExtension
class.
All payment capture extensions have to be inherited from this class which, in turn,
inherits from the core Sana Commerce Cloud Extension
class.
Properties
PaymentModuleId
Gets or sets identifier of payment module.
Payment module identifier connects payment capture extension with payment extension
itself. Therefore this identifier has to be the same as in PaymentModuleIdAttribute
of payment extension.
Payment capture extension processes transactions of payment methods that use payment provider with the corresponding payment module identifier. Payment capture extension will be skipped if no payment extension with corresponding identifier exists.
public class CustomPayPalCaptureExtension : PaymentCaptureExtension
{
public override string PaymentModuleId => PaymentExtension.GetPaymentModuleId(typeof(CustomPayPalPaymentExtension));
}
Methods
AdjustAuthorisation
Adjusts authorisation.
In this method you should implement logic of adjusting authorisation from the payment service provider.
public override void AdjustAuthorisation(AuthorisationAdjustmentContext context)
{
// Assuming that PspWebService is your instance of PSP gateway service
var result = PspWebService.AdjustAuthorisation(context);
context.State.PaymentStatus = result.Completed ? PaymentStatus.InProgress : PaymentStatus.Cancelled;
}
Capture
Captures payment.
In this method you should implement logic of capturing payment from the payment service provider.
public override void Capture(PaymentCaptureContext context)
{
// Assuming that PspWebService is your instance of PSP gateway service
var result = PspWebService.Capture(context);
context.State.PaymentStatus = result.Completed ? PaymentStatus.InProgress : PaymentStatus.Cancelled;
context.CaptureReferenceId = result.CaptureReferenceId;
}
GetCaptureStrategy
Returns capture strategy.
This method is called for each payment method that uses payment provider specified in PaymentModuleId property.
This method gets parameter of PaymentCaptureStrategyContext
type, so that you can use this data to decide
which strategy is needed for payment method.
There are next existing capture strategies:
Invoice
- capturing will be triggered on invoice creation.Shipping
- capturing will be triggered when the order fully shipped.NotNeeded
- capturing not needed.
public override CaptureStrategy GetCaptureStrategy(PaymentCaptureStrategyContext context)
{
return (context.MethodSettings as CustomPayPalSettings).CaptureStrategy;
}
IsAuthorisationAdjustmentRequired
Returns boolean value indicating whether authorisation adjustment is required.
This method gets parameter of AuthorisationAdjustmentMethodContext
type, so that you can use this data to decide
whether authorisation adjustment is needed for payment method.
public override bool IsAuthorisationAdjustmentRequired(AuthorisationAdjustmentMethodContext context)
{
return (context.MethodSettings as CustomPayPalSettings).IsDelayedAuthorisationAdjustmentEnabled;
}