From c8448e01118a354588aba9221f3b393b57d8e190 Mon Sep 17 00:00:00 2001 From: Mihai Alexandru Joldis Date: Fri, 3 Jun 2016 23:43:46 +0300 Subject: [PATCH] First release --- class-virtualmerchant.php | 226 ++++++++++++++++++++++++++++++++++++++ includes/functions.php | 131 ++++++++++++++++++++++ vmerchant.php | 56 ++++++++++ 3 files changed, 413 insertions(+) create mode 100644 class-virtualmerchant.php create mode 100644 includes/functions.php create mode 100644 vmerchant.php diff --git a/class-virtualmerchant.php b/class-virtualmerchant.php new file mode 100644 index 0000000..e402dc8 --- /dev/null +++ b/class-virtualmerchant.php @@ -0,0 +1,226 @@ + 0 ) { + $CardNumber = $_POST['CardNumber']; + } else { + $errorMsg .= __( 'Credit Card Number Required', 'wpsc_gold_cart' ) . '
'; + } + + if ( isset( $_POST['ExpiryMonth'] ) && strlen( $_POST['ExpiryMonth'] ) > 0 ) { + $ExpiryMonth = $_POST['ExpiryMonth']; + } else { + $errorMsg .= __( 'Credit Card Expiry Month Required', 'wpsc_gold_cart' ) . '
'; + } + + if ( isset( $_POST['ExpiryYear'] ) && strlen( $_POST['ExpiryYear'] ) > 0 ) { + $ExpiryYear = $_POST['ExpiryYear']; + } else { + $errorMsg .= __( 'Credit Card Expiry Year Required', 'wpsc_gold_cart' ) . '
'; + } + + if ( isset( $_POST['Cvc2'] ) && strlen( $_POST['Cvc2'] ) > 0 ) { + $Cvc2 = $_POST['Cvc2']; + } else { + $errorMsg .= __( 'Credit Card Cvc2 code Required', 'wpsc_gold_cart' ) . '
'; + } + + if ( strlen( $errorMsg ) > 0 ) { + $this->set_error_message( $errorMsg ); + header( 'Location: '.$this->cart_data['shopping_cart_url'] ); + exit(); + } + + $options = get_option( 'wpsc_vmerchnat' ); + + // temp vars to make things easier + if ( get_option('permalink_structure') != '' ) { + $separator ="?"; + } else { + $separator ="&"; + } + + if ( $options['mode'] == 'test' ) { + // test url goes here + $url = 'https://demo.myvirtualmerchant.com/VirtualMerchantDemo/process.do'; + } else { + //live url goes here + $url = 'https://www.myvirtualmerchant.com/VirtualMerchant/process.do'; + } + + $amount = number_format( $this->cart_data['total_price'], 2, '.', '' ); + $sales_tax = $this->cart_data['cart_tax']; + $invoice_number = $this->cart_data['session_id']; + $email = $this->cart_data['email_address']; + $transaction_results_page = $this->cart_data['transaction_results_url']; + $credit_card_date = $ExpiryMonth . '' . $ExpiryYear; + + // optional vars + $first_name = $this->cleanInput($this->cart_data['billing_address']['first_name']); + $last_name = $this->cleanInput($this->cart_data['billing_address']['last_name']); + $address2 = $this->cleanInput($this->cart_data['billing_address']['address']); + $city = $this->cleanInput($this->cart_data['billing_address']['city']); + $state = $this->cleanInput($this->cart_data['billing_address']['state']); + $country = $this->cart_data['billing_address']['country']; + + // avs vars + if ( $options['avs'] == 'yes' ) { + $avs_zip = $this->cart_data['billing_address']['post_code']; + $avs_address = $this->cleanInput($this->cart_data['billing_address']['address']); + } + + $form = ' + + + + + + +
+ + + + + + + + + + + + + + + + + + + '; + if ( strlen( $first_name ) > 0 ){ + $form .= ''; + } + + if ( strlen( $last_name ) > 0 ) { + $form .= ''; + } + + if ( strlen( $address2 ) > 0 ) { + $form .= ''; + } + + if ( strlen( $city ) > 0 ) { + $form .= ''; + } + + if ( strlen( $state ) > 0 ) { + $form .= ''; + } + + if ( strlen( $country ) > 0 ) { + $form .= ''; + } + + if ( $options['mode'] == 'test' ) { + $form .= ''; + } else { + $form .= ''; + } + + if ( $options['avs'] == 'yes' ) { + $form .= ' + '; + } + + $form .= ' +
+ + + '; + + echo $form; + exit(); + } + + private function cleanInput($strRawText){ + $iCharPos = 0; + $chrThisChar = ""; + $strCleanedText = ""; + $strAllowableChars = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_/\(),.:|"; + $blnAllowAccentedChars = TRUE; + + //Compare each character based on list of acceptable characters + while ( $iCharPos < strlen( $strRawText ) ) { + // Only include valid characters ** + $chrThisChar = substr($strRawText, $iCharPos, 1); + if ( strpos( $strAllowableChars, $chrThisChar ) !== FALSE ) { + $strCleanedText = $strCleanedText . $chrThisChar; + } elseIf ( $blnAllowAccentedChars == TRUE ) { + // Allow accented characters and most high order bit chars which are harmless ** + if ( ord( $chrThisChar ) >= 191 ) { + $strCleanedText = $strCleanedText . $chrThisChar; + } + } + + $iCharPos = $iCharPos + 1; + } + + return $strCleanedText; + } +} + +if ( isset( $_GET['ssl_card_number'] ) && + isset( $_GET['ssl_exp_date'] ) && + isset( $_GET['ssl_amount'] ) && + isset( $_GET['ssl_invoice_number']) && + isset( $_GET['ssl_result_message'] ) && + isset( $_GET['ssl_txn_id'] ) && + isset( $_GET['ssl_approval_code'] ) && + isset( $_GET['ssl_cvv2_response'] ) && + isset( $_GET['ssl_txn_time'] ) ) { + add_action('init', 'wpec_vmerchant_ipn'); +} + +function wpec_vmerchant_ipn() { + + $sessionid = $_GET['ssl_invoice_number']; + + if ( $_GET['ssl_result_message'] == 'APPROVED' || $_GET['ssl_result_message'] == 'APPROVAL' ) { + // success + $purchase_log = new WPSC_Purchase_Log( $sessionid, 'sessionid' ); + $purchase_log->set( array( + 'processed' => WPSC_Purchase_Log::ACCEPTED_PAYMENT, + 'transactid' => $_GET['ssl_txn_id'], + 'notes' => 'Virtual Merchant time : "' . $_GET['ssl_txn_time'] . '"', + ) ); + $purchase_log->save(); + + // set this global, wonder if this is ok + transaction_results( $sessionid, true ); + } else { + // success + $purchase_log = new WPSC_Purchase_Log( $sessionid, 'sessionid' ); + $purchase_log->set( array( + 'processed' => WPSC_Purchase_Log::INCOMPLETE_SALE, + 'transactid' => $_GET['ssl_txn_id'], + 'notes' => 'Virtual Merchant time : "' . $_GET['ssl_txn_time'] . '"', + ) ); + $purchase_log->save(); + $error_messages = wpsc_get_customer_meta( 'checkout_misc_error_messages' ); + if ( ! is_array( $error_messages ) ) + $error_messages = array(); + $error_messages[] = '' . urldecode( $_GET['ssl_result_message'] ) . ' '; + wpsc_update_customer_meta( 'checkout_misc_error_messages', $error_messages ); + $checkout_page_url = get_option( 'shopping_cart_url' ); + + if ( $checkout_page_url ) { + header( 'Location: '.$checkout_page_url ); + exit(); + } + } +} +?> \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php new file mode 100644 index 0000000..20b72cf --- /dev/null +++ b/includes/functions.php @@ -0,0 +1,131 @@ + $value ) { + $options[$name] = rtrim($value); + } + + update_option( 'wpsc_vmerchnat', $options ); + + return true; +} + +function wpec_virtualmerchant_settings_form() { + $args = array( + 'user_id' => '', + 'merchant_id' => '', + 'pin' => '', + 'avs' => 'no', + 'mode' => 'live' + ); + add_option( 'wpsc_vmerchnat', $args ); + $options = get_option( 'wpsc_vmerchnat' ); + $output = ' + + + '. __( 'Account ID', 'wpsc_gold_cart' ) .' + + + + + + + + ' . __( 'User ID', 'wpsc_gold_cart' ) .' + + + + + + + + ' . __( 'Merchant Pin', 'wpsc_gold_cart' ) .' + + + + + + + + ' . __( 'AVS Security', 'wpsc_gold_cart' ) .' + + + + + + + + + ' . __( 'Mode', 'wpsc_gold_cart' ) .' + + + + + + + '; + $struc = get_option('permalink_structure'); + if ( $struc == '' ) { + $output .= ' + + + '.__( 'This Gateway will only work if you change your permalink structure do anything except the default setting. In Settings->Permalinks', 'wpsc_gold_cart' ).' + + + '; + } + return $output; +} + +function wpec_vmerchant_checkout_fields() { + global $gateway_checkout_form_fields; + if( in_array( 'wpec_virtualmerchant', (array) get_option('custom_gateway_options') ) ) { + + $curryear = date( 'Y' ); + $curryear_2 = date( 'y' ); + $years = ''; + //generate year options + for ( $i = 0; $i < 10; $i++ ) { + $years .= "\r\n"; + $curryear++; + $curryear_2++; + } + ob_start(); ?> + + + + + + + + + + + + + + + + + + 'Virtual Merchant', + 'api_version' => 2.0, + 'class_name' => 'wpec_merchant_virtualmerchant', + 'has_recurring_billing' => false, + 'display_name' => 'Credit Card', + 'wp_admin_cannot_cancel' => false, + 'requirements' => array( + 'php_version' => 5.0 + ), + 'form' => 'wpec_virtualmerchant_settings_form', + 'submit_function' => 'wpec_save_virtualmerchant_settings', + 'internalname' => 'wpec_virtualmerchant', + 'display_name' => "Credit Card" + ); + return $nzshpcrt_gateways; +} +add_filter( 'wpsc_merchants_modules', 'wpec_add_vmerchant_gateway', 100 ); +?> \ No newline at end of file