In my redirect file, I'm trying to get the grand total of a customer's cart and also email using the order id but on redirecting to the bank payment gateway which I'm using, it retruns a response that the amount sent is invalid. Which simply means, I'm sending an empty parameter.
The form field name is "amt" while the form field for email is "email"
Below is the code:
<?php
// Retrieve order
$_order = new Mage_Sales_Model_Order();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$_order->loadByIncrementId($orderId);
?>
<form method="post">
<input type="hidden" name="amt" value="<?php echo $_order->getBaseGrandTotal(); ?>">
<input type="hidden" name="orderId" value="<?php echo $orderId; ?>">
<input type="hidden" name="email" value="<?php echo Mage::getSingleton('customer/session')->getCustomer()->getEmail() ; ?>">
</form>
Can anyone help out with this?
Thanks!
It might not be able to find the last order. Try
<?php $_order = Mage::getSingleton('checkout/session')->getLastRealOrder(); ?>
<?php if (!$_order || !$_order->getId()): ?>
<!-- no last order found -->
<?php else: ?>
<form method="post">
<input type="hidden" name="amt" value="<?php echo $_order->getBaseGrandTotal(); ?>">
<input type="hidden" name="orderId" value="<?php echo $_order->getId(); ?>">
<input type="hidden" name="email" value="<?php echo $_order->getCustomerEmail(); ?>">
</form>
<?php endif ?>
Related
Hello all i just need to make a simple page. And need to practice how we integrate paypall in our website and use it. But i don't what is the problem it redirect me to 400 error page. Here is my code.
<table class="right" >
<?php
while($row = $results->fetch_assoc()){
?>
<tr>
<td class="image-container"><img src="images/<?php echo $row['image']; ?>" class = "image"/></td>
<td><h3 class="Product-Name">name: <?php echo $row['name'];?></h3> <h4>Price <?php echo $row['price']; ?></h4></td>
<td>
<input type="hidden" name="cmd" value="_ext-enter">
<form name = "subs" action = "https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="business" value="mona22-merchant#softgetix.com">
<input type="hidden" name="amount" value = <?php echo $row['price'] ?> id="paypalamt">
<input type="hidden" name="item_name" value = <?php echo $row['name']?> id = "name" >
<input type="image" src="../images/mobile2.jpg" border="0" name = "submit">
</form>
</td>
</tr>
<?php }?>
</table>
The inputs with ( name="amount" & name="item_name" ), thier values have to be enclosed like this :
value ="php code inside"
Log in to your paypal account.
Go to Tools > Business Setup.
Scroll down to Paypal Buttons:
You have on the right side an option with : Create new button
Add and edit your button.
I'm creating a site with a payment system, I'll explain you the problem with the code :
Order.php
<div class="bg-login" style="background-color: #fef8f8;">
<div id="login">
<div class="order-header">
Détails de la commande
</div>
<div class="order-content">
<h3>Prix:</h3>
<p><?php echo $price; ?> €</p>
<h3>Commande:</h3>
<p><?php echo $paypal['item_name']; ?></p>
<h3>Serveur:</h3>
<p><?php echo strtoupper($server); ?></p>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" id="paypal-form" method="POST">
<input type="hidden" id="cmd" name="cmd" value="<?php echo $paypal['cmd']; ?>">
<input type="hidden" id="return" name="return" value="<?php echo $paypal['return']; ?>">
<input type="hidden" id="currency_code" name="currency_code" value="<?php echo $paypal['currency_code']; ?>">
<input type="hidden" id="business" name="business" value="<?php echo $paypal['business']; ?>">
<input type="hidden" id="amount" name="amount" value="<?php echo $paypal['amount']; ?>">
<input type="hidden" id="item_name" name="item_name" value="<?php echo $paypal['item_name']; ?>">
<button type="button" onclick="payment()" class="order-submit">Payer <?php echo $price; ?> €</button>
</form>
</div>
</div>
</div>
This is my page which get me the price of the order to Paypal. And with this :
<input type="hidden" id="return" name="return" value="<?php echo $paypal['return']; ?>">
I can, after the transaction, get the user on a page "Paypal.php" when the transaction is done.
On this page paypal.php i'll ask the user to create an account after his order (will add order infos in the database when he has created his account).
The problem is, I had as idea to make every order infos in sessions variables to get them in paypal.php, but everyone can go on paypal.php even if they didn't payed, so they just have to go on order.php then go to paypal.php to get a free order.
I'd like to know how is possible to get the status of the order with paypal on paypal.php, I looks a bit on paypal doc, there's a IPN thing to know the status of the transaction, but I don't know how to use it :( If someone could help me to know if the user has well payed on paypal.php, would be really awesome And If you've any smart idea instead of take the order infos in sessions, tell me, I've no idea for it.
Thanks !!
Hopefully this makes sense. Been working on a project for awhile and i'm just about done! Just stuck and not sure why this isn't working.
I have an entire Crud app used with php and mysql. Everything works correctly except for when I go to my update.php page. When I click update on the home page, it takes me to the update page where I can fill out fields to update the mysql data. That all works fine! What I am having issues with is when I go to the update page, the form fields are blank. I want them to be pre-filled with the data that's already in there, so "fetching" the data. That way, the user doesn't have to go back and look at the data and then re-type all the information again instead of just backspacing and updating just the field data that they want. Does that make sense? Here's my code. Notice and focus where I have the $fetch variable...I know it's a lot. I tried to remove all the really unecessary stuff. If you are able to look at this and see an easy fix, please let me know! Struggling here. Below is my "update.php" page:
<?php
session_start();
$login_session=$_SESSION['login_user'];?>
<?php
if(!$_SESSION['login_user']){
header("location: login.php");
die;
}
?>
<p>Go Back |
Logout </p>
<?php
include 'scripts/db.php';
if(isset($_GET['id']) && is_numeric($_GET['id']))
{
$id=$_GET['id'];
}
$select=mysql_query("SELECT * FROM Order_1 WHERE id='$id'");
$fetch=mysql_fetch_array($select);
if(isset($_POST['update']))
{
$name=$_POST['name'];
$product=$_POST['product'];
$size=$_POST['size'];
$price=$_POST['price'];
$shipping=$_POST['shipping'];
$shipped=$_POST['shipped'];
$delivered=$_POST['delivered'];
$update=mysql_query("UPDATE Order_1 SET Name='$name',Product='$product',Size='$size',Price='$price',Shipping='$shipping',Shipped='$shipped',Delivered='$delivered' WHERE id='$id' ");
if($update) {
?>
<script>alert('Record updated successfully!');</script>
<?php
echo '<script type="text/javascript">window.location="home.php";</script>';
}
else
{
?>
<script>alert('Error updating record.');</script>
<?php
}
}
?>
<div class="container">
<h1>Edit Your Order and Click Submit:</h1>
<div class="updateForm">
<form method="post">
<p>Name: <input type="text" name="name" placeholder="First, Last" value="<?php echo $fetch['name']; ?>" /></p>
<p>Product: <input type="text" name="product" size="15" placeholder="T-Shirt, Shoes, etc..." value="<?php echo $fetch['product']; ?>" /></p>
<p>Size: <input type="text" name="size" size="10" placeholder="S, M, L, XL, XXL" value="<?php echo $fetch['size']; ?>" /></p>
<p>Price: <input type="text" name="price" size="10" placeholder="$0.00" value="<?php echo $fetch['price']; ?>" /></p>
<p>Shipping: <input type="text" name="shipping" size="10" placeholder="$0.00" value="<?php echo $fetch['shipping']; ?>" /></p>
<p>Shipped?
Yes<input type="radio" name = "shipped" value="Yes" value= "<?php echo $fetch['Yes']; ?>"/>
No<input type="radio" name = "shipped" value="No" value = "<?php echo $fetch['No']; ?>" /></p>
<p>Delivered?
Yes<input type="radio" name = "delivered" value="Yes" value="<?php echo $fetch['Yes']; ?>" />
No<input type="radio" name = "delivered" value = "<?php echo $fetch['No']; ?>" /></p>
<p><input type="submit" name="update" value="Submit" /></p>
</form>
</div>
</div>
If the above title looks confusing then here is the description....
I have a template page where I have placed the wordpress default registration form. Now what exactly I want is to add few extra fields on that form.
The wordpress registration will go on as it is. I mean the username and email and password gets stored on the database but along with that new fields or extra details like phone/address/age etc etc gets emailed to a specific email id.
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form">
<div class="username">
<label for="user_login"><?php _e('Username'); ?>: </label>
<input type="text" name="user_login" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" id="user_login" tabindex="101" />
</div>
<div class="password">
<label for="user_email"><?php _e('Your Email'); ?>: </label>
<input type="text" name="user_email" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" id="user_email" tabindex="102" />
</div>
<div class="login_fields">
<?php do_action('register_form'); ?>
<input type="submit" name="user-submit" value="<?php _e('Sign up!'); ?>" class="user-submit" tabindex="103" />
<?php $register = $_GET['register']; if($register == true) { echo '<p>Check your email for the password!</p>'; } ?>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>?register=true" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</form>
**Note:- The new fields aren't added here.
Is it possible? If yes, then how? Should I add a second form below this form which fires the email? Kindly please suggest an appropriate solution for this.
Although variations of this question have been asked before, none of them have helped me solve this puzzle. at present the form I have put together updates the database fine etc, the issue is when I go to edit the field, only the first part of the data is shown for example, if the data was 'Sunny Day' then when i clicked to edit this field all i would get is 'Sunny', so then if i then clicked update, it would edit the database back to Sunny. Am i missing something?!
Thanks in advance.
// Connects to your Database
$query=mysql_connect("localhost", "cl52-abcdef","abcdef") or die(mysql_error());
mysql_select_db("cl52-abcdef",$query);
?>
<html>
<body>
<?php
if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['submit']))
{
$holdesc1=$_POST['holdesc1'];
$holdest1=$_POST['holdest1'];
$rrp1=$_POST['rrp1'];
$cpe1=$_POST['cpe1'];
$ea1=$_POST['ea1'];
$query3=mysql_query("update DealOne set holdesc1='$holdesc1',holdest1='$holdest1',rrp1='$rrp1',cpe1='$cpe1',ea1='$ea1' where id='$id'");
if($query3)
{
header('location:list.php');
}
}
$query1=mysql_query("select holdesc1, holdest1, rrp1, cpe1, ea1 from DealOne where id='$id'");
$query2=mysql_fetch_array($query1);
?>
<form method="post" action="">
1 <input type="text" value=<? echo $query2['holdesc1']; ?> name="holdesc1"><br>
2 <input type="text" value=<? echo $query2['holdest1']; ?> name="holdest1"><br>
3 <input type="text" value=<? echo $query2['rrp1']; ?> name="rrp1"><br>
4 <input type="text" value=<? echo $query2['cpe1']; ?> name="cpe1"><br>
5 <input type="text" value=<? echo $query2['ea1']; ?> name="ea1"><br><br>
<input type="submit" name="submit" value="update" />
</form>
<?php
}
?>
</body>
</html>
Only the first part of the data is showing up because your value attribute values do not have quotes around it. Otherwise, your HTML looks like: <input type="text" value=Sunny day name="holdesc1">
Change your text inputs to the following:
<input type="text" value="<? echo $query2['holdesc1']; ?>" name="holdesc1"><br>
<input type="text" value="<? echo $query2['holdest1']; ?>" name="holdest1"><br>
<input type="text" value="<? echo $query2['rrp1']; ?>" name="rrp1"><br>
<input type="text" value="<? echo $query2['cpe1']; ?>" name="cpe1"><br>
<input type="text" value="<? echo $query2['ea1']; ?>" name="ea1"><br><br>