thiwankalk
unread,Aug 6, 2009, 10:53:15 AM8/6/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Sri Lanka Web Development
/*
define's
app_paypal_apiusername;
app_paypal_apipassword;
app_paypal_apisignature;
app_paypal_apiendpoint;
app_paypal_version;
*/
class Paypal_Payment {
private $API_UserName=app_paypal_apiusername;
private $API_Password=app_paypal_apipassword;
private $API_Signature=app_paypal_apisignature;
private $API_Endpoint =app_paypal_apiendpoint;
private $version=app_paypal_version;
public function doTrasaction($data) {
$methodName = "doDirectPayment";
$paymentType =urlencode($data['paymenttype']);
$firstName =urlencode($data['firstname']);
$lastName =urlencode($data['lastname']);
$creditCardType =urlencode($data['creditcardtype']);
$creditCardNumber = urlencode($data['crdnumber']);
$expDateMonth =urlencode($data['month']);
// Month must be padded with leading zero
$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
$expDateYear =urlencode( $data['year']);
$cvv2Number = urlencode($data['cvc']);
$address = urlencode($data['address']);
//$address2 = urlencode($data['address2']);
$country = urldecode($data['country']);
$city = urlencode($data['city']);
$state =urlencode( $data['state']);
$zip = urlencode($data['zipcode']);
$amount = urlencode($data['amount']);
$currencyCode="USD";
$paymentType=urlencode($data['paymenttype']);
$nvpstr="&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=
$creditCardType&ACCT=$creditCardNumber&EXPDATE=".$padDateMonth.
$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=
$lastName&STREET=$address&CITY=$city&STATE=$state"."&ZIP=
$zip&COUNTRYCODE=US&CURRENCYCODE=$currencyCode";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
if(app_paypal_useproxy)
curl_setopt ($ch, CURLOPT_PROXY,
app_paypal_proxyhost.":".app_paypal_proxyport);
$nvpreq="METHOD=".urlencode($methodName)."&VERSION=".urlencode
($this->version)."&PWD=".urlencode($this-
>API_Password)."&USER=".urlencode($this-
>API_UserName)."&SIGNATURE=".urlencode($this->API_Signature).$nvpstr;
curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
$response = curl_exec($ch);
$nvpResArray=$this->deformatNVP($response);
$nvpReqArray=$this->deformatNVP($nvpreq);
if (curl_errno($ch)) {
return FALSE;
} else {
curl_close($ch);
}
return $nvpResArray;
}
private function deformatNVP($nvpstr){
$intial=0;
$nvpArray = array();
while(strlen($nvpstr)){
$keypos= strpos($nvpstr,'=');
$valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen
($nvpstr);
$keyval=substr($nvpstr,$intial,$keypos);
$valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
$nvpArray[urldecode($keyval)] =urldecode($valval);
$nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
}
return $nvpArray;
}
}
$payment = new Paypal_Payment();
$status = $payment->doTrasaction($data);
if($status['ACK']=='Failure') {
echo 'fail';
} else {
echo 'pass';
}