In
GrandNode we can distinguish two standard types of payment :
Redirection
– customer after place order is redirected to payment site
Standard – during checkout display to customer component with a payment form, usually credit cart form
public partial interface IPaymentProvider : IProvider
{
Task InitPaymentTransaction();
Task ProcessPayment(PaymentTransaction paymentTransaction);
Task PostProcessPayment(PaymentTransaction paymentTransaction);
Task PostRedirectPayment(PaymentTransaction paymentTransaction);
Task HidePaymentMethod(IList cart);
Task GetAdditionalHandlingFee(IList cart);
Task Capture(PaymentTransaction paymentTransaction);
Task Refund(RefundPaymentRequest refundPaymentRequest);
Task Void(PaymentTransaction paymentTransaction);
Task CancelPayment(PaymentTransaction paymentTransaction);
Task CanRePostRedirectPayment(PaymentTransaction paymentTransaction);
Task> ValidatePaymentForm(IFormCollection form);
Task SavePaymentInfo(IFormCollection form);
void GetPublicViewComponent(out string viewComponentName);
PaymentMethodType PaymentMethodType { get; }
Task SkipPaymentInfo();
Task Description();
string LogoURL { get; }
Task SupportCapture();
Task SupportPartiallyRefund();
Task SupportRefund();
Task SupportVoid();
}
InitPaymentTransaction
– we can add initial value to our payment transaction
ProcessPayment
– method for processing a payment
transaction, for example in credit card payment you should authorize your payment in this
method
PostProcessPayment
– invoke after ProcessPayment
PostRedirectPayment
– use for redirection payment method, you can inject IHttpContextAccessor to
your class and make the redirect.
HidePaymentMethod
- Returns a value indicating whether the payment method should be hidden during
checkout. For example, you can return true if the currency is not supported.
GetAdditionalHandlingFee
– Calculate additional handling fee
Capture –
capture payment ( can be invoked from admin panel)
Refund - refund
payment ( can be invoked from admin panel)
Void - void
payment
( can be invoked from admin panel)
CancelPayment
-cancel payment, you can in this method for example send cancel request to your
payment provider
CanRePostRedirectPayment
– indicate that PostRedirectPayment will be invoke. Return true if you use
redirect payment.
GetPublicViewComponent
– view component name that will be rendered in payment info (during checkout).
This can be the simple view that displays additional info about payment or can be a form that takes data (for example credit card form)
SkipPaymentInfo
– return true if you want to omit payment info (associated with GetPublicViewComponent)
ValidatePaymentForm
– if you use the view component you can validate passed data by customers in this
method
SavePaymentInfo
– you can save data from your form. PaymentTransaction class has the field
CustomValues that allow you to pass additional data.
Description
– return description string. Recommended to use with resources string
LogoUrl –
path to your logo image. It doesn't have to be the same as the plugin's logo
PaymentMethodType – Redirect/Standard/Other
To sum up
we will discuss a sample flow of the payment method with a credit card :
HidePaymentMethod
(after enter to checkout) ->
Description
->
GetAdditionalHandlingFee
->
InitPaymentTransaction
->
SkipPaymentInfo
(in our case return false, because we want to display form) ->
GetPublicViewComponent
(display html form with inputs for credit cart data)->
ValidatePaymentForm
(validate card number, month, year)->
SavePaymentInfo
(save credit cart data to Session or PaymentTransaction) ->
ProcessPayment (in this method send request to payment provider and make payment as Authorized, this is our last step)
If you
want to know more check out our free plugin source code : Payments.BrainTree