How to integrate PayUMoney in core php - php

Hi I am new to PHP and I want to integrate the PayUMoney with core PHP. Can anyone tell me how to do the integration of PayUMoney in core PHP.
Here is my code
Controller:
<?php
$results = $db->query("SELECT * FROM courses");
while($row = $results->fetch_assoc())
{
?>
<img src="images/<?php echo $row['image']; ?>" style = "width:20%;"/>
<br/><strong>Course:</strong> <?php echo $row['name']; ?>
<strong>Price:</strong> <?php echo $row['price']; ?>
<form action="http://www.payumoney.com" method="post">
<input type="hidden" name="business" value="ashalatha.cse76#gmail.com">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="<?php echo $row['name']; ?>">
<input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="image" name="submit" border="0" style="width:9%;"
src="buynow.png" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="" >
</form>
<?php } ?>

This OpenPayu sdk is only for polish market. You can change configuration in link below https://github.com/PayU/openpayu_php/blob/master/lib/OpenPayU/Configuration.php
and adjust to parametres.

Related

Paypal Code error. Redirecting to error 400

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.

Paypal integration with php , Code working with 1 mail id not with another

I have a problem with integrating paypal gateway in my website
I tested many times and used many codes.
My current code :
<?php
//Include DB configuration file
include 'dbConfig.php';
//Set useful variables for paypal form
$paypalURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; //Test PayPal API URL
//$paypalID = 'PayPalMerchant#example.com'; //Business Email
$paypalID = 'intermixitsolution#gmail.com';
?>
<?php
//Fetch products from the database
$results = $db->query("SELECT * FROM products");
while($row = $results->fetch_assoc()){
?>
<img src="images/<?php echo $row['image']; ?>"/>
Name: <?php echo $row['name']; ?>
Price: <?php echo $row['price']; ?>
<form action="<?php echo $paypalURL; ?>" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="<?php echo $paypalID; ?>">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="<?php echo $row['name']; ?>">
<input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="hidden" name="currency_code" value="USD">
<!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='http://intermixitsolution.net/paypal/cancel.php'>
<input type='hidden' name='return' value='http://intermixitsolution.net/paypal/success.php'>
<!-- Display the payment button. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
<?php } ?>
In this code if i used
$paypalID = 'intermixitsolution#gmail.com';
It gives error as:
And if i use
$paypalID = 'PayPalMerchant#example.com';
Everything working fine
Suggest me solution.Thanks

Notify function isn't updating the database while performing paypal payments

This is my first time integrating the Paypal Payment in a project and it is in CI. So the thing is everything is working perfectly except that the Notify Url was supposed to make me able to change the payment status from 'Pending' to 'Success' but it isn't in my case. I have the code below and i really have tried many things but still don't know where i am slipping off.
<form id="paypal-pre" action="<?php echo base_url('auth/process'); ?>" method="post">
<input type="hidden" name="user_id" value="<?php echo $_POST['register_user_id']; ?>">
<input type="hidden" name="first_name" value="<?php echo $_POST['customer_first_name']; ?>">
<input type="hidden" name="last_name" value="<?php echo $_POST['customer_last_name']; ?>">
<input type="hidden" name="addr1" value="<?php echo $_POST['customer_address1']; ?>">
<input type="hidden" name="addr2" value="<?php echo $_POST['customer_address2']; ?>">
<input type="hidden" name="city" value="<?php echo $_POST['customer_city']; ?>">
<input type="hidden" name="county" value="<?php echo $_POST['customer_county']; ?>">
<input type="hidden" name="postcode" value="<?php echo $_POST['customer_postcode']; ?>">
<input type="hidden" name="amount" value="<?php echo $_POST['payment_total']; ?>">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
Above is the billing info collection form.
function process(){
$arr['user'] = array(
'p_user_id' => $this->input->post('user_id'),
'p_billing_firstname' => $this->input->post('first_name'),
'p_billing_lastname' => $this->input->post('last_name'),
'p_billing_address1' => $this->input->post('addr1'),
'p_billing_address2' => $this->input->post('addr2'),
'p_billing_city' => $this->input->post('city'),
'p_billing_county' => $this->input->post('county'),
'p_billing_postcode' => $this->input->post('postcode'),
'p_status' => 'processing',
'p_amount' => $this->input->post('amount'),
);
$arr['pay'] = array(
'p_amount' => $this->input->post('payment_total'),
);
$this->load->model('demo_auth_model');
$this->demo_auth_model->process($arr);
$this->load->view('paypal',$arr);}
function notify() {
if($this->input->post('custom') != ''){
$id = $this->input->post('custom');
$amt = $_POST['amount'];
$sql = "UPDATE users_payments SET p_status='success' WHERE p_id='$id'";
$this->db->query($sql);
return;
}
}
The Process and notify controller function
<?php $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$paypal_id = '******#yahoo.com';
$amount = $_POST['amount'];
$id = mysql_insert_id();?>
<form id="paypal" action="<?= $paypal_url; ?>" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="amount" value="<?php echo $amount; ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="<?php echo 'Business Register'; ?>">
<input type="hidden" name="custom" value="<?php echo $id; ?>" />
<input type='hidden' name='notify_url' value='<?php echo base_url('auth/notify'); ?>'>
<input type='hidden' name='cancel_return' value='<?php echo base_url('auth/cancel'); ?>'>
<input type='hidden' name='return' value='<?php echo base_url();?>'>
</form><script type="text/javascript">
document.getElementById('paypal').submit();
</script>
The main paypal form which is submitted automatically after saving the billing information.
public function process($arr) {
$this->db->set($arr['user']);
$this->db->insert('user_payments');
return;
}
Process Model from demo_auth_model
Any help would be really appreciated.
P.S. All database infos are correct
well for codeigniter i prefer this library
http://tutsnare.com/integrate-paypal-using-ci-merchant-in-codeigniter/
https://github.com/expressodev/ci-merchant
for 2 Reasons
1. Auto redirect to our website
2. Take all data in session to our website
Try it and enjoy

Sandbox paypal test account not returning variables

I have two paypal test accounts. One is "testaddabusiness#shop.com" and another is "testaddapersonal#shop.com". They both are for testing my transactions. I followed a tutorial to make a shopping cart integrated with paypal. The problem is it is not returning some of the variables which i need to save in my database table. I have setup the website preference with success.php. It is not returning payment details from paypal.
success.php
<?php
session_start();
include("db/db.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<html>
<title>Success</title>
<body>
<?php
if(isset($_SESSION['cart']) && isset ($_SESSION['login_email'])){
$total=0;
$ships=$_POST['shipment'];
$user=$_POST['name'];
$user_id=$_POST['id'];
$file=$_FILES['file']['name'];
//orders and order details.
$que=mysqli_query($con,"insert into orders(custom_file,date,customerid,ship_days) values('$file',CURRENT_TIMESTAMP(),'$user_id','$ships')");
if($que)
{
$m=move_uploaded_file($_FILES['file']['name'],'./ServerUploadedFiles/'.$user.$file);
$q=mysqli_query($con,"select serial from orders where customerid='$user_id' and date=CURRENT_TIMESTAMP()");
while($row1=mysqli_fetch_array($q,MYSQLI_ASSOC))
{
$order_id=$row1['serial'];
}
foreach($_SESSION['cart'] as $id => $value){
$subtotal=$value['price']*$value['quantity'];
$pid=$value['id'];
$quantity=$value['quantity'];
$color=$value['color'];
$size=$value['size'];
$total+= $subtotal;
$query= mysqli_query($con, "INSERT INTO order_detail(orderid,productid,quantity,price,color,size) VALUES ($order_id, $pid, $quantity, $subtotal, '$color', '$size')");
}
}
//payment details for paypal
$amount=$_GET['amt'];
$currency=$_GET['cc'];
$trx_id=$_GET['tx'];
$insert_payments= mysqli_query($con,"insert into payments(amount,cust_id,trx_id,currency) values('$amount','$user_id','$trx_id','$currency')");
if($amount==$total)
{
echo "<h2>Hello". $user."You have successfully done purchasing process.Please <a href='profile.php'>Go to your account</a>!</h2>";
}
else
{
echo "<h2>Hello". $user."Your payment was not successful.Please <a href='profile.php'>Go to your account</a>!</h2>";
}
}
?>
</body>
</html>
form.php
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" enctype="multipart/form-data">
<?php
$email=$_SESSION["login_email"];
$query=mysqli_query($con,"select * from customers where email='$email'");
while($row=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<input type="hidden" class="input_form" name="id" value="<?=$row["serial"]?>">
<input type="hidden" class="input_form" name="name" value="<?=$row["name"]?>">
<input type="hidden" class="input_form" name="phone" value="<?= $row["phone"] ?>">
<input type="hidden" class="input_form" name="city" value="<?= $row["city"] ?>">
<input type="hidden" class="input_form" name="address" value="<?= $row["address"] ?>">
Download custom size form Provide us your custom size
<input type="file" name="file">
Select shipment interval (optional):<select id="shipment" name="shipment">
<option selected value="7" id="7">7</option>
<option value="6" id="6"> 6 </option>
<option value="5" id="5">5 </option>
<option value="4" id="4">4 </option>
<option value="3" id="3">3 </option>
</select>
<p>Before clicking submit read Terms and Policies carefully..Once ordered would not be restored.</p>
<input type="checkbox" value="I accept the terms and policies by Aada Fashion.">I accept the terms and policies by Aada Fashion.
<?php
}
?>
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="testaddabusiness#shop.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<?php
if(isset($_SESSION['cart'])){
$count=1;
foreach($_SESSION['cart'] as $id => $value){
?>
<input type="hidden" name="item_number_<?php echo $count ?>" value="<?php echo $value['id'] ?>">
<input type="hidden" name="item_name_<?php echo $count ?>" value="<?php echo $value['name'] ?>">
<input type="hidden" name="quantity_<?php echo $count ?>" value="<?php echo $value['quantity'] ?>">
<input type="hidden" name="amount_<?php echo $count ?>" value="<?php echo $value['price'] ?>">
<input type="hidden" name="on1_<?php echo $count ?>" value="<?php echo $value['color'] ?>">
<input type="hidden" name="on0_<?php echo $count ?>" value="<?php echo $value['size'] ?>">
<input type="hidden" name="currency_code" value="USD">
<?php
$count++;
}
}
?>
<input type="hidden" name="return" value="http://abc/WebProject_Adda/success.php">
<input type="hidden" name="cancel_return" value="http://abc/WebProject_Adda/paypal_cancel.php">
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>

Display all cart items in Paypal checkout

I want to list all the items purchased in Paypal checkout. I have tried the following code but it does not show items there. It just show the input field in checkout. I am adding snapshot of paypal also. I am first time trying to integrate my site with Paypal.
Code
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="testaddabusiness#shop.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<?php
if(isset($_SESSION['cart'])){
foreach($_SESSION['cart'] as $id => $value){
$count=1;
?>
<input type="text" name="item_name_<?php echo $count ?>" value="<?php echo $value['name'] ?>">
<input type="text" name="item_qty_<?php echo $count ?>" value="<?php echo $value['quantity'] ?>">
<input type="text" name="amount_<?php echo $count ?>" value="<?php echo $value['price'] ?>">
<input type="text" name="color_<?php echo $count ?>" value="<?php echo $value['color'] ?>">
<input type="text" name="size_<?php echo $count ?>" value="<?php echo $value['size'] ?>">
<input type="text" name="currency_code_<?php echo $count ?>" value="USD">
<?php
$count++;
}}
?>
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
item_name_x only applies to Cart Upload command.
You need to change cmd value to "_cart", and add another variable called upload and value of 1.
Here is an example:
cmd = _cart
upload = 1
amount_1 = 0.01
item_name_1 = Test Item
item_number_1 = 123
currency_code = USD
...
After that, your code should work.
For more information, visit HTML Variables of PayPal Payment Standard.

Categories