From da07b626a5592cf9ef7cce5667580e9a0fbba5eb Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 6 Mar 2018 16:47:37 -0500 Subject: [PATCH] Payment form, filters and debugging. Going through and removing php notices when I find them. Payment Form is now saving the payment and transactions and is working with Authorize.net. Need to replace the select for the member accounts on the add new invoice page with autocomplete. --- classes/billingSupport.php | 22 ++ classes/data/dataAccounts.php | 28 +- config/plugin.ini | 100 ++++++ css/admin.css | 3 + defines.php | 2 +- index.php | 2 +- .../Authorize.Net/paymentGateway.php | 2 +- models/admin/billing/accounts.php | 2 + models/admin/billing/index.php | 3 +- models/admin/billing/invoices.php | 70 ++-- models/admin/member/billing.php | 301 ++++++++++-------- ...V0.0.9.sql => create_database_V0.0.10.sql} | 2 + setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.0.10.sql | 14 + views/admin/billing/editAccount.html | 25 +- views/admin/billing/editInvoice.html | 4 + views/admin/billing/invoices.html | 40 ++- views/admin/billing/makePayment.html | 145 +++++++-- views/admin/billing/paymentProcess.html | 7 +- 19 files changed, 567 insertions(+), 206 deletions(-) rename setup/databaseScripts/{create_database_V0.0.9.sql => create_database_V0.0.10.sql} (98%) create mode 100644 setup/databaseScripts/update_database_V0.0.10.sql diff --git a/classes/billingSupport.php b/classes/billingSupport.php index dc5726f..534ecce 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -129,6 +129,28 @@ class GlmBillingSupport } } } + public function createPayment( $account, $payment ) + { + // Insert the payment + $this->wpdb->insert( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'payments', + array( + 'transaction_time' => date('Y-m-d H:i:s'), + 'account' => $account, + 'amount' => $payment, + 'payment_method' => '', + 'payment_data' => '', + ), + array( + '%s', + '%d', + '%s', + '%s', + '%s', + ) + ); + return $this->wpdb->insert_id; + } /** * markInvoiceAsPaid diff --git a/classes/data/dataAccounts.php b/classes/data/dataAccounts.php index 88f2fb2..ab2977e 100644 --- a/classes/data/dataAccounts.php +++ b/classes/data/dataAccounts.php @@ -170,12 +170,28 @@ class GlmDataAccounts extends GlmDataAbstract 'required' => true, ), + // Billing First Name + 'billing_fname' => array( + 'field' => 'billing_fname', + 'type' => 'text', + 'use' => 'a', + 'required' => true, + ), + + // Billing Last Name + 'billing_lname' => array( + 'field' => 'billing_lname', + 'type' => 'text', + 'use' => 'a', + 'required' => true, + ), + // Billing Address 1 'billing_addr1' => array( 'field' => 'billing_addr1', 'type' => 'text', 'use' => 'a', - 'required' => false, + 'required' => true, ), // Billing Address 2 @@ -191,15 +207,17 @@ class GlmDataAccounts extends GlmDataAbstract 'field' => 'billing_city', 'type' => 'text', 'use' => 'a', - 'required' => false, + 'required' => true, ), // Billing State 'billing_state' => array( 'field' => 'billing_state', - 'type' => 'text', + 'type' => 'list', + 'list' => $this->config['states'], + 'default' => $this->config['settings']['default_state'], 'use' => 'a', - 'required' => false, + 'required' => true, ), // Billing Zip @@ -207,7 +225,7 @@ class GlmDataAccounts extends GlmDataAbstract 'field' => 'billing_zip', 'type' => 'text', 'use' => 'a', - 'required' => false, + 'required' => true, ), // Billing Phone diff --git a/config/plugin.ini b/config/plugin.ini index f3d941f..90f2589 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -47,3 +47,103 @@ send_date_when[20] = "After" send_date_when_numb['Before'] = 10 send_date_when_numb['After'] = 20 + +; Credit Cards - Use as Bitmap Index or List +; +credit_card[1] = 'Visa' +credit_card[2] = 'MasterCard' +credit_card[3] = 'American Express' +credit_card[4] = 'Discover' +credit_card[5] = 'Diners Club' + +credit_card_numb['Visa'] = 1 +credit_card_numb['MasterCard'] = 2 +credit_card_numb['American Express'] = 3 +credit_card_numb['Discover'] = 4 +credit_card_numb['Diners Club'] = 5 + +credit_card_match[1] = '/^4[0-9]{12}(?:[0-9]{3})?$/' +credit_card_match[2] = '/^([51|52|53|54|55]{2})([0-9]{14})$/' +credit_card_match[3] = '/^([34|37]{2})([0-9]{13})$/' +credit_card_match[4] = '/^([6011]{4})([0-9]{12})$/' +credit_card_match[5] = '/^([30|36|38]{2})([0-9]{12})$/' + + +; +; Card Processing Methods - Use as Bitmap Index or List +; +proc_method[1] = 'By Merchant' +proc_method[2] = 'Authorize.net' +proc_method[3] = 'Merchant Solutions' +proc_method[98] = 'Test - Card Always Good' +proc_method[99] = 'Test by Card Number' + +proc_method_numb['Merchant'] = 1 +proc_method_numb['Authorize.net'] = 2 +proc_method_numb['MerchantSolutions'] = 3 +proc_method_numb['TestAlwaysGood'] = 4 +proc_method_numb['TestByCardNumber'] = 5 + +proc_dir[1] = 'ByMerchant' +proc_dir[2] = 'Authorize.Net' +proc_dir[3] = 'MerchantSolutions' +proc_dir[98] = 'TestGood' +proc_dir[99] = 'TestByCardNumber' + +; +; Card processing test modes +; +proc_test_mode[1] = 'Local Transaction Approval Test' +proc_test_mode[2] = 'Local Transaction Decline Test' +proc_test_mode[3] = 'On-Line Transaction Test' +proc_test_mode[99] = 'Production Mode' + +proc_test_mode_numb['Local Approval Test'] = 1 +proc_test_mode_numb['Local Decline Test'] = 2 +proc_test_mode_numb['On-Line Test'] = 3 +proc_test_mode_numb['Production Mode'] = 0 + +; +; Card processor result codes +; +proc_result[1] = 'Card approved' +proc_result[2] = 'Bad data supplied to credit card processor' +proc_result[3] = 'Communications failure with credit card processor' +proc_result[4] = 'Bad response from the credit card processor' +proc_result[5] = 'Credit card processor says transaction is not valid' +proc_result[6] = 'Merchant account is not recognized by the credit card processor' +proc_result[7] = 'Credit card has been declined' + +proc_result_numb['Approved'] = 1 +proc_result_numb['BadData'] = 2 +proc_result_numb['CommFailure'] = 3 +proc_result_numb['BadResponse'] = 4 +proc_result_numb['NotValid'] = 5 +proc_result_numb['BadAccount'] = 6 +proc_result_numb['Declined'] = 7 + +; Submission Status - Use as list only +; +submission_status[0] = 'CART' +submission_status[10] = 'COMPLETE' +submission_status[20] = 'UNPAID' +submission_status[30] = 'CC_PEND' +submission_status[40] = 'CC_DECL' +submission_status[50] = 'PAYMENT_PEND' +submission_status[60] = 'ON ARRIVAL' +submission_status[70] = 'ADMIN HOLD' +submission_status[80] = 'FAILED' +submission_status[99] = 'CANCELED' + +submission_status_numb['CART'] = 0 +submission_status_numb['COMPLETE'] = 10 +submission_status_numb['UNPAID'] = 20 +submission_status_numb['CC_PEND'] = 30 +submission_status_numb['CC_DECL'] = 40 +submission_status_numb['PAYMENT_PEND'] = 50 +submission_status_numb['ON_ARRIVAL'] = 60 +submission_status_numb['ADMIN_HOLD'] = 70 +submission_status_numb['FAILED'] = 80 +submission_status_numb['CANCELED'] = 99 + +; diff --git a/css/admin.css b/css/admin.css index d8d4072..491b063 100644 --- a/css/admin.css +++ b/css/admin.css @@ -5,3 +5,6 @@ #billing-invoice-form input[name^="line_item_qty"] { width: 50px; } +.glm-admin-table th { + white-space: nowrap; +} diff --git a/defines.php b/defines.php index 368a2fe..1877939 100644 --- a/defines.php +++ b/defines.php @@ -64,5 +64,5 @@ define('GLM_MEMBERS_BILLING_PLUGIN_CONFIG_PATH', GLM_MEMBERS_BILLING_PLUGIN_PATH // Parameters related to the Main GLM Member DB plugin - Depending on what's going on these may already defined by the main plugin $pluginsPath = str_replace(GLM_MEMBERS_BILLING_PLUGIN_SLUG, '', GLM_MEMBERS_BILLING_PLUGIN_PATH); define('GLM_MEMBERS_BILLING_MAIN_PLUGIN_PATH', $pluginsPath.'/glm-member-db'); -define('GLM_MEMBERS_BILLING_PLUGIN_LIB_PATH', GLM_MEMBERS_BILLING_MAIN_PLUGIN_PATH.'/lib'); +define('GLM_MEMBERS_BILLING_PLUGIN_LIB_PATH', GLM_MEMBERS_BILLING_PLUGIN_PATH.'/lib'); diff --git a/index.php b/index.php index 892b8d6..8d0c8f7 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.9'); +define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.10'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/lib/paymentProcessors/Authorize.Net/paymentGateway.php b/lib/paymentProcessors/Authorize.Net/paymentGateway.php index c3e7d37..6a37c33 100644 --- a/lib/paymentProcessors/Authorize.Net/paymentGateway.php +++ b/lib/paymentProcessors/Authorize.Net/paymentGateway.php @@ -199,7 +199,7 @@ class PaymentGateway $sale->zip = $contact['zip']; $sale->country = $contact['country']; $sale->invoice_num = substr($payment['invoice'], -20); // Only use last 20 chars - $sale->description = $payment['name'].' - Event Tickets'; + $sale->description = $payment['name'].' - Billing'; $sale->email = $contact['email']; $sale->email_customer = $this->account['conf']; $sale->phone = $contact['phone']; diff --git a/models/admin/billing/accounts.php b/models/admin/billing/accounts.php index 96c1cc3..03a1045 100644 --- a/models/admin/billing/accounts.php +++ b/models/admin/billing/accounts.php @@ -119,6 +119,8 @@ class GlmMembersAdmin_billing_accounts extends GlmDataAccounts $invoiceHtml = ''; $fromDate = ''; $toDate = ''; + $annFromDate = ''; + $annToDate = ''; // Get any provided option if (isset($_REQUEST['option'])) { diff --git a/models/admin/billing/index.php b/models/admin/billing/index.php index 4080c5d..0ed8bce 100644 --- a/models/admin/billing/index.php +++ b/models/admin/billing/index.php @@ -223,8 +223,7 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices /** * $pending = array( start, limit, returned, last, list = array...) */ - // echo '
$pending: ' . print_r( $pending, true ) . '
'; - $numberPending = $pending['returned']; + $numberPending = ( isset( $pending['returned'] ) ? $pending['returned'] : 0 ); // Get the number of over due invoices $overDueWhere = 'T.paid <> true AND due_date > NOW()'; diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index 5eb9656..9bda0b7 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -91,37 +91,40 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices public function modelAction($actionData = false) { - $option = 'list'; - $this->invoice_id = false; - $haveInvoices = false; - $invoiceUpdated = false; - $invoiceUpdateError = false; - $invoiceAdded = false; - $invoiceAddError = false; - $view = 'invoices'; - $fromDate = false; - $toDate = false; - $filterArchived = false; - $filterPending = false; - $filterFeatured = false; - $invoiceDeleted = false; - $invoiceDeleteError = false; - $invoiceInsertError = false; - $numbDisplayed = false; - $lastDisplayed = false; - $paging = true; - $prevStart = false; - $nextStart = false; - $start = 1; - $limit = 20; // Set to the number of listings per page - $invTypes = array(); - $invoiceTypes = false; - $invoiceTypeJSON = ''; - $accounts = false; - $nonAccountMembers = false; - $invoiceHtml = ''; - $fromDate = ''; - $toDate = ''; + $option = 'list'; + $this->invoice_id = false; + $haveInvoices = false; + $invoiceUpdated = false; + $invoiceUpdateError = false; + $invoiceAdded = false; + $invoiceAddError = false; + $view = 'invoices'; + $fromDate = false; + $toDate = false; + $filterArchived = false; + $filterPending = false; + $filterFeatured = false; + $invoiceDeleted = false; + $invoiceDeleteError = false; + $invoiceInsertError = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $invTypes = array(); + $invoiceTypes = false; + $invoiceTypeJSON = ''; + $accounts = false; + $nonAccountMembers = false; + $invoiceHtml = ''; + $fromDate = ''; + $toDate = ''; + $invoices = false; + $fromMemberMenu = false; + $filterAccounts = ''; // Get any provided option if (isset($_REQUEST['option'])) { @@ -290,6 +293,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices // Need to get the accounts $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); $accounts = $Accounts->getList(); + // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; $where_params = array( 'true' ); @@ -364,7 +368,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices && $filterAccounts = filter_var( $_REQUEST['filterAccounts'], FILTER_VALIDATE_INT ) ) { $accounts[$filterAccounts]['selected'] = true; - $where_params[] = "T.account = $filterAccounts"; + $where_params[] = "T.account = $filterAccounts"; } // Build the $where from $where_params array. @@ -431,6 +435,8 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices 'invoiceHtml' => $invoiceHtml, 'fromDate' => $fromDate, 'toDate' => $toDate, + 'fromMemberMenu' => $fromMemberMenu, + 'filterAccounts' => $filterAccounts, ); // Return status, any suggested view, and any data to controller diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 8e20bc8..5576f4b 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -14,6 +14,7 @@ */ define('GLM_MEMBERS_BILLING_MEMBER_MENU', true); require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoices.php'; +// require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataPayments.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/billingSupport.php'; // Load Billing data abstract @@ -113,6 +114,9 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $account_data = false; $balance_due = false; $invoiceHtml = false; + $management = false; + $messages = array(); + $invoices = false; // For lockedToMember. $lockedToMember = false; @@ -229,160 +233,182 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling break; case 'createPayment': - echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; $view = 'paymentProcess'; - echo '
$this->config: ' . print_r( $this->config, true ) . '
'; + // echo '
$this->config: ' . print_r( $this->config, true ) . '
'; // Execute selected payment method - switch ($payMethod) { - // Credit Card - case $this->config['payment_method_numb']['CreditCard']: + // Get the selected credit card processor type + $ccProcessor = $this->config['billing_settings']['proc_methods']; - // Get the selected credit card processor type - $ccProcessor = $this->config['settings']['reg_proc_methods']; + // Setup the required account information for the selected payment processor + switch ($ccProcessor) { - // Setup the required account information for the selected payment processor - switch ($ccProcessor) { + case $this->config['proc_method_numb']['Authorize.net']: - case $this->config['proc_method_numb']['Authorize.net']: - - // Get account data - $account = array( - 'login' => $this->config['settings']['reg_authorize_net_login'], - 'key' => $this->config['settings']['reg_authorize_net_key'], - 'test' => $this->config['settings']['reg_authorize_net_test'], - 'conf' => $this->config['settings']['reg_authorize_net_conf'], - 'email' => $this->config['settings']['reg_authorize_net_merchant_email'] - ); - - break; + // Get account data + $account = array( + 'login' => $this->config['billing_settings']['authorize_net_login'], + 'key' => $this->config['billing_settings']['authorize_net_key'], + 'test' => $this->config['billing_settings']['authorize_net_test'], + 'conf' => $this->config['billing_settings']['authorize_net_conf'], + 'email' => $this->config['billing_settings']['authorize_net_merchant_email'] + ); - case $this->config['proc_method_numb']['MerchantSolutions']: + break; - // Get account data - $account = array( - 'acctid' => $this->config['settings']['reg_merchant_solutions_acctid'], - 'merchantpin' => $this->config['settings']['reg_merchant_solutions_merchantpin'], - 'test' => $this->config['settings']['reg_merchant_solutions_test'], - 'conf' => $this->config['settings']['reg_merchant_solutions_conf'], - 'email' => $this->config['settings']['reg_merchant_solutions_merchant_email'] - ); + case $this->config['proc_method_numb']['MerchantSolutions']: - break; + // Get account data + $account = array( + 'acctid' => $this->config['billing_settings']['merchant_solutions_acctid'], + 'merchantpin' => $this->config['billing_settings']['merchant_solutions_merchantpin'], + 'test' => $this->config['billing_settings']['merchant_solutions_test'], + 'conf' => $this->config['billing_settings']['merchant_solutions_conf'], + 'email' => $this->config['billing_settings']['merchant_solutions_merchant_email'] + ); - // These don't require account data - case $this->config['proc_method_numb']['Merchant']: - case $this->config['proc_method_numb']['TestAlwaysGood']: - case $this->config['proc_method_numb']['TestByCardNumber']: - default: - $account = array(); - break; + break; - } + // These don't require account data + case $this->config['proc_method_numb']['Merchant']: + case $this->config['proc_method_numb']['TestAlwaysGood']: + case $this->config['proc_method_numb']['TestByCardNumber']: + default: + $account = array(); + break; - // Get the credit card input - $cardData = array( - 'cc_type' => filter_input(INPUT_POST, 'cc_type', FILTER_SANITIZE_NUMBER_INT), - 'cc_name' => filter_input(INPUT_POST, 'cc_name', FILTER_SANITIZE_STRING), - 'cc_numb' => filter_input(INPUT_POST, 'cc_numb', FILTER_SANITIZE_NUMBER_INT), - 'cc_exp' => filter_input(INPUT_POST, 'cc_exp', FILTER_SANITIZE_STRING), - 'cc_cvv' => filter_input(INPUT_POST, 'cc_cvv', FILTER_SANITIZE_NUMBER_INT) - ); + } - // Check all credit card input - if ( - $cardData['cc_type'] && $cardData['cc_type'] > 0 && - $cardData['cc_name'] && $cardData['cc_name'] != '' && - $cardData['cc_numb'] && $cardData['cc_numb'] > 0 && - $cardData['cc_exp'] && $cardData['cc_exp'] != '' && - $cardData['cc_cvv'] && $cardData['cc_cvv'] > 0 - ) { + // echo '
$account: ' . print_r( $account, true ) . '
'; + // Get the credit card input + $cardData = filter_var_array( + $_REQUEST, + array( + 'cc_type' => FILTER_SANITIZE_STRING, + 'cc_name' => FILTER_SANITIZE_STRING, + 'cc_numb' => FILTER_SANITIZE_NUMBER_INT, + 'cc_exp' => FILTER_SANITIZE_STRING, + 'cc_cvv' => FILTER_SANITIZE_NUMBER_INT, + ) + ); - if (!isset($this->config['credit_card_match'][$cardData['cc_type']]) || - !preg_match($this->config['credit_card_match'][$cardData['cc_type']], $cardData['cc_numb']) - ) { - $messages[] = 'The credit card number you entered does not match the selected type of credit card.'; - } + $paymentData = filter_var_array( + $_REQUEST, + array( + 'account_id' => FILTER_SANITIZE_NUMBER_INT, + 'invoice_id' => FILTER_SANITIZE_NUMBER_INT, + 'member' => FILTER_SANITIZE_NUMBER_INT, + 'amount' => array( + 'filter' => FILTER_SANITIZE_NUMBER_FLOAT, + 'flags' => FILTER_FLAG_ALLOW_FRACTION, + ), + 'billing_addr1' => FILTER_SANITIZE_STRING, + 'billing_addr2' => FILTER_SANITIZE_STRING, + 'billing_city' => FILTER_SANITIZE_STRING, + 'billing_state' => FILTER_SANITIZE_STRING, + 'billing_zip' => FILTER_SANITIZE_STRING, + 'billing_phone' => FILTER_SANITIZE_STRING, + ) + ); - } else { - $messages[] = 'You did not supply all required credit card information.'; - } + // Add billing information to billing array + $billing = array( + 'fname' => $paymentData['billing_fname'], + 'lname' => $paymentData['billing_lname'], + 'addr1' => $paymentData['billing_addr1'], + 'addr2' => $paymentData['billing_addr2'], + 'city' => $paymentData['billing_city'], + 'state' => $paymentData['billing_state'], + 'zip' => $paymentData['billing_zip'], + 'phone' => $paymentData['bill_phone'], + 'email' => $paymentData['email'] + ); + // echo '
$cardData: ' . print_r( $cardData, true ) . '
'; + $cardMatch = $this->config['credit_card_match']; + // echo '
$cardMatch: ' . print_r( $cardMatch, true ) . '
'; + // echo '
$paymentData: ' . print_r( $paymentData, true ) . '
'; + // exit; + + // Check all credit card input + if ( + $cardData['cc_type'] && $cardData['cc_type'] > 0 && + $cardData['cc_name'] && $cardData['cc_name'] != '' && + $cardData['cc_numb'] && $cardData['cc_numb'] > 0 && + $cardData['cc_exp'] && $cardData['cc_exp'] != '' && + $cardData['cc_cvv'] && $cardData['cc_cvv'] > 0 + ) { + + if (!isset($this->config['credit_card_match'][$cardData['cc_type']]) || + !preg_match($this->config['credit_card_match'][$cardData['cc_type']], $cardData['cc_numb']) + ) { + $messages[] = 'The credit card number you entered does not match the selected type of credit card.'; + } - if (count($messages) == 0) { - - // Determine the directory of the payment processor to load and instatiate it. - if ($ccProcessor && isset($this->config['proc_dir'][$ccProcessor])) { - require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_LIB_PATH.'/paymentProcessors/'.$this->config['proc_dir'][$ccProcessor].'/paymentGateway.php'; - $CcProcessor = new PaymentGateway($account); - } - - $payment = array( - 'name' => $this->config['settings']['reg_org_name'], // Name of venue - 'charge' => $this->cart['totalCharges'], // Total charges - 'cctype' => $cardData['cc_type'], // Card Type - 'ccname' => $cardData['cc_name'], // Name on Card - 'ccnumb' => $cardData['cc_numb'], // Card Number - 'ccexp' => $cardData['cc_exp'], // Expiration Date - 'cccode' => $cardData['cc_cvv'], // CCV - security code - 'invoice' => 'reg-'.$_SESSION['glm_reg_cart_id'] // Invoice # is "reg-" plus cart ID - ); - - // Now try to run the card processor - $ccResult = $CcProcessor->processPayment($payment, $billing); - - // If successful submission - say we're complete - if (is_array($ccResult) && isset($ccResult['status']) && $ccResult['status'] == 1) { - - $cartStatus = $this->config['submission_status_numb']['COMPLETE']; - - // Store Credit Card information - $cc_numb_store = '....'.substr($payment['ccnumb'], -4); - $reqData = array_merge( - $reqData, - array( - 'cc_type' => $payment['cctype'], - 'cc_name' => $payment['ccname'], - 'cc_numb' => $cc_numb_store, - 'cc_exp' => $payment['ccexp'], - 'cc_conf' => $ccConfirmation, - ) - ); - $reqFormat = array_merge( - $reqFormat, - array( - '%d', - '%s', - '%s', - '%s', - '%s', - ) - ); - - } + } else { + $messages[] = 'You did not supply all required credit card information.'; + } - } + if (count($messages) == 0) { - break; + // Determine the directory of the payment processor to load and instatiate it. + if ($ccProcessor && isset($this->config['proc_dir'][$ccProcessor])) { + require_once GLM_MEMBERS_BILLING_PLUGIN_LIB_PATH.'/paymentProcessors/'.$this->config['proc_dir'][$ccProcessor].'/paymentGateway.php'; + $CcProcessor = new PaymentGateway($account); + } - // Pay Pal - // case $this->config['payment_method_numb']['PayPal']: - // break; + $payment = array( + 'name' => $this->config['settings']['company_name'], // Company Name + 'charge' => $paymentData['amount'], // Total charges + 'cctype' => $cardData['cc_type'], // Card Type + 'ccname' => $cardData['cc_name'], // Name on Card + 'ccnumb' => $cardData['cc_numb'], // Card Number + 'ccexp' => $cardData['cc_exp'], // Expiration Date + 'cccode' => $cardData['cc_cvv'], // CCV - security code + 'invoice' => 'billing-'.$paymentData['invoice_id'] // Invoice # is "reg-" plus cart ID + ); + + // Now try to run the card processor + $ccResult = $CcProcessor->processPayment($payment, $billing); + // echo '
ccResult: ' . print_r( $ccResult, true ) . '
'; + + // If successful submission - say we're complete + if (is_array($ccResult) && isset($ccResult['status']) && $ccResult['status'] == 1) { + // Need to record the payment + + // Support class + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + + // Set transaction_time to current time. + $_REQUEST['transaction_time'] = date('Y-m-d H:i:s'); + // Create new payment. + $payment_id = $BillingSupport->createPayment( $paymentData['account_id'], $paymentData['amount'] ); + // Record the payment. + $BillingSupport->recordPayment( $payment_id, $paymentData['account_id'], $paymentData['amount'] ); + + $messages[] = $ccResult['statusText']; + $messages[] = $ccResult['description']; - // Payment Method unknown - default: - $payMethod = false; - $messages[] = "I'm sorry, we couldn't tell which payment method you wanted to use. Please select one under \"Payment Information\" below."; - break; + } } + // echo '
$messages: ' . print_r( $messages, true ) . '
'; + break; case 'makepayment': + // Load DataClass for accounts. require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); + // Load DataClass for Management. + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php'; + $Management = new GlmDataBillingManagement( $this->wpdb, $this->config ); + $management = $Management->getEntry( 1 ); + + // Need to see if there's an account for this member. $accountID = $this->wpdb->get_var( @@ -393,20 +419,29 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $this->memberID ) ); - $account = $Accounts->getEntry( $accountID ); + $account = $Accounts->editEntry( $accountID ); + + // Support class + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + + // Get unpaid invoices + $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] ); + // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; + if ( !empty( $invoices ) ) { + foreach ( $invoices as &$invoice ) { + $invoice['due_date'] = date( 'n/d/Y', strtotime( $invoice['due_date'] ) ); + } + } + $cc_accepts = $this->config['billing_settings']['cc_accepts']; + // echo '
$cc_accepts: ' . print_r( $cc_accepts, true ) . '
'; // Set the file name for the view file. $view = 'makePayment'; // echo '
$account: ' . print_r( $account, true ) . '
'; - // Set this to CreditCard - $payMethod = $this->config['payment_method_numb']['CreditCard']; - - - break; case 'list': - $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config); + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); $view = 'statements'; // Get the list of invoices for this member. $statements = $BillingSupport->getStatementsByRefDest( $this->memberID ); @@ -441,6 +476,10 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling 'balance_due' => $balance_due, 'transaction_types' => $this->config['transaction_type'], 'invoiceHtml' => $invoiceHtml, + 'billing_settings' => $this->config['billing_settings'], + 'management' => $management, + 'messages' => $messages, + 'invoices' => $invoices, ); // Return status, any suggested view, and any data to controller. diff --git a/setup/databaseScripts/create_database_V0.0.9.sql b/setup/databaseScripts/create_database_V0.0.10.sql similarity index 98% rename from setup/databaseScripts/create_database_V0.0.9.sql rename to setup/databaseScripts/create_database_V0.0.10.sql index 34b8906..729ef67 100644 --- a/setup/databaseScripts/create_database_V0.0.9.sql +++ b/setup/databaseScripts/create_database_V0.0.10.sql @@ -14,6 +14,8 @@ CREATE TABLE {prefix}accounts ( id INT NOT NULL AUTO_INCREMENT, ref_dest INT NOT NULL, -- reference to member id ref_name TINYTEXT NOT NULL, -- Name of reference member + billing_fname TINYTEXT NULL, -- Billing First Name + billing_lname TINYTEXT NULL, -- Billing Last Name billing_addr1 TINYTEXT NULL, -- Billing Address 1 billing_addr2 TINYTEXT NULL, -- Billing Address 2 billing_city TINYTEXT NULL, -- Billing City diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index e8905e9..4a7b504 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -23,5 +23,6 @@ $glmMembersBillingDbVersions = array( '0.0.7' => array('version' => '0.0.7', 'tables' => 13), '0.0.8' => array('version' => '0.0.8', 'tables' => 14), '0.0.9' => array('version' => '0.0.9', 'tables' => 14), + '0.0.10' => array('version' => '0.0.10', 'tables' => 14), ); diff --git a/setup/databaseScripts/update_database_V0.0.10.sql b/setup/databaseScripts/update_database_V0.0.10.sql new file mode 100644 index 0000000..fa9f259 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.10.sql @@ -0,0 +1,14 @@ +-- Gaslight Media Billing Database +-- File Created: 03/06/2018 +-- Database Version: 0.0.10 +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Add billing_fname field to the accounts table +ALTER TABLE {prefix}accounts ADD billing_fname TINYTEXT NULL; + +---- + +-- Add billing_lname field to the accounts table +ALTER TABLE {prefix}accounts ADD billing_lname TINYTEXT NULL; diff --git a/views/admin/billing/editAccount.html b/views/admin/billing/editAccount.html index 147909d..8351960 100644 --- a/views/admin/billing/editAccount.html +++ b/views/admin/billing/editAccount.html @@ -55,6 +55,22 @@ + + Billing First Name + + + {if $account.fieldFail.billing_fname}

{$account.fieldFail.billing_fname}

{/if}
+ + + + + Billing Last Name + + + {if $account.fieldFail.billing_lname}

{$account.fieldFail.billing_lname}

{/if}
+ + + Billing Address 1 @@ -82,7 +98,14 @@ Billing State - + {if $account.fieldFail.billing_state}

{$account.fieldFail.billing_state}

{/if}
diff --git a/views/admin/billing/editInvoice.html b/views/admin/billing/editInvoice.html index 34607d5..940b475 100644 --- a/views/admin/billing/editInvoice.html +++ b/views/admin/billing/editInvoice.html @@ -23,6 +23,7 @@ Billing Account
+ +
-
+
-
Select Invoice
- Need to list unpaid invoices here... +

Billing Information

-
Amount
-
- +
Billing First Name
+
+
-
Billing Address 1
-
- +
Billing Last Name
+
+
+
-
Billing Address 2
-
- +
Billing Address 1
+
+
-
Billing City
-
- +
Billing Address 2
+
+
-
Billing State
-
- +
Billing City
+
+ +
+
+ +
+
Billing State
+
+ +
+
+ +
+
Billing Zip
+
+
-
Billing Zip
+
Billing Email
+
+ +
+
+ +
+
Billing Phone
+
+ +
+
+ +
+ {if $invoices} +
+
- +

Payment Information

+
Select Invoice
+ +
+
+ +
+
Amount
+
+ +
+
+ +
+
Name on Card
+
+ +
+
+ +
+
Card Type
+
+ +
+
+ +
+
Card Number
+
+ +
+
+ +
+
Card Expiration
+
+ +
+
+ +
+
C V V
+
+ +
+
+ + +
+
+ {else} + You don't have any unpaid invoices! + {/if}
diff --git a/views/admin/billing/paymentProcess.html b/views/admin/billing/paymentProcess.html index 09ea881..ed62455 100644 --- a/views/admin/billing/paymentProcess.html +++ b/views/admin/billing/paymentProcess.html @@ -1,6 +1,11 @@ {include file='admin/member/header.html'} {include file='admin/billing/memberBillingSubHeader.html'} -Payment process here !! +{if $messages} + {foreach $messages as $message} + {$message}
+ {/foreach} +{/if} + {include file='admin/footer.html'} -- 2.17.1