I need to connect to the payment gateway from my JSF application. I need to achieve the following:
(A) Need to send a POST request with required parameters. The Java controller code is as below is being called from the xhtml page
A payment object is already created when user hits "Proceed for Payment" button.
public void paymentGateway() {
ExternalContext externalContext=FacesContext.getCurrentInstance().getExternalContext();
try {
externalContext.redirect("https://test.payu.in/_payment?key="
+ this.key
+ "&txnid=1232132&amount="
+ payment.getTotalAmount()
+ "&productinfo="
+ payment.getItem().getName());
} catch (IOException e) {
e.printStackTrace();
}
}
<div class="form-group">
<h:commandButton value="Proceed for Payment"
action="#{myController.paymentGateway}"
styleClass="btn btn-submit" />
</div>
The above is INCORRECT, I need to send parameters to EXTERNAL SERVER but the above will show all parameters on the browser URL bar.
(B) Also when the Payment Gateway server responds (successful payment or error), I need capture that in the "response" and show it on the XHTML page.
I know for this, Servlet would be ideal to redirect it to Payment Gateway with requirement parameters & store the response in response object, but how to accomplish this part, I do not know.
Requesting any help, please.
Thank you!