function onTP_Processpayment($data, $vars)
 {
     $isValid = true;
     $error = array();
     $error['code'] = '';
     $error['desc'] = '';
     $plgPaymentpaypalproHelper = new plgPaymentpaypalproHelper();
     $action_url = $plgPaymentpaypalproHelper->buildpaypalproUrl();
     if ($data['recurring_frequency'] == 'QUARTERLY') {
         $BILLINGFREQUENCY = 3;
         $BILLINGPERIOD = 'MONTH';
     } else {
         $BILLINGFREQUENCY = $data['recurring_count'];
         $BILLINGPERIOD = ucfirst(strtolower($data['recurring_frequency']));
     }
     $exp_month = str_pad($data['expire_month'], 2, "0", STR_PAD_LEFT);
     $data['cardexp'] = $exp_month . $data['expire_year'];
     if ($data['is_recurring']) {
         $pro_values = array("METHOD" => 'CreateRecurringPaymentsProfile', "AMT" => $data['chargetotal'], "CREDITCARDTYPE" => $data['credit_card_type'], "ACCT" => $data['cardnum'], "CVV2" => $data['cardcsc'], "EXPDATE" => $data['cardexp'], "COUNTRYCODE" => $data['cardcountry'], "PROFILESTARTDATE" => gmdate("Y-m-d\\TH:i:s\\Z"), "BILLINGFREQUENCY" => $BILLINGFREQUENCY, "BILLINGPERIOD" => $BILLINGPERIOD, "DESC" => "recurring billing", "VERSION" => "65.0", "VERSION" => "104.0", "USER" => $this->params->get('pro_api_username'), "PWD" => $this->params->get('pro_api_password'), "SIGNATURE" => $this->params->get('pro_api_signature'));
     } else {
         $pro_values = array("METHOD" => 'DoDirectPayment', "VERSION" => "65.0", "USER" => $this->params->get('pro_api_username'), "PWD" => $this->params->get('pro_api_password'), "SIGNATURE" => $this->params->get('pro_api_signature'), "PAYMENTACTION" => "Sale", "IPADDRESS" => $_SERVER['REMOTE_ADDR'], "AMT" => $data['chargetotal'], "CREDITCARDTYPE" => $data['credit_card_type'], "ACCT" => $data['cardnum'], "EXPDATE" => $data['cardexp'], "CVV2" => $data['cardcsc'], "FIRSTNAME" => $data['cardfname'], "LASTNAME" => $data['cardlname'], "STREET" => $data['cardaddress1'], "CITY" => $data['cardcity'], "STATE" => $data['cardstate'], "ZIP" => $data['cardzip'], "COUNTRYCODE" => $data['cardcountry'], "INVNUM" => $data['order_id']);
     }
     $fields = "";
     foreach ($pro_values as $key => $value) {
         $fields .= "{$key}=" . urlencode($value) . "&";
     }
     //call to curl
     $ch = curl_init($action_url);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& "));
     $resp = curl_exec($ch);
     //execute post and get results
     curl_close($ch);
     //call to curl
     $allresp = explode('&', $resp);
     foreach ($allresp as $r) {
         $res = explode('=', $r);
         $final_res[$res[0]] = urldecode($res[1]);
     }
     JFactory::getApplication()->enqueueMessage('ACK Response : ' . $final_res['ACK']);
     if ($final_res['ACK'] == 'Success') {
         JFactory::getApplication()->enqueueMessage('Recurring payments profile created Successfully.');
     } else {
         JFactory::getApplication()->enqueueMessage('Unable to create Recurring Payments Profile');
     }
     $error['code'] .= $final_res['L_ERRORCODE0'];
     $error['desc'] .= $final_res['L_LONGMESSAGE0'];
     //3.compare response order id and send order id in notify URL
     $res_orderid = '';
     $res_orderid = $data['order_id'];
     if ($isValid) {
         if (!empty($vars) && $res_orderid != $vars->order_id) {
             $trxnstatus = 'ERROR';
             $isValid = false;
             $error['desc'] .= "ORDER_MISMATCH " . " Invalid ORDERID; notify order_is " . $vars->order_id . ", and response " . $res_orderid;
         }
     }
     // amount check
     if ($isValid) {
         if (!empty($vars)) {
             // Check that the amount is correct
             $order_amount = (double) $vars->amount;
             $retrunamount = (double) $final_res['AMT'];
             $epsilon = 0.01;
             if ($order_amount - $retrunamount > $epsilon) {
                 $trxnstatus = 'ERROR';
                 // change response status to ERROR FOR AMOUNT ONLY
                 $isValid = false;
                 $error['desc'] .= "ORDER_AMOUNT_MISTMATCH - order amount= " . $order_amount . ' response order amount = ' . $retrunamount;
             }
         }
     }
     // translate response
     if (!empty($trxnstatus)) {
         $payment_status = $this->translateResponse($trxnstatus);
     } else {
         $payment_status = $this->translateResponse($final_res['ACK']);
     }
     $transaction_id = $final_res['TRANSACTIONID'];
     $result = array('transaction_id' => $transaction_id, 'order_id' => $data['order_id'], 'status' => $payment_status, 'total_paid_amt' => $final_res['AMT'], 'raw_data' => $resp, 'error' => $error, 'return' => $data['return']);
     return $result;
 }
 function onTP_Processpayment($data)
 {
     $error = array();
     $action_url = plgPaymentpaypalproHelper::buildpaypalproUrl();
     $exp_month = str_pad($data['expire_month'], 2, "0", STR_PAD_LEFT);
     $data['cardexp'] = $exp_month . $data['expire_year'];
     //print_r($data);die;
     $pro_values = array("METHOD" => 'DoDirectPayment', "VERSION" => "65.0", "USER" => $this->params->get('pro_api_username'), "PWD" => $this->params->get('pro_api_password'), "SIGNATURE" => $this->params->get('pro_api_signature'), "PAYMENTACTION" => "Sale", "IPADDRESS" => $_SERVER['REMOTE_ADDR'], "AMT" => $data['chargetotal'], "CREDITCARDTYPE" => $data['credit_card_type'], "ACCT" => $data['cardnum'], "EXPDATE" => $data['cardexp'], "CVV2" => $data['cardcsc'], "FIRSTNAME" => $data['cardfname'], "LASTNAME" => $data['cardlname'], "STREET" => $data['cardaddress1'], "CITY" => $data['cardcity'], "STATE" => $data['cardstate'], "ZIP" => $data['cardzip'], "COUNTRYCODE" => $data['cardcountry'], "INVNUM" => $data['order_id']);
     $fields = "";
     foreach ($pro_values as $key => $value) {
         $fields .= "{$key}=" . urlencode($value) . "&";
     }
     //call to curl
     $ch = curl_init($action_url);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& "));
     //echo $ch;die;
     $resp = curl_exec($ch);
     //execute post and get results
     curl_close($ch);
     //call to curl
     $allresp = explode('&', $resp);
     foreach ($allresp as $r) {
         $res = explode('=', $r);
         $final_res[$res[0]] = urldecode($res[1]);
     }
     $payment_status = $this->translateResponse($final_res['ACK']);
     $error['code'] = $final_res['L_ERRORCODE0'];
     $error['desc'] = $final_res['L_LONGMESSAGE0'];
     $transaction_id = $final_res['TRANSACTIONID'];
     $result = array('transaction_id' => $transaction_id, 'order_id' => $data['order_id'], 'status' => $payment_status, 'total_paid_amt' => $final_res['AMT'], 'raw_data' => $resp, 'error' => $error, 'return' => $data['return']);
     return $result;
 }