/**
  * enqueue additional scripts if required by form
  * @param array $form
  * @param boolean $ajax
  */
 public function gformEnqueueScripts($form, $ajax)
 {
     if (GFEwayPlugin::hasFieldType($form['fields'], GFEWAY_FIELD_RECURRING)) {
         // enqueue script for field
         wp_enqueue_script('gfeway_recurring');
         // add datepicker style if Gravity Forms hasn't done so already -- since Gravity Forms v1.8.6
         if (version_compare(GFCommon::$version, '1.8.6', '>=') && !wp_style_is('gforms_datepicker_css', 'done')) {
             wp_enqueue_style('gforms_datepicker_css', GFCommon::get_base_url() . '/css/datepicker.css', null, GFCommon::$version);
             wp_print_styles(array('gforms_datepicker_css'));
         }
         // enqueue default styling
         wp_enqueue_style('gfeway');
     }
 }
 /**
  * load eWAY response data as XML string
  *
  * @param string $response eWAY response as a string (hopefully of XML data)
  */
 public function loadResponseXML($response)
 {
     GFEwayPlugin::log_debug(sprintf('%s: eWAY says "%s"', __METHOD__, $response));
     // make sure we actually got something from eWAY
     if (strlen($response) === 0) {
         throw new GFEwayException('eWAY payment request returned nothing; please check your card details');
     }
     // prevent XML injection attacks, and handle errors without warnings
     $oldDisableEntityLoader = libxml_disable_entity_loader(true);
     $oldUseInternalErrors = libxml_use_internal_errors(true);
     try {
         $xml = simplexml_load_string($response);
         if ($xml === false) {
             $errmsg = '';
             foreach (libxml_get_errors() as $error) {
                 $errmsg .= $error->message;
             }
             throw new Exception($errmsg);
         }
         $this->status = strcasecmp((string) $xml->ewayTrxnStatus, 'true') === 0;
         $this->transactionNumber = (string) $xml->ewayTrxnNumber;
         $this->transactionReference = (string) $xml->ewayTrxnReference;
         $this->option1 = (string) $xml->ewayTrxnOption1;
         $this->option2 = (string) $xml->ewayTrxnOption2;
         $this->option3 = (string) $xml->ewayTrxnOption3;
         $this->authCode = (string) $xml->ewayAuthCode;
         $this->error = (string) $xml->ewayTrxnError;
         $this->beagleScore = (string) $xml->ewayBeagleScore;
         // if we got an amount, convert it back into dollars.cents from just cents
         if (!empty($xml->ewayReturnAmount)) {
             $this->amount = floatval($xml->ewayReturnAmount) / 100.0;
         } else {
             $this->amount = null;
         }
         // restore old libxml settings
         libxml_disable_entity_loader($oldDisableEntityLoader);
         libxml_use_internal_errors($oldUseInternalErrors);
     } catch (Exception $e) {
         // restore old libxml settings
         libxml_disable_entity_loader($oldDisableEntityLoader);
         libxml_use_internal_errors($oldUseInternalErrors);
         throw new GFEwayException('Error parsing eWAY response: ' . $e->getMessage());
     }
 }
 /**
  * update payment status if it has changed
  * @param array $form
  * @param int $lead_id
  */
 public function gformAfterUpdateEntry($form, $lead_id)
 {
     // make sure we have permission
     check_admin_referer('gforms_save_entry', 'gforms_save_entry');
     // check that save action is for update
     if (strtolower(rgpost('save')) != 'update') {
         return;
     }
     // make sure payment is one of ours (probably)
     $payment_gateway = gform_get_meta($lead_id, 'payment_gateway');
     if (empty($payment_gateway) && GFEwayPlugin::isEwayForm($form['id'], $form['fields']) || $payment_gateway != 'gfeway') {
         return;
     }
     // make sure we have a new payment status
     $payment_status = rgpost('payment_status');
     if (empty($payment_status)) {
         return;
     }
     // update payment status
     $lead = GFFormsModel::get_lead($lead_id);
     $lead['payment_status'] = $payment_status;
     GFFormsModel::update_lead($lead);
 }
 /**
  * load eWAY response data as XML string
  *
  * @param string $response eWAY response as a string (hopefully of XML data)
  */
 public function loadResponseXML($response)
 {
     GFEwayPlugin::log_debug(sprintf('%s: eWAY says "%s"', __METHOD__, $response));
     // make sure we actually got something from eWAY
     if (strlen($response) === 0) {
         throw new GFEwayException('eWAY payment request returned nothing; please check your card details');
     }
     // prevent XML injection attacks, and handle errors without warnings
     $oldDisableEntityLoader = libxml_disable_entity_loader(true);
     $oldUseInternalErrors = libxml_use_internal_errors(true);
     try {
         $xml = simplexml_load_string($response);
         if ($xml === false) {
             $errmsg = '';
             foreach (libxml_get_errors() as $error) {
                 $errmsg .= $error->message;
             }
             throw new Exception($errmsg);
         }
         $this->status = strcasecmp((string) $xml->Result, 'success') === 0;
         $this->errorType = (string) $xml->ErrorSeverity;
         $this->error = (string) $xml->ErrorDetails;
         // restore old libxml settings
         libxml_disable_entity_loader($oldDisableEntityLoader);
         libxml_use_internal_errors($oldUseInternalErrors);
     } catch (Exception $e) {
         // restore old libxml settings
         libxml_disable_entity_loader($oldDisableEntityLoader);
         libxml_use_internal_errors($oldUseInternalErrors);
         throw new GFEwayException('Error parsing eWAY recurring payments response: ' . $e->getMessage());
     }
 }
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
if (!defined('ABSPATH')) {
    exit;
}
if (!defined('GFEWAY_PLUGIN_ROOT')) {
    define('GFEWAY_PLUGIN_FILE', __FILE__);
    define('GFEWAY_PLUGIN_ROOT', dirname(__FILE__) . '/');
    define('GFEWAY_PLUGIN_NAME', basename(dirname(__FILE__)) . '/' . basename(__FILE__));
    define('GFEWAY_PLUGIN_OPTIONS', 'gfeway_plugin');
    define('GFEWAY_PLUGIN_VERSION', '1.8.0');
    // error message names
    define('GFEWAY_ERROR_ALREADY_SUBMITTED', 'gfeway_err_already');
    define('GFEWAY_ERROR_NO_AMOUNT', 'gfeway_err_no_amount');
    define('GFEWAY_ERROR_REQ_CARD_HOLDER', 'gfeway_err_req_card_holder');
    define('GFEWAY_ERROR_REQ_CARD_NAME', 'gfeway_err_req_card_name');
    define('GFEWAY_ERROR_EWAY_FAIL', 'gfeway_err_eway_fail');
    // custom fields
    define('GFEWAY_FIELD_RECURRING', 'gfewayrecurring');
}
// instantiate the plug-in
require GFEWAY_PLUGIN_ROOT . 'includes/class.GFEwayPlugin.php';
GFEwayPlugin::getInstance();
 /**
  * send the eWAY payment request and retrieve and parse the response
  * @return GFEwayStoredResponse
  * @param string $xml eWAY payment request as an XML document, per eWAY specifications
  */
 private function sendPayment($xml)
 {
     // use sandbox if not from live website
     $url = $this->isLiveSite ? self::REALTIME_API_LIVE : self::REALTIME_API_SANDBOX;
     // execute the cURL request, and retrieve the response
     try {
         $responseXML = GFEwayPlugin::curlSendRequest($url, $xml, $this->sslVerifyPeer);
     } catch (GFEwayCurlException $e) {
         throw new GFEwayException("Error posting eWAY payment to {$url}: " . $e->getMessage());
     }
     $response = new GFEwayStoredResponse();
     $response->loadResponseXML($responseXML);
     return $response;
 }