Verify PayPal payment - php

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 !!

Related

How to integrate paypal into my php project?

I'm developing an ecommerce website (as a project) and I want to integrate payment gateway in same. In this project when a user clicks on a product at index page, he's redirected to product_detail.php where there is a buy now button which directs him to payment gateway, but I always get the error "BAD_INPUT_ERROR: Things don't appear to be working at the moment. Please try again later."
Here's a part of my code
<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="INR">
<INPUT TYPE="hidden" name="charset" value="utf-8">
<!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='http://localhost/search/cancel.php'>
<input type='hidden' name='return' value='http://localhost/search/success.php'>
<!-- Display the payment button. -->
<input type="image" name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
</form>
Am I missing something? (I'm a beginner in php and I learned this from a website), also I wasn't able to turn on Auto return in my paypal sandbox account because they weren't able to validate my return URL. Do I need to host my project first so that it accepts my return URL?

paypal Payment gateway link for direct payment

hear is my code for paypal payment it redirects to login of paypal gateway,
but i want it redirect to direct payment page so that if i haven't paypal account
i can countinue with that option.
<?php
$paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$paypal_id = 'gohilpriyank-facilitator#ymail.com';
?>
<div class="form-group row-fluid">
<div class="span6">
<span style="font-weight: bold">Ship To Address:-</span>
<div><?php echo $ship_to['ship_address']; ?></div>
<div><?php echo $ship_to['ship_landmark']; ?></div>
<div><?php echo $ship_to['ship_city']; ?></div>
<div><?php echo $ship_to['ship_state']; ?></div>
<div><?php echo $ship_to['ship_pincode']; ?></div>
</div>
<div class="span6">
<span style="font-weight: bold">Choose Payment Mode</span>
<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
<input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="Kevalam Payment">
<input type="hidden" name="item_number" value="<?php echo count($this->cart->contents()); ?>">
<input type="hidden" name="credits" value="510">
<input type="hidden" name="userid" value="1">
<input type="hidden" name="amount" value="<?php echo $_SESSION['grand_total']; ?>">
<input type="hidden" name="cpp_header_image" value="http://k1-pc/myriad/assets/user_temp/image/logo.png">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="handling" value="0">
<input type="hidden" name="cancel_return" value="http://k1-pc/myriad/cancel.php">
<input type="hidden" name="return" value="http://k1-pc/myriad/success.php">
<input type="image" src="https://paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" name="submit">
</form>
</div>
</div><div class="clear"></div>
When using Payments Standard like this the Guest Checkout (direct credit card) option is displayed differently based on the cookies set for the current browser.
If you've ever signed in to any PayPal with the same browser it will find a cookie and assume that you'll be signing in again, so it will show you a landing page that really pushes the login aspect of PayPal checkout.
If you clear your browser cache/cookies (or just try a fresh browser) you should see a different landing page where the Guest Checkout option is more prominently displayed.
If you switch to the Express Checkout API instead of using Payments Standard you can force Guest Checkout to be displayed more prominently regardless of browser cookies. The SetExpressCheckout request includes parameters you can use to adjust the checkout pages accordingly.
Since you're using PHP, I'd recommend taking a look at my PHP class library for PayPal. It would make integrating Express Checkout very simple for you. Basically, it consists of the following API calls, which are included in the /templates directory with the library.
SetExpressCheckout
GetExpressCheckoutDetails
DoExpressCheckoutPayment
The parameters you'll use to handle the Guest Checkout options are in the SetExpressCheckout request and consist of...
SOLUTIONTYPE=Sole
LANDINGPAGE=Billing
USERSELECTEDFUNDINGSOURCE=CreditCard

getting the grand total and email using order id in magento

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 ?>

Using paypal buy now form in php gallery please help

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

Virtuemart Repeat Order

The thing is that I would like to implement the following functionality to my site:
In the account settings - order details I would like to add a button that would add all the products from that very order to cart.
Now, I pretty much get it how the add to cart functionality is implemented on the flypage and browse page. I can't really get how should I pass multiple items to the add to cart function on order details page and how it'll be processed by ps_cart if an item is out of stock or is unpublished.
Here's the code of the add to cart form from browse page:
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
<?php echo $ps_product_attribute->show_quantity_box($product_id,$product_id); ?><br />
<input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
<input type="hidden" name="category_id" value="<?php echo #$_REQUEST['category_id'] ?>" />
<input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
<input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
<input type="hidden" name="page" value="shop.cart" />
<input type="hidden" name="func" value="cartadd" />
<input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="set_price[]" value="" />
<input type="hidden" name="adjust_price[]" value="" />
<input type="hidden" name="master_product[]" value="" />
</form>
I wonder if I'd need to pass all of these to ps_cart?
I don't expect from any of you a completely ready extension, it would be great if you could point me in the right direction.
Thanks!
EDIT:
I was able to set up the add to cart button, now I have to pass the needed data.
It would be great if it would work with at least one item, then I'd start thinking how to alter the code.
EDIT 2:
I was able to make it work flawlessly for one product. But how can I pass multiple Product Id's and their quantities to the add to cart function?
The current code in ps_cart already has a loop to iterate through multiple product IDs that are sent to the cart. From the look of the code there, I would simple put all of the product IDs you want to add to the cart in to prod_id array. You will notice that prod_id, set_price, adjust_price, and master_product are all arrays in the form. My guess is that you will need to put in those values for each product you want to add and ps_cart will do the rest.

Categories