Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal Payment Callback

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?

like image 547
Endre Hovde Avatar asked Oct 27 '10 00:10

Endre Hovde


People also ask

How do you call back a PayPal transaction?

There's no button for refund requests on PayPal. However, sellers can manually issue a refund up to 180 days after a transaction. If you haven't, contact the seller and ask for a refund. If they're not sure how to issue one, all they have to do is look up the transaction in their records.

What is an API for PayPal?

The PayPal REST API is organized around transaction workflows, including: orders, payments, subscriptions, invoicing, and disputes. Try out our REST APIs with test credentials on Postman. The API uses standard verbs and returns HTTP response codes and JSON-encoded responses.

Is the PayPal API free?

jackezt / Paypal-Payment-Get-Api Paypal Server is a self-hosted, open-source Paypal payment processor. It's secure, private, censorship-resistant and free.

Is PayPal using node JS?

Node. js helps us solve this by enabling both the browser and server applications to be written in JavaScript. It unifies our engineering specialties into one team which allows us to understand and react to our users' needs at any level in the technology stack.


1 Answers

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.

like image 171
Jhourlad Estrella Avatar answered Sep 18 '22 20:09

Jhourlad Estrella