skip to Main Content

I am using a payment service. This service want me to send a callBackUrl while starting payment process. And the service sends a post request to my callBackUrl after 3D security page. And I am checking some datas and return status. But, I need to redirect user directly to a custom url after my checkings. In short, how can I redirect to custom url inside a post method?

2

Answers


  1. Chosen as BEST ANSWER

    I solved my problem by sending response with 302 status code. You can see code below.

    [HttpPost]
    [Route("Callback")]
    [AllowAnonymous]
    public async Task<IActionResult> CallBackAsync(CancellationToken cancellationToken = default)
    {
        ...
        var response = new ObjectResult(null)
        {
            StatusCode = StatusCodes.Status302Found
        };
    
        Response.Headers["Location"] = "https://google.com";
        return response;
    }
    

  2. The answer would be specific to the payment gateway you are using. As @akseli has mentioned in comment, Payment Gateways has success and Cancel URL parameters.
    Following code is implementation of Stripe for processing payment and you can define options while creating session.

    //var domain = "https://localhost:7050/";
    var domain = Request.Scheme + "://" + Request.Host.Value + "/";
    
    var options = new Stripe.Checkout.SessionCreateOptions
    {
    
        SuccessUrl = domain+$"Customer/Cart/OrderConfirmation?id={ShoppingCartVM.OrderHeader.Id}",
        CancelUrl = domain+"Customer/Cart/Index",
        LineItems = new List<Stripe.Checkout.SessionLineItemOptions>(),                   
        Mode = "payment",
    };
    

    Let us know if this works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search