Here is my completed code for doing function for the form of going to the PayPal payment gateway by javascript without clicking on the "BUY NOW" button. Just my problem is here, this going to opening a new window to do that, I want this function to do it on the same window. Please guide me on how can we fix it? Any help will be appreciated.
window.onload = function() {
// u should put a name for your form
document.forms['my_form'].submit();
}
<form target="PayPal" id="my_form" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin:0;padding:0;">
<input type="hidden" name="business" value="test#yahoo.com">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="Membership">
<input type="hidden" name="item_number" value="1 Month">
<input type="hidden" name="amount" value="23">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="shipping" value="">
<input type="hidden" name="shipping2" value="">
<input type="hidden" name="handling" value="">
<input type="hidden" name="return" value="https://test.com/Successful_Payment.php">
<input type="hidden" name="cancel_return" value="">
<input type="hidden" name="undefined_quantity" value="0">
<input type="hidden" name="receiver_email" value="test#yahoo.com">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="0">
</form>
```
remove attribute target="Paypal" from the form
Related
I'm implementing MyPos payment gateway to accept debit card purchases. Their SDK is working in a weird manner. When I start the payment process, the SDK tries to echo HTML code with a form which will auto submit itself to their checkout page. This shouldn't be a problem if I submit my order page with the normal form submit, but I'm using ajax from my order page. I'm handling all other payment methods through ajax calls to my server, so I'd like to be consistent and use ajax here too.
So basically:
From my order page i press "pay with card" button.
Javascript will make ajax call to my server with order details, and will set up a purchase with MyPos sdk.
MyPos sdk echoes a HTML (but I'm capturing it with output buffer) which looks as following
<body onload="document.ipcForm.submit();">
<form id="ipcForm" name="ipcForm" action="https://www.mypos.eu/vmp/checkout-test" method="post"><input type="hidden" name="IPCmethod" value="IPCPurchase">
<input type="hidden" name="IPCVersion" value="1.4">
<input type="hidden" name="IPCLanguage" value="it">
<input type="hidden" name="SID" value="000000000000010">
<input type="hidden" name="WalletNumber" value="61938166610">
<input type="hidden" name="KeyIndex" value="1">
<input type="hidden" name="Source" value="SDK_PHP_1.2.1">
<input type="hidden" name="Currency" value="EUR">
<input type="hidden" name="Amount" value="5.26">
<input type="hidden" name="OrderID" value="46057">
<input type="hidden" name="URL_OK" value="http://website.test/api/private/mypos/success-redirect">
<input type="hidden" name="URL_Cancel" value="http://website.test/api/private/mypos/cancel-redirect">
<input type="hidden" name="URL_Notify" value="http://website.test/api/private/mypos/ipc-notify">
<input type="hidden" name="Note" value="">
<input type="hidden" name="customeremail" value="testuser24#gmail.com">
<input type="hidden" name="customerphone" value="3333333333">
<input type="hidden" name="customerfirstnames" value="Test">
<input type="hidden" name="customerfamilyname" value="User">
<input type="hidden" name="customercountry" value="ITA">
<input type="hidden" name="customercity" value="Arco">
<input type="hidden" name="customerzipcode" value="38062">
<input type="hidden" name="customeraddress" value="Via Fiori 12">
<input type="hidden" name="CartItems" value="1">
<input type="hidden" name="Article_1" value="CRONO-Ex 1kg">
<input type="hidden" name="Quantity_1" value="1">
<input type="hidden" name="Price_1" value="5.26">
<input type="hidden" name="Amount_1" value="5.26">
<input type="hidden" name="Currency_1" value="EUR">
<input type="hidden" name="CardTokenRequest" value="0">
<input type="hidden" name="PaymentParametersRequired" value="1">
<input type="hidden" name="PaymentMethod" value="3">
<input type="hidden" name="Signature" value="jq7OSRfkJmyt22rquIDoxK0QB1GBFug4eUcGYyyKg08bY+d036bgJ/R49iq9L8ZMB+Sz8VBDb/QsqLtRLqIbaP2e7j1sYRaoZZDeK+E3gRuDp/yJofVjPWjK8Q1ZbaokoM9ETaBZI+6oUjUEIES9nqfMYFgH0tk3axDcHkZ8HKg=">
</form>
</body>
Technically i should echo this to a page, and it will auto submit to their website. But instead I'm capturing this with output buffer, and send it back to javascript with JSON response.
Now how can I execute this HTML and make it do it's job? (eg. auto submitting itself to that post action URL)
You could read the Action URL from the response separately and then serialize the form and make a new Ajax call again.
var myForm = $(response).find("#ipcForm");
var url = myForm.attr('action'); //get submit url [replace url here if desired]
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes form input
success: function(data){
console.log(data);
}
});
Here is my code for going to the Paypal payment gateway for the item after a click on the "Buy Now" Button, But I want this function to be without even click on the "Buy Now" button, my meaning is when then webpage opened automatically go to the Paypal payment gateway without a click on "Buy Now" button. Is it possible? Any guidance will be very helpful.
<script type="text/javascript" src="https://test.com/java.js"></script>
<form target="PayPal" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin:0;padding:0;">
<input type="hidden" name="business" value="test#yahoo.com">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="Membership">
<input type="hidden" name="item_number" value="1 Month">
<input type="hidden" name="amount" value="23">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="shipping" value="">
<input type="hidden" name="shipping2" value="">
<input type="hidden" name="handling" value="">
<input type="hidden" name="return" value="https://test.com/Successful_Payment.php">
<input type="hidden" name="cancel_return" value="">
<input type="hidden" name="undefined_quantity" value="0">
<input type="hidden" name="receiver_email" value="test#yahoo.com">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="0">
<div id="PayPal6" style="position:absolute;left:445px;top:470px;width:134px;height:65px;">
<input type="image" name="submit" src="images/buynow.png" style="position:absolute;left:0px;top:0px;" alt="Make payments with PayPal, it's fast, free, and secure!">
</div>
</form>
U can achieve that by JavaScript:
window.onload = function(){
// u should put a name for your form
document.forms['my_form_name'].submit();
}
EDIT: You could also submit the PayPal submit button instead of the form:
window.onload = function(){
document.getElementById('paypalButton').submit();
}
I created a Paypal button for both one-time & recurring donations using some jQuery to switch out the input values so both buttons could be used.
The links function perfectly in both Chrome and Firefox, but when I test it in Safari the submit button just takes it to Paypal's main page, not the checkout. Does anyone have a clue why this might be happening?
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" id="paypal-form">
<input id="paypal-cmd" type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="TBX92MDZ4GV64">
<input type="hidden" name="lc" value="US">
<input id="paypal-item-name" type="hidden" name="item_name" value="Monthly Donation to Growing Home">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="src" value="1">
<input type="hidden" name="a3" value="75.00">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-SubscriptionsBF:btn_subscribe_SM.gif:NonHosted">
<div id="paypal-donate">
<h2>Donate</h2>
<p><input id="paypal-amount" type="text" name="a3" maxlength="10" placeholder="$75" value="$75"></p>
<div id="donate-once" class="button-off">Today</div>
<div id="donate-monthly" class="button-on">Monthly</div>
</div>
<div id="paypal-share">
<h2>Share</h2>
<input type="hidden" name="on0" value="Why do you give?">
<p><textarea id="paypal-reason" name="os0" placeholder="What's your reason for giving?"></textarea></p>
<input type="hidden" name="on1" value="Can we quote you?">
<input type="checkbox" name="os1" id="paypal-quote"><label for="paypal-quote"></label>
<span class="paypal-quote-label">Can we quote you?<span>
</div>
<div id="paypal-submit">
<h2>Submit</h2>
<p>Thank you so much for donating.</p>
<input type="image" src="donate_sm.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</div>
var onceButton = jQuery('#donate-once');
var monthlyButton = jQuery('#donate-monthly');
jQuery("input[type=checkbox]").change(function(){
cb = jQuery(this);
cb.val(cb.prop('checked'));
});
jQuery(onceButton).click(function(){
jQuery(onceButton).removeClass('button-off').addClass('button-on');
jQuery(monthlyButton).removeClass('button-on').addClass('button-off');
var a = jQuery("input[name=no_note]").val();
if (a === '1') jQuery("#paypal-cmd").val("_donations"), jQuery("#paypal-item-name").val("One-Time Donation to Growing Home"), jQuery("input[name=src]").val("0"), jQuery("input[name=no_note]").val("0"), jQuery("input[type='hidden'][name=a3]").remove(), jQuery("input[name=a3]").attr('name', 'amount'), jQuery("input[name=p3]").remove(), jQuery("input[name=t3]").remove();
});
jQuery(monthlyButton).click(function(){
jQuery(monthlyButton).removeClass('button-off').addClass('button-on');
jQuery(onceButton).removeClass('button-on').addClass('button-off');
var a = jQuery("input[name=no_note]").val();
if (a === '0') jQuery("#paypal-cmd").val("_xclick-subscriptions"), jQuery("#paypal-item-name").val("Monthly Donation to Growing Home"), jQuery("input[name=src]").val("1"), jQuery("input[name=no_note]").val("1"), jQuery("input[name=amount]").attr('name', 'a3'), jQuery('#paypal-form').append('<input type="hidden" name="a3" value="75.00"><input type="hidden" name="p3" value="1"><input type="hidden" name="t3" value="M">');
});
I am trying to dynamically update the amount and currency value fields in the following PayPal Buy Now form based on the radio button selection using the function below. I am unable to get it to pass the currency and amount values to the form.
The form:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" name="f" id="f">
<input name="audio-book" type="radio" class="sum" value="54.95" checked="checked" /> NZ$ 54.95
<input name="audio-book" type="radio" class="sum" value="43.95" /> AU$ 43.95
<input name="audio-book" type="radio" class="sum" value="45.00" /> US$ 45.00
<input name="audio-book" type="radio" class="sum" value="34.95" /> EU€ 34.95
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="xxxxxxxxxx">
<input type="hidden" name="lc" value="NZ">
<input type="hidden" name="item_name" value="xxxxxxxxx">
<input type="hidden" name="amount" id="amount" value="">
<input type="hidden" name="currency_code" id="currency_code" value="">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="xxxxx">
<input type="hidden" name="cancel_return" value="xxxxxx">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" class="alignleft wp-image-2884 size-full" src="../uploads/btn_buynow_pp_142x27.png" border="0" name="submit1" id="button" onclick="javascript:doSubmit();" alt="PayPal - The safer...">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
and the function:
<script>
function doSubmit(){
var $cost=0;
var $code="";
var $currency=['NZD', 'AUD', 'USD', 'EUR'];
var parent = document.getElementsByClassName('sum');
for (i = 0; i<parent.length; ++i){
if(parent[i].checked === true){
cost = Number(parent[i].value);
code = currency[i];}
}
document.getElementById('amount').value = cost;
document.getElementById('currency_code').value = code;
document.getElementById('f').submit();
return true;
}
</script>
It seems like everything is fine with the code . The only thing you need to change in the script is the below line :
Currently you have :
code = currency[i];
Change it to :
code = $currency[i];
I just tried it at my end and it worked .
Please have look at my sample fiddle:
http://jsfiddle.net/ghtgggb2/
Couple of things
move the script to the bottom (not sure where it is in your HTML)
move the function to the form for testing onsubmit="return doSubmit()"
I have a program that has 10 buttons or forms, onclick it redirects output to this form. and it opens another window that does an action.
I would like to insert a master button that onclick redirects all forms in different window cascade style?
Please help.
With jquery you can do this easily.
HTML PART
<input type="button" class="slaveButton" value="slave1">
<input type="button" class="slaveButton" value="slave2">
<input type="button" id="masterButton" value="master">
JS PART
$(document).ready(function() {
$("#masterButton").click(function(){
$(".slaveButton").trigger("click");
})
})
<form class="sp nm" method="POST" action="https://login.anaximan.com/login.php?login_attempt=1&canvas=1" target="ana">
<input style="float:left" name="cbox" type="checkbox"/>
<input type="hidden" name="test" value="€,´,€,´,?,?,?" />
<input type="hidden" name="next" value="http://app.anaximan.com/ana/index.php?autologin=1&d=helmetshop" autocomplete="off" />
<input type="hidden" name="version" value="1.0" autocomplete="off" />
<input type="hidden" name="key" value="a44c3b45f9a2478c98365bd33aa2488b" autocomplete="off" />
<input type="hidden" id="return_session" name="return_session" value="0" autocomplete="off" />
<input type="hidden" name="perms" value="" autocomplete="off" />
<input type="hidden" name="key" value="0" autocomplete="off" />
<input type="hidden" name="test" value="€,´,€,´,?,?,?" />
<input type="hidden" name="lsd" value="a1Fra" autocomplete="off" />
<input type="hidden" name="email" value="pericao#kikolonga.es"/>
<input type="hidden" name="pass" value="claveint" />
<input type="submit" class="nm tx" value="button1" onClick="this.form.cbox.checked=true; redirectOutput(this.form);" />
</form>