So, I am doing a site selling membership plan. User clicks on the plan, system will display a registration form. Inside the form, I need to get user's IC No. (which is a legal identification card number as in the country I'm working in), and a password created by user. Then,user clicks "subscribe" button. The user will be directed to paypal processing 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'];?>">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="D">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="business" value="seller@test.com">
<input type="hidden" name="return" value="<?php echo base_url(); ?>">
<input type="hidden" name="notify_url" value="<?php echo base_url(); ?>payment/subscribe" />
<input type="hidden" name="rm" value="2">
<label for='icno'>IC No</label><input type='text' name='icno'/>
<label for='password'>Password</label><input type='password' name='password'/>
<input type='image' src="<?php echo base_url(); ?>assets/images/sign_up_btn.png" alt="" border="0" />
</form>
I'm using codeigniter framework if it matters. On my return page which is my home page, I code this:
<?php
$posted_data = print_r($_POST,true);
file_put_contents('posted_data.txt',$posted_data);
?>
while my controller for notify_url (payment/subscribe):
public function subscribe() {
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "
";
$fp = fsockopen ('ssl://sandbox.www.paypal.com', 443, $errno, $errstr, 30);
$payer_email = $_POST['payer_email'];
$icno = mysql_real_escape_string($_POST["custom"]);
$txn_type = $_POST['txn_type'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
$s = "insert into test(name) values('$icno')";
$result = mysql_query($s);
}
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
So, the purchasing process goes well. The problem is, then the user click return button to our site, it won't update the DB (insert into test(name) values('$icno')). What did I do wrong?
Btw, after the user return to main site, a .txt file is created, but only store this info
Array
(
[txn_type] => subscr_signup
[subscr_id] => I-8AEF8X938J
[last_name] => last_name_here ,
[residence_country] => US
[mc_currency] => USD
[item_name] => Silver Membership
[business] => seller@test.com
[amount3] => 70.00
[recurring] => 1
[address_street] => 1 Main St
[payer_status] => verified
[payer_email] => buyer@test.com
[address_status] => confirmed
[first_name] => first_name_here
[receiver_email] => seller@test.com
[address_country_code] => US
[payer_id] => MYRA3LAP4FGLG
[address_city] => San Jose
[reattempt] => 1
[item_number] => 3
[address_state] => CA
[subscr_date] => 22:30:49 Feb 17, 2014 PST
[address_zip] => 95131
[custom] => q123
[charset] => windows-1252
[period3] => 1 D
[address_country] => United States
[mc_amount3] => 70.00
[address_name] => address_name_here ,
[auth] => ABb4M0wVhKnTyPm1zMMDyJTKE4-EhqEET7e.DwmfWEGfNLfMkcAZ6i047iela23om-6bq4LnY4mZEUy4GUiC3Lg
[form_charset] => UTF-8
)
In case you ask why I don't try IPN; I just start to learn how paypal integration, therefore I better learn how to do both.
I tried to change:
if (strcmp ($res, "VERIFIED") == 0) {
$s = "insert into test(name) values('$icno')";
$result = mysql_query($s);
}
to
if (strcmp ($res, "txn_type") == "subscr_signup") {
$s = "insert into test(name) values('$user_id')";
$result = mysql_query($s);
}
it still won't update the DB