I've been given the task of setting up a payment processor for my boss who uses Moneris in Canada. I need to use their form to post the price but unsure what the best method is and have little to no back-end WordPress experience.
I need to assign the woocommerce cart total to the input "charge_total" value on the form submit.
Sample Form:
<form action="https://esqa.moneris.com/HPPDP/index.php" method="POST"><input name="ps_store_id" type="HIDDEN" value="XXXX" />
<input name="hpp_key" type="HIDDEN" value="XXXX" />
<input name="charge_total" type="HIDDEN" value="1" />
<input name="SUBMIT" type="SUBMIT" value="Click to proceed to Secure Page" />
</form>
You need to modify your template where the form is generated.
your sample form would become
<?php
global $woocommerce;
$cartTotal=$woocommerce->cart->get_cart_total()
?>
<form action="https://esqa.moneris.com/HPPDP/index.php" method="POST">
<input name="ps_store_id" type="HIDDEN" value="XXXX" />
<input name="hpp_key" type="HIDDEN" value="XXXX" />
<input name="charge_total" type="HIDDEN" value="<?php echo $cartTotal?>" />
<input name="SUBMIT" type="SUBMIT" value="Click to proceed to Secure Page" />
</form>
wp-content/plugins/woocommerce/templates/checkout/form-checkout.php is your main checkout file. i do not know where in the checkout process you wish to allow the user to leave the site, but i assume it would be form-pay.php
Good day, hope it helps you out
edit:
after conversation in comments, i would point you towards using the hooks. i will be using the after checkout hook to inject some html in there but if you let me know where you need the code ill re edit the hook for the proper position
put this in the functions.php file in your enabled theme
function add_custom_html() {
global $woocommerce;
$cartTotal=$woocommerce->cart->get_cart_total()
$my_custom_form = '<form action="https://esqa.moneris.com/HPPDP/index.php" method="POST">
<input name="ps_store_id" type="HIDDEN" value="XXXX" />
<input name="hpp_key" type="HIDDEN" value="XXXX" />
<input name="charge_total" type="HIDDEN" value="'&$cartTotal&'"/>
<input name="SUBMIT" type="SUBMIT" value="Click to proceed to Secure Page" />
</form>';
echo $my_custom_form;
}
add_action( 'woocommerce_after_checkout_form', 'add_custom_html');
Related
I am not getting the way to hide the values that are passing through url in php. Clicking over a link , page redirects plus parameters are also shown on url .For eg:-
/localhost/oops/edit.php?id='1'
but I want to hide the data after ? while redirecting.
Your only option is to use a form and POST if the page your are logging into is controlled by a 3rd party. Try to use hidden input type while login. Maybe that'll work for you. For example:
<form action="http://mywebsite.com/login.aspx" method="post">
<input type="hidden" name="check" value="uid" />
<input type="hidden" name="user" value="adam" />
<input type="hidden" name="pass" value="pass1234" />
<input type="hidden" name="profile" value="profile" />
<input type="hidden" name="defaultdatabaseb" value="database" />
<input type="submit" value="submit" />
</form>
Currently, I am working on a site that uses PayPal to Checkout. I would like to enable stripe, as well, so there can be a "checkout with stripe" button at the bottom of the form.
<form method="POST" id="form1" >
<select id="udidSelect" onchange="udidPrice(this)">
<option value="invalid" disabled="disabled">Choose Package</option>
<option value="udid">UDID Registration</option>
<option value="profile">UDID Registration & Free Unlimited Apps (Provisioning Profile)</option>
</select><br />
<br />
<input type="text" placeholder="Name" /><br />
<br />
<input type="email" placeholder="Email" /><br />
<br />
<input type="text" placeholder="UDID (40 Characters Long)" name="os0" /> <br />
<input type="hidden" name="on0" value="UDID">
<br />
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" id="udidbuttonID" value="9PSTCESRS3FSG">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" value="PayPal" onclick="submitForm('https://www.paypal.com/cgi-bin/webscr')" style="float:right;">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Now I would like to have a PayPal Button at the bottom of the form and a Stripe button at the bottom of the form. And if the user clicked the stripe button, it would take them to the next page and PASS ALONG the information entered in this page. I am not sure how to do this, and I am also not sure how to have different post options for the form. (Sorry I am kind of new to this.)
On the stripe checkout page, also, how would I request that information that was passed along, from the previous form. Would it just be something like this?
<input type="hidden" name="somedata" value="<?php echo $_POST['somedata']; ?>" />
<input type="hidden" name="otherdata" value="<?php echo $_POST['otherdata']; ?>" />
If I'm reading your question correctly, you want the form to go to different pages depending on whether the user clicked on Stripe or Paypal.
You can use JavaScript/jQuery to change the action attribute of the form:
<!--HTML-->
<button onClick="setFormAction('stripe')">Stripe</button>
<button onClick="setFormAction('paypal')">Paypal</button>
//Javascript
function setFormAction(which) {
if (which == 'stripe') {
//Change 'stripe.php' to the proper URL
document.getElementById('form1').action = 'stripe.php';
} else {
document.getElementById('form1').action = 'paypal.php'; //Change this also
}
//Finally, submit the form
document.getElementById('form1').submit();
}
Or, more understandably, the jQuery solution:
<!--HTML-->
<button id="stripe">Stripe</button>
<button id="paypal">Paypal</button>
//Javascript
$('button#stripe').click(function() {
$('form#form1')
.attr('action', 'stripe.php') //Change to proper stripe URL
.submit();
});
$('button#paypal').click(function() {
$('form#form1')
.attr('action', 'paypal.php') //Change to paypal URL
.submit();
});
On the next page, you do exactly what you said previously:
<input type="hidden" name="somedata" val="<?php echo $somedata; ?>" />
Always sanitize user-inputted values before echoing them on the page (therefore the variable $somedata rather than $_POST['somedata'].
An alternative to hidden input fields is sessions. Much easier to handle once you get the hang of it.
Add another line as:
test.php is the page where you want to post this form
<input type="button" border="0" value="Pay with Stripe" onclick="submitForm('test.php')">
in test.php you can get the values like this:
<input type="hidden" name="test" value="<?php echo $_REQUEST['test'] ?>">
SO..i have this project that is totally backwards, but basically i have to give a working form that adds a quantity of some item_ID and then redirects to the cart page of a framework i use.
Of course rather than me just skin my framework, and customize its functionality for him. This guy has some hacked up php pages that he "wrote himself" that he insists on hard coding forms into.
anyways, i have a form that submits to my cart.php in the action
<form name="orderform" method="post" action="http://s429036015.onlinehome.us/cart.php" id="orderform">
<input type="hidden" name="mode" value="add" />
<input type="hidden" name="productid" value="140" />
<input type="hidden" name="cat" value="" />
<input type="hidden" name="page" value="" />
Qty <input type="text" id="product_avail" name="amount" />
<button class="button main-button list-button add-to-cart-button" type="submit" title="" onClick="location.href='cart.php'">
<span class="button-right"><span class="button-left">Add to cart</span></span>
</button>
</form>
The above form submits properly, with the quantity entered, session stores the data and the items are in the cart just fine....however, that onclick event on the <button> doesn't work!
I've even tried this
<button class="button main-button list-button add-to-cart-button" type="submit" title="" onClick="GotoPage(); return:true;">
with this script ahead of the form
<script type="text/javascript">
function GotoPage() {
window.location = "http://s429036015.onlinehome.us/cart.php";
}
</script>
anyone have any ideas? driving me nuts...
In PHP, after you process data from form, try this:
header('location: http://s429036015.onlinehome.us/cart.php');
Basically I just want to turn off the button after people purchase the art and send them a receipt. I would also like to have a copy of their information. This is what I am passing through my array:
<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="email#mydomain.com" />
<input type="hidden" name="item_name" value="<?php echo $title; ?> (ID:#<?php echo " {$p['id']}" ?>)" />
<input type="hidden" name="item_number" value="<?php echo "{$p['id']}" ?>" />
<input type="hidden" name="amount" value="<?php echo "{$p['price']}" ?>" />
<input type="hidden" name="shipping" value="39.99" />
<input type="hidden" name="return" value="http://mydomain.com/thankyou.php" />
<input type="submit" value=" " class="button" />
</form>
How do I setup a sold field in my database and show/hide my button in php?
IPN, API which do I need to use to make it happen?
Cheers!
I would setup the IPN listener to mark the item's status as sold in it's database table (you are generating that form based on a database?) when the IPN comes back "VERFIFIED" and payment_status = 'Complete'. Then, only generate that form when the item is not sold.
If you don't know how to implement an IPN listener, here is a tutorial: PayPal IPN with PHP
I own a locally exclusive trade form for people to sell items to others locally. I want to have an option to include a Paypal "Buy Now" button in new posts but I'm stuck at how to include the button in a new post without having the user manually copy/past the HTML. I have made a simple Paypal button generator with a checkbox and jQuery to display form fields if checkbox is checked. Here it is on jsfiddle
HTML
<form>
<input type="checkbox" id="checkme" /> Add a "Buy Now" Paypal button
</form>
<div id="extra">
<form action="includes/paypal_button.php" method="post">
Paypal account email: <input type="text" name="email" /><br />
Short item description: <input type="text" name="item" /><br />
Price for item (all amounts are in USD): <input type="text" name="amount" /><br />
Tax amout: <input type="text" name="tax" /><br />
Shipping and handling: <input type="text" name="shipping" />
<input type=submit value="Create Paypal button!">
</form>
</div>
jQuery
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//Hide div w/id extra
$("#extra").css("display","none");
// Add onclick handler to checkbox w/id checkme
$("#checkme").click(function(){
// If checked
if ($("#checkme").is(":checked"))
{
//show the hidden div
$("#extra").show("fast");
}
else
{
//otherwise, hide it
$("#extra").hide("fast");
}
});
});
</script>
The controller form is in a separate php script, paypal_button.php
HTML
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo htmlspecialchars(($_POST["email"]))?>" >
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="<?php echo htmlspecialchars(($_POST["item"]))?>">
<input type="hidden" name="amount" value="<?php echo htmlspecialchars(($_POST["amount"]))?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="tax_rate" value="<?php echo htmlspecialchars(($_POST["tax"]))?>">
<input type="hidden" name="shipping" value="<?php echo htmlspecialchars(($_POST["shipping"]))?>">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" 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">
</form>
So should I include the controller(the button to print) in a php if statement that will print the button in new form posts? It would be highly appreciative if someone could point me in the right direction.
Thanks in advance