Reputation: 309
Well I have a website for which I have a Paypal business account (registered in UK). The paypal is integrated with my website and is working just fine. When user clicks on the "Proceed To Pay" the user is taken to Paypal's website (screenshot below). Now the only problem I have with this procedure is the fact that customers HAVE to make a Paypal account first in order to pay me. I am baffled with all the options Paypal is offering (standard, pro, merchant, what not) and I am not sure what is it exactly that I am doing wrong.
Screenshot http://ascensionnexus.com/Capture.jpg
Please advice and explain if I need to change something in my code to let the customer pay using their Credit Card directly(on Paypal's website) rather than asking them to open Paypal account first.
EDIT
The HTML form that is on my confirmorder page is as follow.
<form class="paypal" action="payments.php" method="post" id="paypal_form" target="_parent">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="lc" value="US" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
<input type="hidden" name="amount" value="<?php echo $productunit_price * 1.05;?>" />
<input type="hidden" name="quantity" value="<?php echo $product_quantity;?>" />
<input type="hidden" name="first_name" value="<?php echo $customer_first_name;?>" />
<input type="hidden" name="last_name" value="<?php echo $customer_last_name;?>" />
<input type="hidden" name="notify_url" value="http://mywebsite.com/payments.php" />
<input type="hidden" name="payer_email" value="<?php echo $customer_email;?>" />
<input type="hidden" name="item_name" value="<?php echo $service_name;?> (<?php echo $product_name;?>)" / >
<input type="hidden" name="custom" value="<?php echo $orderalias.",".$_SESSION["user_id"];?>" / >
<input type="image" value="Submit Payment" src="imgs/proceed_btn.jpg"/>
</form>
The php code in payments.php is as follows:
<?php
// PayPal settings
$paypal_email = '[email protected]';
$return_url = 'http://mywebsite.com/thankyou.php?payment=1';
$cancel_url = 'http://mywebsite.com/orders.php';
$notify_url = 'http://mywebsite.com/payments.php';
if (!isset($_POST["txn_id"]) && !isset($_POST["txn_type"])){
// Firstly Append paypal account to querystring
$querystring .= "?business=".urlencode($paypal_email)."&";
//loop for posted values and append to querystring
foreach($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$querystring .= "$key=$value&";
}
// Append paypal return addresses
$querystring .= "return=".urlencode(stripslashes($return_url))."&";
$querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
$querystring .= "notify_url=".urlencode($notify_url);
// Redirect to paypal IPN
header('location:https://www.paypal.com/cgi-bin/webscr'.$querystring);
exit();
}else{
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
$req .= "&$key=$value";
}
// assign posted variables to local variables
$data['item_name'] = $_POST['item_name'];
$data['item_number'] = $_POST['item_number'];
$data['payment_status'] = $_POST['payment_status'];
$data['payment_amount'] = $_POST['mc_gross'] * 0.95;
$data['payment_currency'] = $_POST['mc_currency'];
$data['txn_id'] = $_POST['txn_id'];
$data['receiver_email'] = $_POST['receiver_email'];
$data['payer_email'] = $_POST['payer_email'];
$data['custom'] = $_POST['custom'];
$separatedata = explode(",",$data["custom"]);
$orderalias = $separatedata[0];
$user = $separatedata[1];
if($data['payment_status']=="Completed" ){
// do my stuff here
}else{
// do my stuff here
}
}
?>
Upvotes: 0
Views: 838
Reputation: 94
enable paypal pro business and use DoDirectPayment API. Below is simple DoDirectPayment code.
$infos = array(
'METHOD' => 'DoDirectPayment',
'USER' => $paypal_pros_username,
'PWD' => $paypal_pros_password,
'SIGNATURE' => $paypal_pros_signature,
'VERSION' => urlencode('115'),
'PAYMENTACTION' => $_POST['paypal_pros_transaction_type'],
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'CREDITCARDTYPE' => $_POST['creditCardType'],
'ACCT' => $_POST['creditCardNumber'],
'EXPDATE' => $_POST['expDateMonth'].$_POST['expDateYear'],
'CVV2' => $_POST['cvv2Number'],
//'EMAIL' => $_POST['email'],
'FIRSTNAME' => $_POST['firstName'],
'LASTNAME' => $_POST['lastName'],
'STREET' => $_POST['address1'],
'CITY' => $_POST['city'],
'STATE' => $_POST['state'],
'ZIP' => $_POST['zip'],
'COUNTRYCODE' => $_POST['country'],
'AMT' => $_POST['amount'],
'CURRENCYCODE' => $_POST['PayPal_pros_curency'],
'DESC' => $_POST['paypal_pro_desc'],
'NOTIFYURL' => 'https://website.com/ipn.php'
);
// Loop through $infos array to generate the NVP string.
$nvp_string = '';
foreach($infos as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
// Send NVP string to PayPal and store response
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $strPurchaseURL);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// Get response from the server.
$result = curl_exec($ch);
// Parse the API response
parse_str($result, $output);
if(array_key_exists('ACK', $output)){
print_r($output);
if($output['ACK']=="Success"){
//Success email
}
elseif($output['ACK']=="Failure"){
}
else {
echo 'There is any error! Please go back and try again.';
}
}
else {
echo 'There is any error! Please go back and try again.';
}
Upvotes: 0
Reputation: 1
Here’s how to turn on PayPal Account Optional:
Go to http://www.paypal.com/ and log in to your account.
Click Profile near the top of the page. Click My selling tools. Under Selling Online, click Update near "Website preferences." Select On under "PayPal Account Optional" near the bottom of the page. Click Save. Here’s how to turn off PayPal Account Optional:
Go to http://www.paypal.com/ and log in to your account. Click Profile near the top of the page. Click My selling tools. Click Update near "Website preferences." Select Off under "PayPal Account Optional" near the bottom of the page. Click Save
Upvotes: 0