I have built an application, that sends a notification url with the GUID of the logged in user to PayPal, and upon completion of purchase, the url is called, and after verification, the user database entry updates the column purchased from 0 to 1.
The user then clicks the return to app button, and the premium functionality displays based on the purchased column.
I have been testing this over the last few months in the sandbox. 100% of the times tested (including after this issue), the premium tab displays after purchase completion.
Client is thrilled, and gives the go ahead to move to production. I have set up IPN with the exact same URL, I have changed literally nothing except switching from www.sandbox.paypal.com to www.paypal.com and changing the account listed from the sandbox business to the personal business.
Ths issue is, the button now doesn't show up, until, you refresh the screen. Clicking the "return to app" button, which previously was working as expected, now doesn't display the premium tab. Once I click refresh - it then shows up. If I switch everything back to the sandbox settings, boom - it works just fine again.
Here is the BuyNow button code with production account:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="buynowForm" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="ACCOUNT EMAIL">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Product">
<input type="hidden" name="amount" value="10.00">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type='hidden' name='notify_url' value='http://app.com/purchase/<?php echo $data[0]['uid'] ?>'>
<input type='hidden' name='return' value='http://app.com/'>
<input type="hidden" name="rm" value="1">
<input type="hidden" name="cbt" value="Return to Product Plus">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="submit" class="hidden-print visible-print" border="0" name="buysubmit" value="Click For Product Plus" alt="Click for Product Plus">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
And here is the processing route called above:
$app->post('/purchase/:uid', function ($uid) use ($app) {
$request = Slim::getInstance()->request();
$inputs = json_decode($request->getBody());
$db_conn = conn();
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
if (get_magic_quotes_gpc())
{
$_POST[$key] = stripslashes($value);
$value = stripslashes($value);
}
$value = urlencode($value);
$req .= "&$key=$value";
}
$url = "https://www.paypal.com/cgi-bin/webscr";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
$result = curl_exec($ch);
curl_close($ch);
if (strcmp ($result, "VERIFIED") == 0)
{
$sql_st = 'UPDATE `user_data` SET `purchased` = 1 WHERE uid=:uid';
$sql = $db_conn->prepare($sql_st);
if ($sql->execute(array('uid'=>$uid))) {
$data = array('status' => "Ok");
} else {
$data = array('status' => print_r(mysql_error()));
}
}
else
{
// Did Not Process IPN Properly
}
});
REALLY hoping this is just something incredibly dumb on my part. Any help/guidance is appreciated.
Essentially the solution here is one of two options -
Build a secondary method of completion - in other words, the IPN is not the first line of defense for a purchased upgrade to software. Everything on my end is working, however the timing of the IPN (notify_url) call is too slow to make instant upgrades not exactly instant. Return them to a page that performs the upgrade then redirects.
Store the upgraded features behind a different route - this was PayPal's suggestion. Essentially, have app.com/basic and app.com/upgraded. This isn't really ideal, nor would I suggest it as a permanent solution.
Summed up - this is a known issue with PayPal. The sandbox and production workflows are basically different - not by function or API, but in usage - the production level account is getting hit more, and the time it takes to process the notifications are much slower.
Hope this helps someone.
Related
I work on a website based on Symfony 3 and PayPal API.
I tried to use IPN outside Symfony and it worked well.
Now I try to implements this into my controller and nothing happens.
This code comes from the Paypal's Github.
public function paypalAction(Request $request){
// STEP 1: Read POST data
// reading posted data from directly from $_POST causes serialization
// issues with array data in POST
// reading raw POST data from input stream instead.
$raw_post_data = $request->getContent();
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
// STEP 2: Post IPN data back to paypal to validate
$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
// In wamp like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
// of the certificate as shown below.
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);
// STEP 3: Inspect IPN validation result and act accordingly
if (strcmp ($res, "VERIFIED") == 0) {
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$cart_item = $_POST['num_cart_items'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
// <---- HERE you can do your INSERT to the database
return new Response("Paypal worked !");
} else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
return new Response("Paypal didn't worked !");
}
}
Sorry but I am not yet able to post as a comment which I feel this should really be. Few things I wanted to mention, first please check your logs (symfony3: /{project}/var/log/dev.log (or prod.log in prod) and let us know anything related to your requests.
Second, are the IPNs being sent and where to? Something people overlook is that they will run a symfony project locally and forget that paypal can't send it's ipn to your local host... If you want to do this you should use something like ngrok to tunnel your localhost and then have it sent to the tunnel address which is exposing your localhost
Third, I have just finished a project which integrated paypal and the Orderly IPN Bundle was a mega time saver. https://github.com/orderly/symfony2-paypal-ipn
Sure receiving and logging the IPN is easy, but Orderly will do a lot more than that - what we should be doing but didn't think about - and it's very easy to integrate. Although, please note Orderly IPN is no longer maintained so if you choose to take this option you may want to refer to these pull requests
https://github.com/orderly/symfony2-paypal-ipn/pull/38/files
https://github.com/orderly/symfony2-paypal-ipn/pull/42/files (although maybe don't just set 255 to everyone and use some initiative)
Hope this helps in some way.
Oh, PS. Something I ran into which you may - PayPal by default was sending its IPNs as windows-1252 but my database was in UTF-8. Took me a while to catch on to this because no issues were causes until someone with ü in their name made an order. To change this https://simple-membership-plugin.com/setting-utf-8-formatting-for-your-paypal-ipn-messages/
edit: in symfony you should also be passing Request $request into paypalAction instead of using $_GET or $_POST although they will work.
You cannot use file_get_contents('php://input'); because the Request object used it before.
use Symfony\Component\HttpFoundation\Request;
...
public function paypalAction(Request $request)
{
$raw_post_data = $request->getContent();
...
}
Well, I went further into this and I noticed that the problem comes from the PayPal buttons/forms that I use.
Here's the code of a "Buy Now" button which works perfectly with IPN and my controller :
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type='hidden' value="5" name="amount" />
<input name="currency_code" type="hidden" value="EUR" />
<input name="shipping" type="hidden" value="0.00" />
<input name="tax" type="hidden" value="0.00" />
<input name="return" type="hidden" value="http://www.YOURDOMAIN.com/valid/paiement" />
<input name="cancel_return" type="hidden" value="http://www.YOURDOMAIN.com/cancel/paiement" />
<input name="notify_url" type="hidden" value="http://www.YOURDOMAIN.com/validation/paiement" />
<input name="cmd" type="hidden" value="_xclick" />
<input name="business" type="hidden" value="YOURMAIL#YOURDOMAIN.com" />
<input name="item_name" type="hidden" value="A kind of book" />
<input name="no_note" type="hidden" value="1" />
<input name="lc" type="hidden" value="FR" />
<input name="bn" type="hidden" value="PP-BuyNowBF" />
<input name="custom" type="hidden" value="4" />
<input alt="Effectuez vos paiements via PayPal : une solution rapide, gratuite et sécurisée" name="submit" src="https://www.paypal.com/fr_FR/FR/i/btn/btn_buynow_LG.gif" type="image" /><img src="https://www.paypal.com/fr_FR/i/scr/pixel.gif" border="0" alt="" width="1" height="1" />
</form>
And this is a "Add to cart" button which doesn't work and gives me no callback from PayPal IPN. I get an empty response.
<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="YOURID">
<input name="return" type="hidden" value="http://www.YOURDOMAIN.com/valid/paiement" />
<input name="cancel_return" type="hidden" value="http://www.YOURDOMAIN.com/cancel/paiement" />
<input name="notify_url" type="hidden" value="http://www.YOURDOMAIN.com/validation/paiement" />
<input type="image" src="https://www.sandbox.paypal.com/fr_FR/FR/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal, le réflexe sécurité pour payer en ligne">
<img alt="" border="0" src="https://www.sandbox.paypal.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
</form>
I don't understand why the IPN works differently depending of the buttons I use.
Note : In any of these cases, the IPN Simulator works perfectly.
I have a question regarding php button. I want to make a dynamic buy now button with paypal. A button that i can pass my custom variables into. The only way i know how to that is through a paypal form.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="paid#yourdomain.com">
<input type="hidden" name="item_name" value="my product">
<input type="hidden" name="item_number" value="12345">
<input type="hidden" name="amount" value="9.99">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
But the above form's amount value can easily be tampered with. So instead of this i want to have just a button in html, and have everything process through a php file. When a user clicked the button, the process of price calculation will happen in the php file, and then redirect the user to paypal, where they can pay for the item. This way the price can't be tampered with. Can someone tell me if it's possible to do it that way? or i have to dynamically encrypt the button using openssl? or there's another way?
Instead of posting directly to PayPal, you can collect all the data server side, and use cURL to post the data to PayPal. The form would look more like:
<form action="confirm.php" method="post">
<input type="hidden" name="business" value="paid#yourdomain.com">
<input type="hidden" name="item_number" value="12345">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Then confirm.php would do a handful of things. Lookup the price, calculate the total, etc.
<?php
$bizName = isset($_POST['business']):$_POST['business']:"";
$itemNumber = isset($_POST['item_number'])?intval($_POST['item_number']):"";
// Lookup details for the Item, purchase, and collect them into an array maybe
$itemDetails = array(
"cmd" => "_xclick",
"amount" => $itemPrice, // Get from DB
"no_note" => 1,
"currency_code" => "USD",
"bn" => "PP-BuyNowBF",
"business" => $bizName,
"item_name" => $itemName, // Get from DB
"item_number" => $itemNumber
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.paypal.com/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($itemDetails));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$svr_out = curl_exec ($ch);
curl_close ($ch);
// Do something with $svr_out, maybe display it, or if it's a redirect, redirect the user in turn.
?>
This is untested and is more of a template to get you started. I am sure your site is more complex and you could then build off of this. It is just an example of something you could do.
I'm stuck at the problem with paypal IPN and it is getting always invalid when i use paypal buy now button, however it works perfectly with IPN simulator.
I know there are many questions and answers at stackoverflow about this to help but i have tried lots of things from here and also from other sites, none of them worked.
Here is the button code i'm using,
<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="xxx-facilitator#gmail.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Teddy Bear">
<input type="hidden" name="amount" value="12.99">
<input type="hidden" name="notify_url" value="http://mysite/ipn">
<input type="hidden" name="custom" value="2">
<input type="hidden" name="return" value="http://mysite/success">
<input type="hidden" name="cancel_return" value="http://mysite/cancel">
<input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
And here is the IPN Listener Code,
<?php
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$postFields = 'cmd=_notify-validate';
foreach($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$postFields .= "&$key=".$value;
}
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postFields
));
$result = curl_exec($ch);
curl_close($ch);
if($result == "VERIFIED"){
$handle = fopen('ipn.txt','w');
fwrite($handle,$result.'----'.$postFields);
fclose($handle);
}else{
$handle = fopen('ipn.txt','w');
fwrite($handle,$result.'----'.$postFields);
fclose($handle);
}
And here is the response i saved into ipn.txt from simulator,
VERIFIED----cmd=_notify-validate&residence_country=US&invoice=abc1234&address_city=San+Jose&first_name=John&payer_id=TESTBUYERID01&shipping=3.04&mc_fee=0.44&txn_id=332239535&receiver_email=seller%40paypalsandbox.com&quantity=1&custom=xyz123&payment_date=17%3A48%3A59+9+Feb+2015+PST&address_country_code=US&address_zip=95131&tax=2.02&item_name=something&address_name=John+Smith&last_name=Smith&receiver_id=seller%40paypalsandbox.com&item_number=AK-1234&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31Aryx.id7DMD.5oDzhJYQOgjfGK2z&address_country=United+States&payment_status=Completed&address_status=confirmed&business=seller%40paypalsandbox.com&payer_email=buyer%40paypalsandbox.com¬ify_version=2.1&txn_type=web_accept&test_ipn=1&payer_status=verified&mc_currency=USD&mc_gross=12.34&address_state=CA&mc_gross1=9.34&payment_type=instant&address_street=123%2C+any+street
And finally this response text by pressing button and after making payment through paypal sandbox account.
INVALID----cmd=_notify-validate&mc_gross=12.99&protection_eligibility=Eligible&address_status=unconfirmed&payer_id=K95EGBDGNUN8S&tax=0.00&address_street=Flat+no.+507+Wing+A+Raheja+Residency%0AFilm+City+Road%2C+Goregaon+East&payment_date=17%3A53%3A25+Feb+09%2C+2015+PST&payment_status=Completed&charset=UTF-8&address_zip=400097&first_name=Test&mc_fee=0.81&address_country_code=IN&address_name=Test+Buyer¬ify_version=3.8&custom=46&payer_status=verified&business=xxx-facilitator%40gmail.com&address_country=India&address_city=Mumbai&quantity=1&verify_sign=AlLjZyUxzvtq5pK4-AOSkTM98NV-AIiAPCkBL.N4R.UZINnl-aty.OZT&payer_email=xxx-buyer%40gmail.com&txn_id=4LG750650N267953C&payment_type=instant&last_name=Buyer&address_state=Maharashtra&receiver_email=xxx-facilitator%40gmail.com&payment_fee=0.81&receiver_id=HYW9VPL8HWUYA&txn_type=web_accept&item_name=Teddy+Bear&mc_currency=USD&item_number=&residence_country=IN&test_ipn=1&handling_amount=0.00&transaction_subject=46&payment_gross=12.99&shipping=0.00&ipn_track_id=a7a2c1d3e08a2
What I have done so far,
Made sure that i'm only working with sandbox and not with live things with paypal
Changed charset of both accounts (buyer and seller at sandbox)
Changed listener code multiple times, but got same result
searched stackoverflow and other sites with google with no luck.
already have looked these ones,
Paypal SandBox IPN always returns INVALID
PayPal IPN returning INVALID
I'm pretty sure it was just problem with order of post data.
Used code from https://github.com/orderly/codeigniter-paypal-ipn and it works like charm!
Hope this answer will help someone and will save time.
So I'm doing a site selling membership plan (monthly billing)
User will need to input a registration form (name, ICNumber, etc which may be different to the paypal used by this user)
Upon clicking 'next/submit', system will save the posted data inside a session, and will display it again in another page so it's like a confirmation page.
Inside the confirmation page,
<form method='post' action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_ext-enter">
<input type="hidden" name="redirect_cmd" value="_xclick-subscriptions">
<input type="hidden" name="item_number" value="<?php echo $plan[0]['id'];?>">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="item_name" value="<?php echo $plan[0]['plan_name'];?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="<?php echo $plan[0]['plan_price'];?>">
<!--change p3 value 1M=1month, 1D(t3) = 1 day-->
<input type="hidden" name="p3" value="1">
<!--change value=M as month-->
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<!--here change to your seller sandbox account-->
<input type="hidden" name="business" value="seller-facilitator#test.com">
<input type="hidden" name="return" value="<?php echo base_url(); ?>signup/success">
<input type="hidden" name="notify_url" value="<?php echo base_url(); ?>payment/subscribe" />
<input type="hidden" name="rm" value="2">
<!--and echoing out bunch of data (name, ICNumber, phone number etc) posted from previous page,, which has been stored into a session array-->
So, user can do the payment, the money has come into the seller account, and buyer's balance has been deducted.
So my questions:
1. where should I put my ipn link? Is it inside 'notify_url' AND 'return' url?
2. If my understanding is correct, we 'should' put a link under our profile>selling preference>IPN so I have updated my profile, and put mydomain.com/controller/ipncode (I'm using codeigniter)
3. I turned on auto-return, but even on live, the site won't autoreturn. This is minor issue; my return page contains a simple 'thank you' page. Now, since the txn_type when the payment is made is "subscr_signup" therefore, NO txn_id, NO payment_status UNTIL the txn_type changes to 'subcr_payment', and this may occur long AFTER or BEFORE the user returns to our main site and surfing. So I need to save the registration data (as the user submitted) for his login. After payment, user can directly login, no matter what the payment outcome will be as the end, the seller and buyer will have to meet up for transaction (this is a rental dvd site, so buyer must go down to the retail shop and collect the dvds he books through the site).
But to make the life of the seller easier, it'd better if I can update the membership_status to 'active' IF the payment_status is verified and completed.
So far, my IPN code is this
$req = 'cmd=_notify-validate';
$fullipnA = array();
$url ='https://www.sandbox.paypal.com/cgi-bin/webscr';
foreach ($_POST as $key => $value)
{
$fullipnA[$key] = $value;
$encodedvalue = urlencode(stripslashes($value));
$req .= "&$key=$encodedvalue";
}
//$fullipn = Array2Str(" : ", "\n", $fullipnA);
$curl_result=$curl_err='';
$fp = curl_init();
curl_setopt($fp, CURLOPT_URL,$url);
curl_setopt($fp, CURLOPT_RETURNTRANSFER,1);
curl_setopt($fp, CURLOPT_POST, 1);
curl_setopt($fp, CURLOPT_POSTFIELDS, $req);
curl_setopt($fp, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($fp, CURLOPT_HEADER , 0);
curl_setopt($fp, CURLOPT_VERBOSE, 1);
curl_setopt($fp, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($fp, CURLOPT_TIMEOUT, 30);
$response = curl_exec($fp);
$curl_err = curl_error($fp);
curl_close($fp);
$custom=$this->session->userdata('registration'); //this contains the submitted registration data in a session array
$this->load->model('signup_model');
//'VERIFIED' only qualifies if the txn_type=subscr_payment(seller has received the money)
//if payment status is verified, then update DB/activate the account
if (strcmp ($response, "VERIFIED") == 0) {
if($_POST['payment_status']=='Completed') {
//this is to get customer_id based on the ICNumber posted upon registration (which is stored inside a session)
$cid=$this->signup_model->getCustomerID($custom['nric']);
//this is to update membership_status to active if payment is verified and completed
$this->signup_model->updatePlanStatus($cid[0]['id'],1);
$this->signup_model->test('payment status complete and verified', $cid);
} else {
$cid=$this->signup_model->getCustomerID($custom['nric']);
$this->signup_model->updatePlanStatus($cid[0]['id'],0);
$this->signup_model->test('payment status NOT complete but verified', $cid);
}
}
//'Invalid' if paypal can't process the payment
//update account status as pending
if (strcmp ($response, "INVALID") == 0) {
$cid=$this->signup_model->getCustomerID($custom['nric']);
$this->signup_model->updatePlanStatus($cid[0]['id'],0);
$this->signup_model->test('payment status NOT verified', $cid);
}
I'm also confused WHERE to put the sql syntax to insert the registration data into the DB.
Currently because I don't know how to use IPN properly, the return url (which is a thank you page), I put mysql db insert there. So, when user click 'return to main site', system will insert the registration details first, with membership_status = 0 (pending), this is to allow user to login directly to use the site.
Please guide me how should I put this all together.
Thanks!
I need to dinamically generate PayPal links with customized payment amounts and recipients. I don't know much about PayPal's way of handling this kind of stuff, and I actually wonder whether it is possible. I have a table with user's email address and payment value and, on the last column, I need to put that link that, clicked, takes to the PayPal's page where, after security checks and everything, the amount of money by me given can be directly transferred to the email address of the user.
Is it possible to do something like this? I'm working in PHP.
Thanks.
please, read documentation - it's all very well described. you will need to register at https://developer.paypal.com/; refer to https://www.paypal.com/documentation for more information.
I believe paypal standard payments would suffice your needs. read this https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_WebsitePaymentsStandard_IntegrationGuide.pdf -- it has all sorts of samples.
when we integrate paypal, we usually do like this: user picks goods to purchase, then proceeds to checkout. at this point, form is created as per documentation, and that form includes merchant account to use for processing the payment. in the form you also specify: notify_url and cancel_url, so you would get notification from the paypal as to what happened and to which account. that should address your needs.
sample form:
<form action="https://www.'.$this->isSandbox().'paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="business" value="'.$this->api->getConfig('billing/paypal/merchant').'">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="item_name" value="'.addslashes($_GET['descr']).'">
<input type="hidden" name="item_number" value="'.addslashes($_GET['id']).'">
<input type="hidden" name="amount" value="'.addslashes($_GET['amount']).'">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="notify_url" value="http://' . $_SERVER['HTTP_HOST'].$this->api->getDestinationURL('/ppproxy',array('ipn'=>$_GET['id'])).'">
<input type="hidden" name="cancel_return" value="http://' . $_SERVER['HTTP_HOST'].$this->api->getDestinationURL('/ppproxy',array('cancel'=>$_GET['id'])).'">
<input type="hidden" name="return" value="http://' . $_SERVER['HTTP_HOST'].$this->api->getDestinationURL('/ppproxy',array('success'=>$_GET['id'])).'">
<input type="hidden" name="currency_code" value="'.addslashes($_GET['currency']).'">
</form>
sample callback handler:
....
if($_POST){
// might be getting adta from paypal! better log!
foreach ($_POST as $key=>$value) $postdata.=$key."=".urlencode($value)."&";
$postdata.="cmd=_notify-validate";
$curl = curl_init("https://www.".$this->isSandbox()."paypal.com/cgi-bin/webscr");
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);
$response = curl_exec ($curl);
curl_close ($curl);
$this->api->logger->logLine($response);
if ($response != "VERIFIED"){
$this->api->logger->logLine('FAILED: post='.print_r($_POST,true));
exit;
}else{
$this->api->logger->logLine('VERIFIED: post='.print_r($_POST,true));
}
if($_POST['payment_status']=='Completed' and $_POST['txn_type']!='reversal')return true; // or perform your desired actions
exit;
}
excerpt from agiletoolkit.org paypal billing addon