PayPal Payment Callback - php

I have searched for more than 4 hours now on how to do callback with PayPal after a payment have been proceeded.
The thing is, I have a site the sells tickets to a LAN Party, and the only way to pay is with PayPal.
Here is my PayPal buy button code:
<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="_MY_PAYPAL_EMAIL_">
<input type="hidden" name="item_number" value="<?php echo mktime(); ?>">
<input type="hidden" name="cn" value="<?php echo $_SESSION['userid']; ?>">
<input type="hidden" name="return" value="http://80.202.213.240/apps/tickets/buy/success/" />
<input type="hidden" name="cancel_return" value="http://80.202.213.240/apps/tickets/buy/cancelled/" />
<input type="hidden" name="notify_url" value="http://80.202.213.240/apps/tickets/buy/ipn/" />
<input type="hidden" name="lc" value="NO">
<input type="hidden" name="item_name" value="BitHack - Standard Ticket">
<input type="hidden" name="amount" value="100.00">
<input type="hidden" name="currency_code" value="NOK">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="button_subtype" value="Tickets">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
<input type="submit" value="Add to Cart" class="ticketShowButton submit" title="Payment via PayPal">
The info should then be inserted into a database, that part I have finished.
Just need the callback system to work.
Anyone know any good callback script examples?
BTW, is it possible do use custom inputs?

The callback function specified in the return and notify url variables are the programmer's responsibility. Why? Because each website has it's own table structure for orders. Try this as a guide:
On your Paypal profile set your preference to redirect automatically after an order. You will also need to set a default return url. this will be used if you forgot to specify a return url on your order form or query string sent to Paypal.
Next, set your rm field/variable to "2" (this will tell Paypal API to autoredirect to your return url after the order and pass the order info in POST format)
You can view the response from Paypal by doing a var_dump($_POST) or print_r($_POST).
One of the important variables from the response is $_POST['payment_status'] which will tell you the outcome of the order. A successful transaction is 'Completed'. A transaction that requires verification from Paypal or from the merchant's side is 'Pending'.
Lastly, don't forget to specify 'invoice' on your Paypal field/request so you can update the status of your order. Something like:
$status = $_POST['payment_status'];
$invoice = $_POST['invoice'];
mysql_query("UPDATE Orders SET status='$status' WHERE order_id='$invoice'");
I know this is bad and unsafe coding but at least you get the general idea in it's simplest form.
Again, don't rely on other's codes. Codes in the net exists for reference purposes and not as God's handwork. Only you have the power to create your own masterpiece :D
I hope that helps. Vote up if you like it. Ignore if not.

A commercial but low cost solution is the LinkLokIPN script at:
http://www.vibralogix.com/linklokipn/
No connection other than as a satisfied customer of the PHP version. Sometimes it is MUCH easier to buy (and perhaps adapt) a working solution than to reinvent the wheel.

Related

paypal website form return parameters with link and auto return

I choose "on" for auto return from my selling tools:
https://www.paypal.com/webapps/customerprofile/
But auto return is not working! why?
and this my form:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="business" value="example#mail.com">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="<?php echo $name; ?>">
<input type="hidden" name="item_number" value="<?php echo $id; ?>">
<input type="hidden" name="amount" value="0.01">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="return" value="http://example.com/done.php">
<input type="hidden" name="cancel_return" value="http://example.com/cancel.php">
<input type="submit" name="submit" value="Buy">
</form>
now my return page not has parameters like this:
http://example.com/done.php?tx=XXXX&st=Completed&amt=200.00&cc=USD&cm=&item_number=7
I need auto return and paramteres!
Help me.
Most Likely, you did not enable Payment Data Transfer(PDT).
You enabled PDT, but if transaction is made via Credit card, you will need to manually click on "return to merchant site" link to get redirected
to your return URL which means auto-return only works if payment is made via paypal account.
Steps to enable PDT
-Login to your PayPal account
-click on Profile
-click 'My selling preferences
-click on Update next to Website preferences
-Go to the Payment Data Transfer Section
-Choose Payment Data Transfer ON and the Token will be displayed below
PDT Sample codes

Capture PayPal return variable using PHP

I am using PayPal Standard HTML form, and after the user has completed the transaction he/she is taken to the return url. I want to be able to identify the user email, the order number, and other information that may be available using php. In other words, I want to use the GET method to retrieve the variables in the URL
This is a recurring payment (subscription), and below is the html code.
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="info#merchant.com">
<input type="hidden" name="return" value="test">
<!-- Specify a Subscribe button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Identify the subscription. -->
<input id="paymentName" type="hidden" name="item_name" value="test">
<input type="hidden" name="item_number" value="1234">
<!-- Set the terms of the regular subscription. -->
<input type="hidden" name="currency_code" value="CAD">
<input id="paymentPrice" type="hidden" name="a3" value="0.01">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<!-- Set recurring payments until canceled. -->
<input type="hidden" name="src" value="1">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" style="width:240px; border: none; height:50px"
src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-large.png"
alt="PayPal - The safer, easier way to pay online">
</form>
As others already commented. You should use Instant Payment Notification (IPN).
documentation
Basically you need to set in your html form a field called "notifyurl", something like this:
<input type="hidden" name="notifyurl"alue="http://www.example.com/ipn_listener.php">
For the ipn_listener.php you have sample code here (if PHP):
Sample code for PHP
If you need to attach some specif information to the payment you can also use the paremeter "custom", and read it back in you ipn listener.

PayPal not returning variables

I'm adding PayPal to my checkout form. Rather than using the API, I just use a form script. However, I'm not getting the response variables from PayPal after the payment has been made. I would like to confirm the amount of money I received to see if the user has paid the amount he should've paid.
Since I dont receive the response variables from paypal, I cannot see whether the user has indeed paid the good amount of money. Am I doing something wrong? I see alot of people have problems with it and none of them had the answer.
My form:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" >
<input type="hidden" name="business" value="seller#seller.com">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="item_name" value="<?php echo $_amount_credits ?> credits">
<input type="hidden" name="item_number" value="<?php echo $_invoice_id ?>">
<input type="hidden" name="amount" value="<?php echo $_total_amount ?>">
<input type="hidden" name="lc" value="NL">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Go back to http://domain.com">
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="return" value="http://domain.com/index.php?payment=success&transaction_id=<?php echo $_GET['tx'] ?>"/>
<input type="hidden" name="cancel_return" value="http://domain.com/index.php?payment=canceled&transaction_id=<?php echo $_GET['tx'] ?>"/>
<input type="submit" class="button blue _quick_order_overview _payment_paypal" name="submit" value="Pay via PayPal">
</form>
You should use Instant Payment Notification (IPN) for this sort of thing. There are lots of good templates for this available on GitHub/Packagist, etc.
IPN will POST transaction data to a listener script you have setup on your server any time a transaction happens on your PayPal account. This would be for payments, refunds, disputes, cleared e-checks, etc. You can automate all sorts of tasks based on the different txn_type's that IPN sends you.

paypal recurring payment pending status?

I have been searching and reading up about this issue for hours now and I do not have a clue why no one has an answer to this apart from changing the provider etc which is not wanted.
I also found this Paypal Sandbox recurring payment with initial amount pending
which is the exact same issue that i have right now and there seems to be someone called "PayPal_Patrick " who replied to that question but they've removed all their comments for some reason!
any way, I am just trying to figure out why the first initial paypal recurring payment shows as pending!
I get the IPN response and my IPN enters the data into mysql database as it should but the payment status shows as pending!
when I look into the paypal sandbox account, I see the payment status as pending too. so there must be something that stops the paypal to create the recurring profile immediately!
here is my simple form that will allow the user to create a recurring payment:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="mysandboxemail#gmail.com">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="cbt" value="Return to The Store">
<input type="hidden" name="cancel_return" value=" <?php echo $actual_link ?>">
<input type="hidden" name="custom" value="This is a custom field!!!">
<input type="hidden" name="item_name" value="ACCOUNT UPGRADE">
<input type="hidden" name="a3" value="5.00">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
could someone please help me out with this issue?
Thanks
Here it is for future reference:...
All you have to do is to change the settings of your Paypal account so it accepts payment from all currencies.

unable to get paypal post pramenters in the return url

I have one code for passing some custom variables to PayPal and these were collected in the return page, but when trying to get these values it is not working
I have a PayPal form like this :
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="submit.png" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
<input type="hidden" name="add" value="1"/>
<input type="hidden" name="custom" value="IP"/>
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="business" value=""/>
<input type="hidden" name="item_name" value=""/>
<input type="hidden" name="item_number" value=""/>
<input type="hidden" name="amount" value=""/>
<input type="hidden" name="page_style" value=""/>
<input type="hidden" name="no_shipping" value="1"/>
<input type="hidden" name="return" value="index.php?action=success"/>
<input type="hidden" name="notify_url" value="index.php?action=ipn"/>
<input type="hidden" name="cancel_return" value=""/>
<input type="hidden" name="rm" value="2"/>
<input type="hidden" name="cn" value="Additional Information"/>
<input type="hidden" name="currency_code" value="AUD"/>
<input type="hidden" name="bn" value="PP-ShopCartBF"/>
</form>
I am successfully returning to the URL after payment. and there I am just trying to print the POST Variable for now and It is not giving me any values.I have tried by both enabling and disabling 'auto return'. In both case I don't get values. Please help me, thanks in advance.
The "notify_url" will be contacted by paypal asynchronously (directly), without you having anything to do with this transaction. So you will never see in your browser any results whatsoever. You should use some kind of logging in your script to see what is actually being sent. Check your web server's access log to see if paypal is actually contacting your script (and make sure it's not "localhost" you're trying from)
If I remember correctly only the transaction id is sent back to the return_url. The notify_url receives that id also. From there you should be able to communicate both pages to fill your needs.

Categories