开发者

PayPal Payment Callback

开发者 https://www.devze.com 2023-01-22 07:05 出处:网络
I have searched for more than 4 hours now on how to do callback with PayPal after a payment have been proceeded.

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_开发者_Go百科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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号