Sending POST with groovy to payment gateway - grails

I have already found similar topics but my code doesn't work.
I need to connect a webshop with payment gateway.
Data must be sent with POST. The problem is that when I want to open the payment form, I get only the info web page about the payment gateway.
Here are parts of my code:
cart.gsp
<jq:jquery>
$("#buy").click(function(e) {
$.ajax({
type:'POST',
url:'${createLink(action: 'fetchPaymentForm')}',
success:function(data,textStatus) {},
error:function(XMLHttpRequest,textStatus,errorThrown) {}
});
e.preventDefault()
})
</jq:jquery>
This part of code runs when I click on button with id "buy".
shoppingCartController.groovy
version
def fetchPaymentForm(){
def restClient = new RESTClient("https://test.payment.com/redirect/")
def resp = restClient.post(
body: [target: "_top", mode: "form",
store_id:"${storeID}", orderNumber: "${orderNumber}",
language: "${language}", currency: "${currency}",
amount: "${amountAll}", cart: "${cart}", Hash:"${hash}", require_complete: "true"],
requestContentType: URLENC
)
}
version
def fetchPaymentForm(){
render(template: "/layouts/paymentForm", model: [orderNumber: orderNumber, amount: amountAll, currency: currency, language: language, storeID: storeID, cart: cart, hash: hash])
}
_paymentForm.gsp
<form method="POST" action="https://test.payment.com/redirect/" name="form" id="form">
<input id="target" name="target" value="_top" type="hidden">
<input id="mode" name="mode" value="form" type="hidden">
<input id="store_id" name="store_id" value="${storeID}" type="hidden">
<input id="order_number" name="order_number" value="${orderNumber}" type="hidden">
<input id="language" name="language" value="${language}" type="hidden">
<input id="currency" name="currency" value="${currency}" type="hidden">
<input id="amount" name="amount" value="${amount}" type="hidden">
<input id="cart" name="cart" value="${cart}" type="hidden">
<input id="Hash" name="Hash" value="${hash}" type="hidden">
<input id="require_complete" name="require_complete" value="false" type="hidden">
</form>
I would be very thankfull if someone could give me an advice or hint what to try.
EDIT:
Here is an example for redirect for C# which is shown in pdf file for payment implementation.
<input id="target" ClientIDMode="Static" name="target" value="_top" hidden="true"/>
<input id="mode" ClientIDMode="Static" name="mode" value="<%=mode %>" hidden="true"/>
<input id="store_id" ClientIDMode="Static" name="store_id" value=" <%=store_id %>" hidden="true"/>
<input id="require_complete" ClientIDMode="Static" name="require_complete" value="<%=require_complete %>" hidden="true"/>
<input id="order_number" ClientIDMode="Static" name="order_number" value="<%=order_number %>" hidden="true"/>
<input id="amount" ClientIDMode="Static" name="amount" value="<%=amount %>" hidden="true"/>
<input id="hash" ClientIDMode="Static" name="hash" value="<%=hash %>" hidden="true"/>
<input id="currency" ClientIDMode="Static" name="currency" value=" <%=currency %>" hidden="true"/>
<input id="cart" ClientIDMode="Static" name="cart" value="<%=cart %>" hidden="true"/>
<input id="payment_number" ClientIDMode="Static" name="payment_number" value="<%=payment_number %>" hidden="true"/>
<input id="language" ClientIDMode="Static" name="language" value="<%=language %>" hidden="true"/>
<asp:button id="Button2" Text="testcps"
PostBackUrl="https://test.payment.com/redirect/" runat="Server" ClientIDMode="Static" OnClick="Button1_Click" />
Obviously I'm missing something but I don't know what.
Thanks for tips in advance.

Related

How do I set the 'Description' with PayPal's 'Buy Now' button?

I have this image where I can set the Amount but I cannot set the Description:
<form action="https://www.paypal.com/cgi-bin/webscr"
method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="moneytreelondon#gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="button_subtype" value="services">
<input id="total_price_and_postage_rate" type="hidden"
name="amount" value<%=r.total_price_and_postage_rate_no_commission%>">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn"
value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
<input type="image" src="" border="0" name="submit" alt="Refund">
<img alt="" [enter image description here][1]border="0"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif"
width="1" height="1">
</form>
How do I set the 'Descriptions'?
You may set the descriptions with this form tag
<input type="hidden" name="item_name" value="Your Desc">
Omitting the item_name and amount tags will let your customers make manual inputs in the PayPal checkout page

Google+ Sign-In hybrid with spring-security

to enabling OpenID authentication with Spring Security
We can add OpenID to the login page as follows:
`
<form action="j_spring_openid_security_check" method="post">
<input name="openid_identifier" size="50" maxlength="100"
type="hidden" value="https://www.google.com/accounts/o8/id"/>
<input type="submit" value="Sign in with Google"/>
</form>
for migrating to Google+ Sign-In how to integrated it with following HTML sign-in button?
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="CLIENT_ID"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schema.org/AddAction"
data-scope="https://www.googleapis.com/auth/plus.login">
</span>
</span>
this solution not work
<form action="<c:url value='j_spring_openid_security_check'/>"
method="post">
<input id="openid_identifier" name="openid_identifier" type="hidden"
value="https://accounts.google.com/o/oauth2/auth?" />
<input name="scope" value="https://www.googleapis.com/auth/plus.login"
type="hidden" />
<input name="response_type" value="code" type="hidden" />
<input name="client_id"
value="*****************.apps.googleusercontent.com"
type="hidden" />
<input name="client_url" value="**********" type="hidden" />
<input name="redirect_uri" value="postmessage" type="hidden" />
<input name="origin" value="**********" type="hidden" />
<input id="openid_submit" type="submit" value="Sign-In" />
</form>

Paypal response on localhost

I have the following hardcoded form in a view:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="mymail#mymail.com" />
<input type="hidden" name="item_name" value="Attack Announcer" />
<input type="hidden" name="item_number" value="2ca168a959bb48e28a2ddb4b4640c568" />
<input type="hidden" name="amount" value="0.01" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="return" value="?????" />
<input type="hidden" name="cancel_return" value="?????" />
<input type="hidden" name="notify_url" value="??????" />
<input type="hidden" name="no_note" value="1" />
<input type="image" name="submit"
src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif"
alt="PayPal — The safer, easier way to pay online." />
<img src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif"
width="1" height="1" alt="" />
</form>
How can I take the response message after the transaction is completed (on localhost)?
For example if I have some action like:
[HttpPost]
public ActionResult PaypalConfirmation(???????????)
{
// ........................
return View();
}
you have to tell it the success url and fail url, that on success transaction go the this url and on failed transaction go to this url, you have to pass the url via hidden fields of return and cancel_return:
URL where paypal will redirect if transaction successfull:
<input type="hidden" name="return" value="#Url.Action("ActionName","ControllerName")" />
URL where paypal will redirect if transaction not Successful:
<input type="hidden" name="cancel_return" value="#Url.Action("ActionName","ControllerName")" />
Also refer this Question (Asp.net Paypal Return Url Requirement)

Paypal checkout page not displaying shipping/postage cost

I have gone through many questions similar to this but I could not resolve the issue. This is not the first time I am using paypal, I have successfully used the code below in other websites as well.
I have also checked the option for overriding the profile postage settings.
I am using the following code:
<form id="f1" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
#* <input type="hidden" name="shipping" value="0.00">*#
<input type="hidden" name="handling_cart" value="#shipamt" />
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="businessEmail#paypal.com" />
<input type="hidden" name="currency_code" value="GBP" />
<input name="custom" type="hidden" id="custom" value="#cartId" />
#foreach(var cartdetail in Model.cartDetail)// (int i = 0; i < Model.order.cart.cartDetail.Count;i++ )
{
<input type="hidden" name="item_number_#i" value="#i" />
<input type="hidden" name="item_name_#i" value="#cartdetail.product.Title" />
<input type="hidden" name="quantity_#i" value="#cartdetail.Quantity" />
<input type="hidden" name="amount_#i" value="#cartdetail.product.getCurrentPrice()">
i++;
}
<input type="hidden" name="return" value="http://parduh.com" />
<input type="hidden" name="cancel_return" value="http://cancelurl.com" />
<input type="hidden" name ="notify_url" value="http://notifyurl.com" />
#* <input type="hidden" name="no_shipping" value="1" />*#
<input type="hidden" name="image_url" value="http://parduh.com/images/logo.png">
</form>
These are the values from chrome's developer tool, all the values are being posted to paypal
handling_cart:16.6167
cmd:_cart
upload:1
business:mybusinessemail#hotmail.com
currency_code:GBP
custom:13
item_number_1:1
item_name_1:Dress
quantity_1:1
amount_1:68.00
Thanks for the help.
The issue is that you are passing the value for handling_cart with more than 2 decimal places. Try the same request, but making sure that you round off so that handling_cart = 16.62.

Paypal automatic redirect to Store Vendor

I made a e-commerce which handles payments by Paypal, the flow works good although there is a boring thing, when the user finish to pay, to go back to the StoreWebSite has to click to the button which was provided by PayPal page.
there is anyway to make that operation automatic?
there is any flag I can set to force paypal redirect to my StoreWebSite when the user finish to pay?
basically I do that
Basically I do the following:
<html ng-app>
<body data-ng-controller="testController">
<form id="Checkpay" name="Checkpay" style="margin: 0" method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" target="_blank" class="ng-pristine ng-valid">
<input type="hidden" id="return_url" name="return_url" value="">
<input type="hidden" name="quantita" id="qtytext" value="0">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="Le Spose di Nika">
<input type="hidden" name="business" value="TEST#TEST.it">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="cancel_return" id="cancel_return" value="">
<input type="hidden" name="return" id="return" value="">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" id="H_amount" name="amount" value="719.80">
<input type="hidden" id="H_first_name" name="first_name">
<input type="hidden" id="H_address1" name="address1">
<input type="hidden" id="H_city" name="city">
<input type="hidden" id="H_state" name="state">
<input type="hidden" id="H_zip" name="zip">
<input type="hidden" id="H_email" name="email">
<input type="hidden" id="Country" name="country">
<input type="hidden" id="charset" name="charset" value="utf8">
<input type="hidden" id="rm" name="rm" value="2">
<input type="hidden" id="notify_url" name="notify_url" value="">
<input id="Submit1" type="submit" value="submit_post" />
</form>
<input id="Submit2" type="button" data-ng-click='pay()' value="js_post" />
</body>
</html>
<script src="http://localhost:27433/Scripts/jquery-1.7.1.min.js"></script>
<script src="http://localhost:27433/Scripts/jquery-ui-1.8.20.min.js"></script>
<script src="http://localhost:27433/Scripts/angular.js"></script>
<script>
function test() {
}
function testController($scope, $http) {
var URL = "http://backend.MYSITE.com/";
$scope.payTest = function () {
var PAYPAL_URL_RELEASE = "https://www.paypal.com/cgi-bin/webscr";
$('#return_url').val(URL);
$('#cancel_return').val(URL + '/ErrorPay');
$('#return').val(URL + '/Success');
$('#notify_url').val(URL + '/PayPalReceiverIPN.ashx?idOrder=');
document.forms["Checkpay"].action = PAYPAL_URL_RELEASE;
document.forms["Checkpay"].submit();
}
}
</script>
return_url
The URL to which the sender's browser is redirected after approving a payment on paypal.com.
You can find it here

Resources