Open Closed

Add more custom payment gateways? #885


User avatar
0
rcalv002 created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v4.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Seperated (Angular): Tiered
  • Exception message and stack trace:
  • Steps to reproduce the issue:

The documentation for the commercial payment module says the below. does this mean we can implement other payment systems, if so, wheres the documentation for what we need to do? I dont have the higher level license to download existing pro module code, so documentation on these things is crucial..

Configure<PaymentOptions>(options => { options.Gateways.Add( new PaymentGatewayConfiguration( "MyPaymentGatewayName", new FixedLocalizableString("MyPaymentGatewayName"), typeof(MyPaymentGateway) ) ); });


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Yes, you can add more payment options. First you need to add your new payment gateway to the Gateways list;

    Configure<PaymentOptions>(options =>
    {
        options.Gateways.Add(
            new PaymentGatewayConfiguration(
                PayuConsts.GatewayName,
                new FixedLocalizableString("Payu"),
                typeof(CustomPaymentGateway)
            )
        );
    });
    

    Then, create an implementaion of IPaymentGateway (CustomPaymentGateway in this example).

    You also need to create two Razor pages for your custom payment option. PrePayment.cshtml and PostPayment.cshtml. When user selects the payment option you have added, payment module first redirects user to PrePayment.cshtml, so you can get extra information if you need to or just redirect user to payment gateways website without any extra operation.

    When user completes the payment on the payment gateway (or payment fails for some gateways), user will be redirected to PostPayment.cshtml, so you can validate the payment with external gateway and if the payment is really succeeded, you can redirect user to requested callback URL.

    For example, this is one of our PostPayment.cshtml.cs code;

    public virtual async Task<IActionResult> OnGetAsync()
    {
        var paymentRequestId = Guid.Parse(Request.Query["paymentRequestId"]);
    
        Logger.LogInformation("PayU return url: " + Request.GetEncodedUrl());
    
        await PaymentRequestAppService.CompleteAsync(
            new CompletePaymentRequestDto
            {
                GateWay = PayuConsts.GatewayName,
                Id = paymentRequestId,
                Properties = new Dictionary<string, string>
                {
                    { "ctrl", Request.Query["ctrl"]},
                    { "payrefno", Request.Query["payrefno"]},
                    { "url", GetCurrentEncodedUrl()}
                }
            });
    
        if (!_paymentWebOptions.Value.CallbackUrl.IsNullOrWhiteSpace())
        {
            var callbackUrl = _paymentWebOptions.Value.CallbackUrl + "?paymentRequestId=" + paymentRequestId;
            var paymentRequest = await PaymentRequestAppService.GetAsync(paymentRequestId);
            var extraPaymentParameters = _purchaseParameterListGenerator.GetExtraParameterConfiguration(paymentRequest);
    
            if (!extraPaymentParameters.AdditionalCallbackParameters.IsNullOrEmpty())
            {
                callbackUrl += "&" + extraPaymentParameters.AdditionalCallbackParameters;
            }
    
            Response.Redirect(callbackUrl);
        }
    
        return Page();
    }
    

    Please let me know if you face any problems.

  • User Avatar
    0
    rcalv002 created

    Hi,

    Thanks for the feedback I'll take a look into it. I see the example is to user razor pages even though my project is implementing apis on the net core and the frontend on angular. Does that mean that the real base of abpio is to use the mvc deployment since some modules seem to rely on it? for example docs module doesnt seem to be available for angular

    Should I just switch my entire project over to netcore with mvc to have the largest coverage?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @rcalv002

    Yes, for Payment Module, there is only MVC UI support. You can use its APIs but this will be harder. Or you can create a new MVC app just for payment processing and redirect users to this app when they want to make a payment from your Angular app. You don't need to change your entire app to MVC.

  • User Avatar
    0
    sgal created

    I ran into some problems

    https://support.abp.io/QA/Questions/1493/How-can-I-run-the-demo-in-pro-module

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35