function espresso_process_mwarrior($payment_data)
{
    $payment_data['txn_type'] = 'Mwarrior';
    $payment_data['txn_id'] = 0;
    $payment_data['payment_status'] = 'Incomplete';
    $payment_data['txn_details'] = serialize($_REQUEST);
    include_once 'Mwarrior.php';
    $mwarrior = new Mwarrior();
    echo '<!--Event Espresso Merchant Warrior Gateway Version ' . $mwarrior->gateway_version . '-->';
    $mwarrior->ipnLog = TRUE;
    $mwarrior_settings = get_option('event_espresso_mwarrior_settings');
    $mwarrior->setMerchantInfo($mwarrior_settings['mwarrior_id'], $mwarrior_settings['mwarrior_apikey'], $mwarrior_settings['mwarrior_passphrase']);
    // Enable test mode if needed
    if ($mwarrior_settings['use_sandbox']) {
        $mwarrior->enableTestMode();
        $email_transaction_dump = true;
    }
    if ($mwarrior->validateIpn()) {
        $payment_data['txn_details'] = serialize($mwarrior->response);
        $payment_data['txn_id'] = $mwarrior->response['responseData']['transactionID'];
        if ($mwarrior->response['status'] == 'approved') {
            ?>
			<h2><?php 
            _e('Thank You!', 'event_espresso');
            ?>
</h2>
			<p><?php 
            _e('Your transaction has been processed.', 'event_espresso');
            ?>
</p>
			<?php 
            $payment_data['payment_status'] = 'Completed';
        } else {
            if (!isset($mwarrior->response['result'])) {
                // Only for Redirect 302
                // Query here - find out why
                $resp = $mwarrior->queryCard($payment_data['txn_id']);
                ?>
				<h2 style="color:#F00;"><?php 
                _e('There was an error processing your transaction!', 'event_espresso');
                ?>
</h2>
				<p>Transaction ID: <?php 
                echo $payment_data['txn_id'];
                ?>
 </p>
				<p><strong>Error:</strong> (<?php 
                echo $resp['responseCode'];
                ?>
 - <?php 
                echo $resp['responseMessage'];
                ?>
) - <?php 
                echo urldecode($resp['authMessage']);
                ?>
</p>
				<?php 
            }
            $payment_data['payment_status'] = 'Declined';
        }
        //Debugging option
        if ($email_transaction_dump == true) {
            // For this, we'll just email ourselves ALL the data as plain text output.
            $subject = 'Instant Payment Notification - Gateway Variable Dump';
            $body = "An instant payment notification was successfully recieved\n";
            $body .= "from " . $payment_data['email'] . " on " . date('m/d/Y');
            $body .= " at " . date('g:i A') . "\n\nDetails:\n";
            foreach ($mwarrior->response as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $k => $v) {
                        $body .= "\n{$k}: {$v}\n";
                    }
                } else {
                    $body .= "\n{$key}: {$value}\n";
                }
            }
            wp_mail($payment_data['contact'], $subject, $body);
        }
    } else {
        $payment_data['payment_status'] = "Incomplete";
        ?>
		<h2 style="color:#F00;"><?php 
        _e('There was an error processing your transaction!', 'event_espresso');
        ?>
</h2>
		<p><strong>Error:</strong> (<?php 
        echo stripslashes($_GET['message']);
        ?>
) </p>
		<?php 
        $subject = 'Instant Payment Notification - Gateway Variable Dump';
        $body = "An instant payment notification failed\n";
        $body .= "from " . $payment_data['email'] . " on " . date('m/d/Y');
        $body .= " at " . date('g:i A') . "\n\nDetails:\n";
        foreach ($mwarrior->response as $key => $value) {
            $body .= "\n{$key}: {$value}\n";
        }
        wp_mail($payment_data['contact'], $subject, $body);
    }
    add_action('action_hook_espresso_email_after_payment', 'espresso_email_after_payment');
    return $payment_data;
}
Example #2
0
function espresso_display_mwarrior($payment_data)
{
    extract($payment_data);
    // Setup class
    include_once 'Mwarrior.php';
    $mwarrior = new Mwarrior();
    // initiate an instance of the class
    echo '<!--Event Espresso Merchant Warrior Gateway Version ' . $mwarrior->gateway_version . '-->';
    global $org_options;
    //global $attendee_id;
    $mwarrior_settings = get_option('event_espresso_mwarrior_settings');
    $mwarrior_id = empty($mwarrior_settings['mwarrior_id']) ? '' : $mwarrior_settings['mwarrior_id'];
    $mwarrior_apikey = empty($mwarrior_settings['mwarrior_apikey']) ? '' : $mwarrior_settings['mwarrior_apikey'];
    $mwarrior_passphrase = empty($mwarrior_settings['mwarrior_passphrase']) ? '' : $mwarrior_settings['mwarrior_passphrase'];
    $mwarrior_cur = empty($mwarrior_settings['currency_format']) ? '' : $mwarrior_settings['currency_format'];
    $logo_url = empty($mwarrior_settings['image_url']) ? '' : $mwarrior_settings['image_url'];
    $use_sandbox = $mwarrior_settings['use_sandbox'];
    if ($use_sandbox) {
        // Enable test mode if needed
        $mwarrior->enableTestMode();
    }
    $salt = $mwarrior->_generateHashSalt();
    $mwarrior->setMerchantInfo($mwarrior_id, $mwarrior_apikey, $mwarrior_passphrase);
    //Post variables
    $mwarrior->addField('method', 'processCard');
    $mwarrior->addField('merchantUUID', $mwarrior_id);
    $mwarrior->addField('apiKey', $mwarrior_apikey);
    $mwarrior->addField('customerName', $fname . " " . $lname);
    $mwarrior->addField('customerEmail', $attendee_email);
    $mwarrior->addField('customerAddress', $address);
    $mwarrior->addField('customerCity', $city);
    $mwarrior->addField('customerPostCode', $zip);
    $mwarrior->addField('customerState', $state);
    $mwarrior->addField('customerCountry', empty($country) ? '' : $country);
    $mwarrior->addField('transactionProduct', stripslashes_deep($event_name));
    $mwarrior->addField('transactionAmount', number_format($event_cost, 2, '.', ''));
    $mwarrior->addField('transactionCurrency', $mwarrior_cur);
    $mwarrior->addField('logoURL', $logo_url);
    if ($mwarrior_settings['force_ssl_return']) {
        $home = str_replace("http://", "https://", home_url());
    } else {
        $home = home_url();
    }
    $mwarrior->addField('returnURL', $home . '/?page_id=' . $org_options['return_url'] . '&id=' . $attendee_id . '&r_id=' . $registration_id . '&event_id=' . $event_id . '&attendee_action=post_payment&form_action=payment&type=mwarrior');
    //$mwarrior->addField('cancel_return', $home.'/?page_id='.$org_options['cancel_return']);
    $mwarrior->addField('notifyURL', $home . '/?page_id=' . $org_options['return_url'] . '&id=' . $attendee_id . '&r_id=' . $registration_id . '&event_id=' . $event_id . '&attendee_action=post_payment&form_action=payment&type=mwarrior');
    $mwarrior->addField('urlHash', $mwarrior->_calculateHash($mwarrior->fields, "url"));
    $mwarrior->addField('hash', $mwarrior->_calculateHash($mwarrior->fields, "transaction"));
    $mwarrior->addField('hashSalt', $salt);
    //Enable this function if you want to send payment notification before the person has paid.
    //This function is copied on the payment processing page
    //event_espresso_send_payment_notification($attendee_id, $txn_id, $amount_pd);
    //Decide if you want to auto redirect to your payment website or display a payment button.
    if (!empty($mwarrior_settings['bypass_payment_page']) && $mwarrior_settings['bypass_payment_page'] == 'Y') {
        $mwarrior->submitPayment();
        //Enable auto redirect to payment site
    } else {
        if (empty($mwarrior_settings['button_url'])) {
            if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "/mwarrior/mwarrior-logo.png")) {
                $button_url = EVENT_ESPRESSO_GATEWAY_DIR . "/mwarrior/mwarrior-logo.png";
            } else {
                $button_url = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/mwarrior/mwarrior-logo.png";
            }
        } elseif (file_exists($mwarrior_settings['button_url'])) {
            $button_url = $mwarrior_settings['button_url'];
        } else {
            //If no other buttons exist, then use the default location
            $button_url = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/mwarrior/mwarrior-logo.png";
        }
        $mwarrior->submitButton($button_url, 'mwarrior');
        //Display payment button
    }
    // Store the salt temporarily in the database
    $mwarrior->_storeHashSalt($salt, espresso_registration_id($attendee_id));
    if ($use_sandbox) {
        echo '<h3 style="color:#ff0000;" title="Payments will not be processed">' . __('Debug Mode Is Turned On', 'event_espresso') . '</h3>';
        $mwarrior->dump_fields();
        // for debugging, output a table of all the fields
    }
}