Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

TestPaymentMethod.cs

using Microsoft.AspNetCore.Http;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Payments;
using Nop.Services.Payments;
using Nop.Services.Plugins;

namespace Nop.Tests.Nop.Services.Tests.Payments;

public class TestPaymentMethod : BasePlugin, IPaymentMethod
{
    #region Methods

    /// 
    /// Refunds a payment
    /// 
    /// Request
    /// Result
    public Task RefundAsync(RefundPaymentRequest refundPaymentRequest)
    {
        var result = new RefundPaymentResult();
        result.AddError("Refund method not supported");

        return Task.FromResult(result);
    }

    /// 
    /// Voids a payment
    /// 
    /// Request
    /// Result
    public Task VoidAsync(VoidPaymentRequest voidPaymentRequest)
    {
        var result = new VoidPaymentResult();
        result.AddError("Void method not supported");

        return Task.FromResult(result);
    }

    /// 
    /// Process recurring payment
    /// 
    /// Payment info required for an order processing
    /// Process payment result
    public Task ProcessRecurringPaymentAsync(ProcessPaymentRequest processPaymentRequest)
    {
        var result = new ProcessPaymentResult();
        result.AddError("Recurring method not supported");

        return Task.FromResult(result);
    }

    /// 
    /// Cancels a recurring payment
    /// 
    /// Request
    /// Result
    public Task CancelRecurringPaymentAsync(CancelRecurringPaymentRequest cancelPaymentRequest)
    {
        var result = new CancelRecurringPaymentResult();
        result.AddError("Cancelling recurring orders not supported");

        return Task.FromResult(result);
    }

    /// 
    /// Gets a value indicating whether customers can complete a payment after order is placed but not completed (for redirection payment methods)
    /// 
    /// Order
    /// Result
    public Task CanRePostProcessPaymentAsync(Order order)
    {
        ArgumentNullException.ThrowIfNull(order);

        //it's not a redirection payment method. So we always return false
        return Task.FromResult(false);
    }

    /// 
    /// Validate payment form
    /// 
    /// The parsed form values
    /// List of validating errors
    public Task> ValidatePaymentFormAsync(IFormCollection form)
    {
        return Task.FromResult>(new List());
    }

    /// 
    /// Get payment information
    /// 
    /// The parsed form values
    /// Payment info holder
    public Task GetPaymentInfoAsync(IFormCollection form)
    {
        return Task.FromResult(new ProcessPaymentRequest());
    }

    /// 
    /// Process a payment
    /// 
    /// Payment info required for an order processing
    /// Process payment result
    public Task ProcessPaymentAsync(ProcessPaymentRequest processPaymentRequest)
    {
        var result = new ProcessPaymentResult
        {
            NewPaymentStatus = PaymentStatus.Paid
        };

        return Task.FromResult(result);
    }

    /// 
    /// Post process payment (used by payment gateways that require redirecting to a third-party URL)
    /// 
    /// Payment info required for an order processing
    public Task PostProcessPaymentAsync(PostProcessPaymentRequest postProcessPaymentRequest)
    {
        return Task.CompletedTask;
    }

    /// 
    /// Returns a value indicating whether payment method should be hidden during checkout
    /// 
    /// Shopping cart
    /// true - hide; false - display.
    public Task HidePaymentMethodAsync(IList cart)
    {
        return Task.FromResult(false);
    }

    /// 
    /// Gets additional handling fee
    /// 
    /// Shopping cart
    /// Additional handling fee
    public Task GetAdditionalHandlingFeeAsync(IList cart)
    {
        return Task.FromResult(AdditionalHandlingFee);
    }

    /// 
    /// Captures payment
    /// 
    /// Capture payment request
    /// Capture payment result
    public Task CaptureAsync(CapturePaymentRequest capturePaymentRequest)
    {
        var result = new CapturePaymentResult();
        result.AddError("Capture method not supported");

        return Task.FromResult(result);
    }

    /// 
    /// Gets a type of a view component for displaying plugin in public store ("payment info" checkout step)
    /// 
    /// View component type
    public Type GetPublicViewComponent()
    {
        return null;
    }

    public Task GetPaymentMethodDescriptionAsync()
    {
        return Task.FromResult(PaymentMethodDescription);
    }

    #endregion

    #region Properties

    /// 
    /// Gets a value indicating whether capture is supported
    /// 
    public bool SupportCapture => TestSupportCapture;

    /// 
    /// Gets a value indicating whether partial refund is supported
    /// 
    public bool SupportPartiallyRefund => TestSupportPartiallyRefund;

    /// 
    /// Gets a value indicating whether refund is supported
    /// 
    public bool SupportRefund => TestSupportRefund;

    /// 
    /// Gets a value indicating whether void is supported
    /// 
    public bool SupportVoid => TestSupportVoid;

    /// 
    /// Gets a recurring payment type of payment method
    /// 
    /// A recurring payment type of payment method
    public RecurringPaymentType RecurringPaymentType => RecurringPaymentType.NotSupported;

    /// 
    /// Gets a payment method type
    /// 
    /// A payment method type
    public PaymentMethodType PaymentMethodType => PaymentMethodType.Standard;

    /// 
    /// Gets a value indicating whether we should display a payment information page for this plugin
    /// 
    public bool SkipPaymentInfo => false;

    /// 
    /// Gets a payment method description that will be displayed on checkout pages in the public store
    /// 
    /// 
    /// return description of this payment method to be display on "payment method" checkout step. good practice is to make it localizable
    /// for example, for a redirection payment method, description may be like this: "You will be redirected to PayPal site to complete the payment"
    /// 
    public string PaymentMethodDescription => string.Empty;

    #endregion

    #region Test data

    public static bool TestSupportCapture { get; set; } = false;

    public static bool TestSupportRefund { get; set; } = false;

    public static bool TestSupportPartiallyRefund { get; set; } = false;

    public static bool TestSupportVoid { get; set; } = false;

    public static decimal AdditionalHandlingFee { get; set; } = decimal.Zero;

    #endregion


}