CompleteShipment in DefaultShipmentProcessor uses this method that use the extension method ProcessPayments
private void CompleteShipment(IOrderGroup order, IShipment shipment)
{
this.CapturePayment(order, shipment);
if (order.Forms.Sum<IOrderForm>((Func<IOrderForm, Decimal>) (form => form.Payments.Sum<IPayment>((Func<IPayment, Decimal>) (p => p.Amount)))) < order.GetTotal(this._orderGroupCalculator).Amount)
throw new Exception("Payment total is less than order total.");
IEnumerable<PaymentProcessingResult> source = order.ProcessPayments(this._paymentProcessor, this._orderGroupCalculator).Where<PaymentProcessingResult>((Func<PaymentProcessingResult, bool>) (r => !r.IsSuccessful));
if (source.Any<PaymentProcessingResult>())
{
string message = string.Join(Environment.NewLine, source.Select<PaymentProcessingResult, string>((Func<PaymentProcessingResult, string>) (e => e.Message)));
throw new PaymentException(PaymentException.ErrorType.ProviderError, string.Empty, message);
}
}
The extension method ProcessPayments runs paymentProcessor.ProcessPayment(ordergroup, payment, (IShipment) null)
public static IEnumerable<PaymentProcessingResult> ProcessPayments(
this IOrderGroup orderGroup,
IPaymentProcessor paymentProcessor,
IOrderGroupCalculator orderGroupCalculator)
{
if (orderGroup.GetTotal(orderGroupCalculator).Amount == Decimal.Zero || orderGroup is IPaymentPlan)
return Enumerable.Empty<PaymentProcessingResult>();
List<PaymentProcessingResult> processingResultList = new List<PaymentProcessingResult>();
foreach (IOrderForm form in (IEnumerable<IOrderForm>) orderGroup.Forms)
{
processingResultList.AddRange(form.Payments.Select<IPayment, PaymentProcessingResult>((Func<IPayment, PaymentProcessingResult>) (payment => paymentProcessor.ProcessPayment(orderGroup, payment, (IShipment) null))));
form.UpdatePaymentTotals();
}
return (IEnumerable<PaymentProcessingResult>) processingResultList;
}
Since shipment will be null here, the switch statement will NEVER call ProcessPayment with shipment information if PaymentGateway implements ISplitPaymentPlugin?????
public virtual PaymentProcessingResult ProcessPayment(
IOrderGroup orderGroup,
IPayment payment,
IShipment shipment)
{
Validator.ThrowIfNull(nameof (payment), (object) payment);
if (PaymentStatusManager.GetPaymentStatus(payment) != PaymentStatus.Pending)
return PaymentProcessingResult.CreateSuccessfulResult(string.Empty);
object paymentGatewayProvider = this.CreatePaymentGatewayProvider(payment);
string empty = string.Empty;
PaymentProcessingResult processingResult;
try
{
switch (paymentGatewayProvider)
{
case ISplitPaymentPlugin splitPaymentPlugin when shipment != null:
processingResult = splitPaymentPlugin.ProcessPayment(orderGroup, payment, shipment);
break;
case IPaymentPlugin paymentPlugin:
processingResult = paymentPlugin.ProcessPayment(orderGroup, payment);
break;
case ISplitPaymentGateway splitPaymentGateway when shipment != null && (payment is Payment payment1 && shipment is Shipment shipment1):
processingResult = splitPaymentGateway.ProcessPayment(payment1, shipment1, ref empty) ? PaymentProcessingResult.CreateSuccessfulResult(empty) : PaymentProcessingResult.CreateUnsuccessfulResult(empty);
break;
default:
processingResult = ((IPaymentGateway) paymentGatewayProvider).ProcessPayment(payment as Payment, ref empty) ? PaymentProcessingResult.CreateSuccessfulResult(empty) : PaymentProcessingResult.CreateUnsuccessfulResult(empty);
break;
}
}