/**
  * Implements all 3 steps of the Direct Post Method for demonstration
  * purposes.
  */
 public static function directPostDemo($url, $api_login_id, $transaction_key, $amount = "0.00", $md5_setting = "")
 {
     // Step 1: Show checkout form to customer.
     if (!count($_POST) && !count($_GET)) {
         $fp_sequence = time();
         // Any sequential number like an invoice number.
         echo AuthorizeNetDPM::getCreditCardForm($amount, $fp_sequence, $url, $api_login_id, $transaction_key);
     } elseif (count($_POST)) {
         $response = new AuthorizeNetSIM($api_login_id, $md5_setting);
         if ($response->isAuthorizeNet()) {
             if ($response->approved) {
                 // Do your processing here.
                 $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id;
             } else {
                 // Redirect to error page.
                 $redirect_url = $url . '?response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text;
             }
             // Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
             echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
         } else {
             echo "Error -- not AuthorizeNet. Check your MD5 Setting.";
         }
     } elseif (!count($_POST) && count($_GET)) {
         if ($_GET['response_code'] == 1) {
             echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']);
         } else {
             echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']);
         }
     }
 }
Esempio n. 2
0
 public function testIsAuthNet()
 {
     $_POST['x_amount'] = "4.12";
     $_POST['x_trans_id'] = "123";
     $_POST['x_MD5_Hash'] = "8FC33C32ABB3EDD8BBC4BE3E904CB47E";
     $message = new AuthorizeNetSIM("528udYYwz", "test");
     $this->assertTrue($message->isAuthorizeNet());
     $_POST['x_amount'] = "4.12";
     $_POST['x_trans_id'] = "123";
     $_POST['x_MD5_Hash'] = "8FC33C32BB3EDD8BBC4BE3E904CB47E";
     $message = new AuthorizeNetSIM("528udYYwz", "test");
     $this->assertFalse($message->isAuthorizeNet());
 }
Esempio n. 3
0
 /**
  * Implements all 3 steps of the Direct Post Method for demonstration
  * purposes.
  */
 public static function directPostDemo($url, $api_login_id, $transaction_key, $amount = "0.00", $md5_setting = "", $test_mode = true)
 {
     
     // Step 1: Show checkout form to customer.
     if (JRequest::getVar('task') == 'submit_order')
     {
         $fp_sequence = time(); // Any sequential number like an invoice number.
         echo AuthorizeNetDPM::getCreditCardForm($amount, $fp_sequence, $url, $api_login_id, $transaction_key, $test_mode, $test_mode);
     }
     // Step 2: Handle AuthorizeNet Transaction Result & return snippet.
     elseif (count($_POST)) 
     {
         $response = new AuthorizeNetSIM($api_login_id, $md5_setting);
         if ($response->isAuthorizeNet()) 
         {
             if ($response->approved) 
             {
                 // Do your processing here.
                 //$mainframe->redirect('index.php?option=com_docmanpaypal&task=ipn&merchant=authorize.net&response_code=1&transaction_id=' . $response->transaction_id); 
                 $redirect_url = JURI::base() . substr($_SERVER['REQUEST_URI'], 0) . '&response_code=1&transaction_id=' . $response->transaction_id;
             }
             else
             {
                 // Redirect to error page.
                 //$mainframe->redirect('index.php?option=com_docmanpaypal&task=ipn&merchant=authorize.net&response_code=' . $response->response_code . '&transaction_id=' . $response->transaction_id. '&response_reason_text=' . $response->response_reason_text);
                 $redirect_url = JURI::base() . substr($_SERVER['REQUEST_URI'], 0) . '&response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text;
             	//$redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text;
             }
             // Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
             echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
         }
         else
         {
             echo "Error -- not AuthorizeNet. Check your MD5 Setting.";
         }
     }
     // Step 3: Show receipt page to customer.
     elseif (!count($_POST) && count($_GET))
     {
         if ($_GET['response_code'] == 1)
         {
             echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']);
         }
         else
         {
           echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']);
         }
     }
 }
 public static function receivePost($url, $api, $hash)
 {
     // Step 2: Handle AuthorizeNet Transaction Result & return snippet.
     if (count($_POST)) {
         $url = remove_query_arg('mcsipn', 'true');
         $response = new AuthorizeNetSIM($api, $hash);
         if ($response->isAuthorizeNet()) {
             if ($response->approved) {
                 // Do your processing here.
                 $redirect_url = add_query_arg(array('response_code' => 1, 'transaction_id' => $response->transaction_id), $url);
             } else {
                 // Redirect to error page.
                 $redirect_url = add_query_arg(array('response_code' => $response->response_code, 'response_reason_text' => $response->response_reason_text, $url));
             }
             // Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
             echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
         } else {
             echo "Error -- not AuthorizeNet. Check your MD5 Setting.";
         }
     }
 }
Esempio n. 5
0
 /**
  * Record transaction information pending
  * $input isn't used here becuase the DPM method uses the post data directly off the global $_POST
  */
 public function pendingPayment(\Jazzee\Entity\Payment $payment, \Foundation\Form\Input $input)
 {
     $input = false;
     $response = new \AuthorizeNetSIM($this->_paymentType->getVar('gatewayId'), $this->_paymentType->getVar('gatewayHash'));
     if ($response->isAuthorizeNet()) {
         if ($response->approved) {
             $payment->setAmount($response->amount);
             $payment->setVar('transactionId', $response->transaction_id);
             $payment->setVar('authorizationCode', $response->authorization_code);
             $payment->pending();
             return true;
         } else {
             $payment->setAmount($response->amount);
             $payment->setVar('transactionId', $response->transaction_id);
             $payment->setVar('rejectedReasonCode', $response->response_reason_code);
             $payment->setVar('rejectedReason', $response->response_reason_text);
             $payment->rejected();
             return true;
         }
     }
     return false;
 }
 public function pjActionConfirm()
 {
     $params = $this->getParams();
     if (!isset($params['key']) || $params['key'] != md5($this->option_arr['private_key'] . PJ_SALT)) {
         return FALSE;
     }
     $resp = array();
     if (isset($params['x_login']) && isset($params['transkey']) && isset($params['md5_setting']) && !empty($params['x_login']) && !empty($params['transkey'])) {
         define("AUTHORIZENET_API_LOGIN_ID", $params['x_login']);
         define("AUTHORIZENET_TRANSACTION_KEY", $params['transkey']);
         define("AUTHORIZENET_SANDBOX", PJ_TEST_MODE);
         define("TEST_REQUEST", PJ_TEST_MODE);
         require_once $this->getConst('PLUGIN_DIR') . 'anet_php_sdk/AuthorizeNet.php';
         $response = new AuthorizeNetSIM($params['x_login'], $params['md5_setting']);
         if ($response->isAuthorizeNet()) {
             if ($response->approved) {
                 // Transaction approved!
                 $resp['transaction_id'] = $_POST['x_invoice_num'];
                 $resp['status'] = 'OK';
             } else {
                 // There was a problem.
                 $resp['response_reason_code'] = $response->response_reason_code;
                 $resp['response_code'] = $response->response_code;
                 $resp['response_reason_text'] = $response->response_reason_text;
                 $resp['status'] = 'FAIL';
             }
         } else {
             $resp['response_reason_text'] = "MD5 Hash failed";
             $resp['status'] = 'FAIL';
         }
     } else {
         $resp['response_reason_text'] = "Missing or empty parameters";
         $resp['status'] = 'FAIL';
     }
     return $resp;
 }
function mcs_receive_ipn()
{
    if (isset($_GET['mcsipn']) && $_GET['mcsipn'] == 'true') {
        global $wpdb;
        mcs_check();
        if (get_option('mcs_gateway') == 'authorizenet') {
            require_once 'gateways/AuthorizeNet.php';
            // The SDK
            $url = add_query_arg('mcsipn', 'true', home_url());
            $api = get_option('mcs_authnet_api');
            $hash = get_option('mcs_authnet_hash');
            // these all need to be set from Authorize.Net data
            $payment_status = mcs_map_status($_POST['x_response_code']);
            // map response to equivalent from PayPal
            $item_number = 1;
            // mandatory for Paypal, but only represents a submissions purchase here.
            $price = $_POST['x_amount'];
            $quantity = isset($_POST['quantity']) ? $_POST['quantity'] : 1;
            // need to add to form
            $quantity = is_int($quantity) ? $quantity : 1;
            $payer_email = $_POST['x_payer_email'];
            // must add to form
            $payer_first_name = $_POST['x_first_name'];
            $payer_last_name = $_POST['x_last_name'];
            $mc_fee = '0.00';
            // not included in data
            $item_name = sprintf(__('%s Event Submission', 'my-calendar-submissions'), get_option('blogname'));
            // required by Paypal
            $parent = '';
            $redirect_url = $_POST['x_referer_url'];
            // paypal IPN data
            $ipn = new AuthorizeNetSIM($api, $hash);
            if ($ipn->isAuthorizeNet()) {
                if ($ipn->approved) {
                    $response = 'VERIFIED';
                    $redirect_url = add_query_arg(array('response_code' => '1', 'transaction_id' => $ipn->transaction_id), $redirect_url);
                    $txn_id = $ipn->transaction_id;
                } else {
                    $response = 'ERROR';
                    $redirect_url = add_query_arg(array('response_code' => $ipn->response_code, 'response_reason_text' => $ipn->response_reason_text), $redirect_url);
                    $txn_id = false;
                }
                $response_code = '200';
            } else {
                wp_die(__('That transaction was not handled by Authorize.net. Please verify your MD5 setting.', 'my-calendar-submissions'));
            }
        } else {
            if (isset($_POST['payment_status'])) {
                $sandbox = get_option("mcs_use_sandbox");
                $receiver = strtolower(get_option('mcs_paypal_email'));
                $url = $sandbox == 'true' ? 'https://www.sandbox.paypal.com/webscr' : 'https://www.paypal.com/webscr';
                $req = 'cmd=_notify-validate';
                foreach ($_POST as $key => $value) {
                    $value = urlencode(stripslashes($value));
                    $req .= "&{$key}={$value}";
                }
                $args = wp_parse_args($req, array());
                global $mcs_version;
                $params = array('body' => $args, 'sslverify' => false, 'timeout' => 30, 'user-agent' => "WordPress/My Calendar Pro {$mcs_version}; " . get_bloginfo('url'));
                // transaction variables to store
                $payment_status = $_POST['payment_status'];
                $item_number = $_POST['item_number'];
                $price = $_POST['mc_gross'];
                $payment_currency = $_POST['mc_currency'];
                $receiver_email = $_POST['receiver_email'];
                $quantity = isset($_POST['quantity']) ? $_POST['quantity'] : 1;
                $quantity = is_int($quantity) ? $quantity : 1;
                $payer_email = $_POST['payer_email'];
                $payer_first_name = $_POST['first_name'];
                $payer_last_name = $_POST['last_name'];
                $mc_fee = $_POST['mc_fee'];
                $item_name = $_POST['item_name'];
                $txn_id = $_POST['txn_id'];
                $parent = isset($_POST['parent_txn_id']) ? $_POST['parent_txn_id'] : '';
                // paypal IPN data
                $ipn = wp_remote_post($url, $params);
                $response = $ipn['body'];
                $response_code = $ipn['response']['code'];
                // die conditions for PayPal
                // if receiver email or currency are wrong, this is probably a fraudulent transaction.
                if (strtolower($receiver_email) != $receiver || $payment_currency != get_option('mcs_currency')) {
                    wp_mail(get_option('mcs_to'), 'Payment Conditions Error', 'PayPal receiver email did not match account or payment currency did not match payment');
                    wp_die();
                }
                $redirect_url = false;
            } else {
                wp_die("No valid IPN request made");
            }
        }
        if ($response_code == '200') {
            if ($response == "VERIFIED") {
                $status = "";
                if (get_option('mcs_gateway') != 'authorizenet') {
                    // See whether the transaction already exists. (For refunds, reversals, or canceled reversals)
                    $sql = "SELECT id, hash, status FROM " . my_calendar_payments_table() . " WHERE txn_id = %s";
                    $txn = $parent != '' ? $wpdb->get_row($wpdb->prepare($sql, array($parent))) : $wpdb->get_row($wpdb->prepare($sql, array($txn_id)));
                } else {
                    $txn = false;
                }
                switch ($payment_status) {
                    case 'Completed':
                    case 'Created':
                    case 'Denied':
                    case 'Expired':
                    case 'Failed':
                    case 'Processed':
                    case 'Voided':
                        $status = $payment_status;
                        break;
                    case 'Pending':
                        $status = $payment_status . ': ' . $post['pending_reason'];
                        break;
                    case 'Refunded':
                    case 'Reversed':
                    case 'Canceled_Reversal':
                        $status = $payment_status . ': ' . $post['ReasonCode'];
                        break;
                }
                if (empty($txn)) {
                    //error_log("INSERT: ".$txn_id." ".$status);
                    $uniqid = uniqid('E');
                    $hash = mcs_uniqid($uniqid);
                    $sql = "INSERT INTO " . my_calendar_payments_table() . "\n\t\t\t\t\t\t\t(item_number,quantity,total,hash,txn_id,price,fee,status,transaction_date,first_name,last_name,payer_email)\n\t\t\t\t\t\t\tVALUES(%d, %d, %d, %s, %s, %f, %f, %s, NOW(), %s, %s, %s )";
                    $wpdb->query($wpdb->prepare($sql, array($item_number, $quantity, $quantity, $hash, $txn_id, $price, $mc_fee, $status, $payer_first_name, $payer_last_name, $payer_email)));
                } else {
                    $hash = $txn->hash;
                    //error_log("UPDATE: ".$txn_id." ".$status." ".$hash." ->".$item_number);
                    $sql = "UPDATE " . my_calendar_payments_table() . "\n\t\t\t\t\t\t\tSET status = %s,price=%f,fee=%f,transaction_date = NOW() WHERE id = %d";
                    $r = $wpdb->query($wpdb->prepare($sql, array($status, $price, $mc_fee, $txn->id)));
                    //error_log(var_dump($r, true));
                }
                if ($status == "Completed") {
                    mcs_send_notifications($payer_first_name, $payer_last_name, $payer_email, $price, $hash, $quantity);
                    setcookie("mcs_receipt", 'true', time() + 60 * 60, SITECOOKIEPATH, COOKIE_DOMAIN, false, true);
                }
            } else {
                // log for manual investigation
                $blogname = get_option('blogname');
                $mail_From = "From: {$blogname} Events <" . get_option('mcs_from') . ">";
                $mail_Subject = __("INVALID IPN on My Calendar Submission Payment", 'my-calendar-submissions');
                $mail_Body = __("Something went wrong. Hopefully this information will help:", 'my-calendar-submissions') . "\n\n";
                foreach ($_POST as $key => $value) {
                    $mail_Body .= $key . " = " . $value . "\n";
                }
                wp_mail(get_option('mcs_to'), $mail_Subject, $mail_Body, $mail_From);
            }
        } else {
            $blogname = get_option('blogname');
            $mail_From = "From: {$blogname} Events <" . get_option('mcs_from') . ">";
            $mail_Subject = __("WP HTTP Failed to contact Paypal", 'my-calendar-submissions');
            $mail_Body = __("Something went wrong. Hopefully this information will help:", 'my-calendar-submissions') . "\n\n";
            $mail_Body .= print_r($ipn, 1);
            wp_mail(get_option('mcs_to'), $mail_Subject, $mail_Body, $mail_From);
        }
        if ($redirect_url) {
            echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
            //wp_safe_redirect( $redirect_url );
            exit;
        } else {
            status_header(200);
        }
    } else {
        return;
    }
}
Esempio n. 8
0
<?php

if (!empty($_GET['invoice']) && !empty($_GET['response']) && $_GET['response'] == 1) {
    include_once '../../../../wp-load.php';
    include_once 'payment-api/authorize-php/autoload.php';
    global $hotel_option, $wpdb;
    $response = new AuthorizeNetSIM($hotel_option['authorize-api-id'], $hotel_option['authorize-md5-hash']);
    if ($response->isAuthorizeNet()) {
        if ($response->approved) {
            $wpdb->update($wpdb->prefix . 'gdlr_hotel_payment', array('payment_status' => 'paid', 'payment_info' => serialize($response), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_GET['invoice']), array('%s', '%s', '%s'), array('%d'));
            $temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlr_hotel_payment ";
            $temp_sql .= "WHERE id = " . $_GET['invoice'];
            $result = $wpdb->get_row($temp_sql);
            $contact_info = unserialize($result->contact_info);
            $data = unserialize($result->booking_data);
            $mail_content = gdlr_hotel_mail_content($contact_info, $data, $response, array('total_price' => $result->total_price, 'pay_amount' => $result->pay_amount, 'booking_code' => $result->customer_code));
            gdlr_hotel_mail($contact_info['email'], __('Thank you for booking the room with us.', 'gdlr-hotel'), $mail_content);
            gdlr_hotel_mail($hotel_option['recipient-mail'], __('New room booking received', 'gdlr-hotel'), $mail_content);
            $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice']), home_url());
        } else {
            $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice'], 'response_code' => $response->response_code, 'response_reason_text' => $response->response_reason_text), home_url());
        }
        // Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
        echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
    } else {
        die("Error. Check your MD5 Setting.");
        $redirect_url = add_query_arg(array($hotel_option['booking-slug'] => '', 'state' => 4, 'invoice' => $_GET['invoice'], 'response_code' => $response->response_code, 'response_reason_text' => $response->response_reason_text), home_url());
        ?>
<html>
<head>
	<script type='text/javascript'charset='utf-8'>window.location='<?php 
 function _authnet_sim_process()
 {
     global $event_details, $wpdb;
     $event_id = intval($_POST['e_ID']);
     if (is_null($event_id)) {
         return false;
     }
     $regis_id = $wpdb->escape($_POST['r_ID']);
     $regis_id = $this->erm->get_regis_id();
     $post_ID = $this->erm->get_regis_post_id();
     //may need to resort to this if
     /*
      $post_ID = intval( $_POST['p_ID'] );
      $gateway_id = intval( $_POST['g_ID'] );
     
     *
      $regis_meta = ( array ) $this->ecm->setup_regis_details( $post_ID );
      $this->ecm->setup_event_details( $event_id );
      $this->erm->setup_current_data( $regis_meta['__epl'] );
     */
     $_totals = $this->erm->calculate_cart_totals();
     $gateway_info = $this->erm->get_gateway_info($gateway_id);
     $api_login_id = $gateway_info['_epl_user'];
     $transaction_key = $gateway_info['_epl_pwd'];
     $this->epl->load_file('libraries/gateways/authnet/AuthorizeNet.php');
     $response = new AuthorizeNetSIM($api_login_id, $gateway_info['_epl_md5_hash']);
     if ($response->isAuthorizeNet()) {
         if ($response->approved) {
             $data['post_ID'] = $post_ID;
             $data['_epl_regis_status'] = 5;
             $data['_epl_grand_total'] = epl_get_element('x_amount', $_POST);
             $data['_epl_payment_amount'] = epl_get_element('x_amount', $_POST);
             $data['_epl_payment_date'] = current_time('mysql');
             $data['_epl_transaction_id'] = epl_get_element('x_trans_id', $_POST);
             $this->erm->update_payment_data($data);
             return true;
         } else {
             return '<div class="epl_error">ERROR: ' . $response->response_reason_text . '</div>';
         }
     }
 }
Esempio n. 10
0
<?php

require_once 'coffee_store_settings.php';
if ($METHOD_TO_USE == "AIM") {
    $transaction = new AuthorizeNetAIM();
    $transaction->setSandbox(AUTHORIZENET_SANDBOX);
    $transaction->setFields(array('amount' => $amount, 'card_num' => $_POST['x_card_num'], 'exp_date' => $_POST['x_exp_date'], 'first_name' => $_POST['x_first_name'], 'last_name' => $_POST['x_last_name'], 'address' => $_POST['x_address'], 'city' => $_POST['x_city'], 'state' => $_POST['x_state'], 'country' => $_POST['x_country'], 'zip' => $_POST['x_zip'], 'email' => $_POST['x_email'], 'card_code' => $_POST['x_card_code']));
    $response = $transaction->authorizeAndCapture();
    if ($response->approved) {
        // Transaction approved! Do your logic here.
        header('Location: thank_you_page.php?transaction_id=' . $response->transaction_id);
    } else {
        header('Location: error_page.php?response_reason_code=' . $response->response_reason_code . '&response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text);
    }
} elseif (count($_POST)) {
    $response = new AuthorizeNetSIM();
    if ($response->isAuthorizeNet()) {
        if ($response->approved) {
            // Transaction approved! Do your logic here.
            // Redirect the user back to your site.
            $return_url = $site_root . 'thank_you_page.php?transaction_id=' . $response->transaction_id;
        } else {
            // There was a problem. Do your logic here.
            // Redirect the user back to your site.
            $return_url = $site_root . 'error_page.php?response_reason_code=' . $response->response_reason_code . '&response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text;
        }
        echo AuthorizeNetDPM::getRelayResponseSnippet($return_url);
    } else {
        echo "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config.php";
    }
}
 /**
  * Payment callback for authorize.net
  * @author Oleg D.
  */
 function payment_callback()
 {
     Configure::write('debug', '0');
     $this->layout = false;
     //Configure::write('debug', 1);
     include_once '../vendors/anet_php_sdk/AuthorizeNet.php';
     if (SIGNUP_AUTH_NET_TEST_MODE) {
         $authLogin = SIGNUP_AUTH_NET_TEST_LOGIN_ID;
         $authSetting = AUTHORIZENET_MD5_SETTING;
     } else {
         $authLogin = SIGNUP_AUTH_NET_LOGIN_ID;
         $authSetting = AUTHORIZENET_MD5_SETTING;
     }
     $response = new AuthorizeNetSIM($authLogin, $authSetting);
     $signupID = intval($_POST['data']['Addition']['sd']);
     $userID = intval($_POST['data']['Addition']['ud']);
     $amount = $_POST['x_amount'];
     $discountID = intval($_POST['data']['Addition']['dd']);
     // 1 - first time payment, 2 - complete payment after partly paid
     $payment_process_num = intval($_POST['data']['Addition']['payment_process_num']);
     $signupStatus['Signup']['id'] = $signupID;
     $this->Signup->recursive = -1;
     $signup = $this->Signup->find('first', array('conditions' => array('Signup.id' => $signupID)));
     if (empty($signup['Signup']['id'])) {
         exit('Signup ID error!');
     }
     if ($response->isAuthorizeNet()) {
         $address_id = $this->_storeBillingAddress($userID, $_POST['x_address'], $_POST['data']['Addition']['address2'], $_POST['x_city'], $_POST['data']['Addition']['state_id'], $_POST['x_zip'], $_POST['data']['Addition']['country_id']);
         $phoneID = $this->Phone->addPhone($_POST['x_phone'], $userID);
         //store payment
         $payment = array();
         $payment['model'] = "Signup";
         $payment['model_id'] = $signupID;
         $payment['user_id'] = $userID;
         $payment['payment_date'] = date('Y-m-d H:i:s');
         if ($response->approved) {
             $payment['status'] = 'Approved';
         } else {
             $payment['status'] = 'Declined';
         }
         $payment['amount'] = $amount;
         $payment['reason'] = $_POST['x_response_reason_text'];
         $payment['description'] = $_POST['x_description'];
         $payment['information'] = serialize($_POST);
         $payment['address_id'] = $address_id;
         $payment['promocode_id'] = $discountID;
         $payment['phone_id'] = $phoneID;
         $this->Payment->create();
         $this->Payment->save($payment);
         $paymentId = $this->Payment->getLastInsertID();
         $this->Payment->savePaymentPromocodes($payment['promocode_id'], $paymentId);
         if ($response->approved) {
             if (floatval($signup['Signup']['total']) - floatval($signup['Signup']['discount']) == floatval($signup['Signup']['paid']) + floatval($payment['amount'])) {
                 $signupStatus['Signup']['status'] = "paid";
                 $signupStatus['Signup']['paid'] = floatval($signup['Signup']['paid'] + $payment['amount']);
                 $this->Promocode->usePromoCode($payment['promocode_id']);
                 //updatecount of use
             } else {
                 $signupStatus['Signup']['status'] = "partly paid";
                 $signupStatus['Signup']['paid'] = floatval($signup['Signup']['paid'] + $payment['amount']);
                 $this->Promocode->usePromoCode($payment['promocode_id']);
                 //updatecount of use
             }
             if ($payment_process_num == 1) {
                 $return_url = SECURE_SERVER . '/signups/thankyou/' . $paymentId;
             } elseif ($payment_process_num == 2) {
                 $return_url = SECURE_SERVER . '/signups/complete_payment_redirect/' . $paymentId;
             }
         } else {
             if ($signup['Signup']['paid'] > 0) {
                 $signupStatus['Signup']['status'] = "partly paid";
             } else {
                 $signupStatus['Signup']['status'] = "not paid";
             }
             if ($payment_process_num == 1) {
                 $return_url = SECURE_SERVER . '/signups/payment_error_redirect/' . $paymentId . '/?error=' . htmlspecialchars($response->response_reason_text);
             } elseif ($payment_process_num == 2) {
                 $return_url = SECURE_SERVER . '/signups/complete_payment_error_redirect/' . $signupID . '/' . $paymentId . '/?error=' . htmlspecialchars($response->response_reason_text);
             }
         }
     } else {
         if ($signup['Signup']['paid'] > 0) {
             $signupStatus['Signup']['status'] = "partly paid";
         } else {
             $signupStatus['Signup']['status'] = "not paid";
         }
         //echo "MD5 Hash failed. Check to make sure your MD5 Setting matches the one in config.php";
         if ($payment_process_num == 1) {
             $return_url = SECURE_SERVER . '/signups/payment_error_redirect/' . $paymentId . '/?error=' . htmlspecialchars('MD5 Hash failed');
         } elseif ($payment_process_num == 2) {
             $return_url = SECURE_SERVER . '/signups/complete_payment_error_redirect/' . $signupID . '/' . $paymentId . '/?error=' . htmlspecialchars('MD5 Hash failed');
         }
     }
     $this->Signup->save($signupStatus);
     echo AuthorizeNetDPM::getRelayResponseSnippet($return_url);
     exit;
 }