Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get response on url specified in UPI Hyperlink payment

Tags:

java

spring

I'm trying to pay through a UPI hyperlink like

upi://pay?pa=abc@upi&pn=payeeName&tr=1234&tn=Pay%20to%20payeeName&am=1&mam=1&cu=INR&url=https://test.com/payment/orderId=123456
  • I am sending above link through sms
  • When I click on link it shows UPI application list as option
  • I have selected BHIM app (also tried other applications)
  • Then completed payment, till now it works fine.

After the UPI payment is done, the Spring controller which handles the "callback" request to https://test.com/payment/orderId=12345, is not getting called.

So how to get response of UPI Hyperlink payment in Java correctly?

Edit:

This is the controller method. I have also tried @GetMapping instead of @PostMapping.

@PostMapping("/payment")
public ModelAndView credPayment(HttpServletRequest request) {

    String key = request.getParameter("orderId");
    String txnId = request.getParameter("txnId");
    String responseCode = request.getParameter("responseCode");
    String approvalRefNo = request.getParameter("ApprovalRefNo");
    String status = request.getParameter("Status");
    String txnRef = request.getParameter("txnRef");
    System.out.println("Parameter Names");
    while (request.getParameterNames().hasMoreElements()) {
        System.out.println(request.getParameterNames().nextElement());
    }

    System.out.println("Header Names");
    while (request.getHeaderNames().hasMoreElements()) {
        System.out.println(request.getHeaderNames().nextElement());
    }

    System.out.println("txnId : "+txnId);
    System.out.println("responseCode : "+responseCode);
    System.out.println("ApprovalRefNo : "+approvalRefNo);
    System.out.println("Status : "+status);
    System.out.println("txnRef : "+txnRef);

    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("redirect:/");
    return modelAndView;
}
like image 688
Nilesh Patel Avatar asked Nov 09 '19 11:11

Nilesh Patel


1 Answers

If I understood it correctly, your redirect URL is

https://test.com/payment/orderId=123456

And when this is called, you need to get order id value in your controller.

Then try changing your method to something like this:

@GetMapping(value = "/payment/{order}")
public ModelAndView credPayment(@PathVariable("order") String order, HttpServletRequest request) {
    System.out.println(order); // prints orderId=123456
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("redirect:/");
    return modelAndView;
}

Issue:

You have configured your URL mapping as /payment only, so anything after that will get excluded from this mapping, eg: /payment/sdfdsfs

like image 178
MyTwoCents Avatar answered Oct 05 '22 23:10

MyTwoCents