From 9236016ec8e0a21c818981565eac2f79ae9acb07 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 2 Mar 2018 16:45:48 -0500 Subject: [PATCH] Adding billing payment form This is for the member to make a payment. --- index.php | 6 +- models/admin/member/billing.php | 183 +++++++++++++++++- .../create_database_V0.0.9.sql | 2 +- views/admin/billing/invoiceStore.html | 2 +- views/admin/billing/makePayment.html | 75 +++++++ .../admin/billing/memberBillingSubHeader.html | 7 +- views/admin/billing/paymentProcess.html | 6 + views/admin/billing/statements.html | 2 +- views/admin/billing/viewInvoice.html | 6 - 9 files changed, 270 insertions(+), 19 deletions(-) create mode 100644 views/admin/billing/makePayment.html create mode 100644 views/admin/billing/paymentProcess.html diff --git a/index.php b/index.php index 52b6a8b..892b8d6 100644 --- a/index.php +++ b/index.php @@ -148,6 +148,9 @@ if (is_file(GLM_MEMBERS_BILLING_PLUGIN_DB_SCRIPTS.'/dbVersions.php')) { $glmMembersBillingSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX."settings WHERE id = 1", ARRAY_A ); unset($glmMembersBillingSettings['id']); +$glmMembersBillingManagement = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX."management WHERE id = 1", ARRAY_A ); +unset($glmMembersBillingManagement['id']); + function glmMembersBillingRegisterAddOn($addOns) { // Add this add-on to the add-ons array @@ -158,7 +161,8 @@ function glmMembersBillingRegisterAddOn($addOns) { 'slug' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'actions' => $GLOBALS['glmMembersBillingAddOnValidActions'], 'config' => array( - 'settings' => $GLOBALS['glmMembersBillingSettings'] + 'settings' => $GLOBALS['glmMembersBillingSettings'], + 'billing_settings' => $GLOBALS['glmMembersBillingManagement'], ), 'shortcodes' => $GLOBALS['glmMembersBillingShortcodes'], 'shortcodesDescription' => $GLOBALS['glmMembersBillingShortcodesDescription'] diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index b9fb255..8e20bc8 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -226,22 +226,195 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // Set the file name for the view file. $view = 'viewInvoice'; + break; + case 'createPayment': + + echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + + $view = 'paymentProcess'; + + 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['settings']['reg_proc_methods']; + + // Setup the required account information for the selected payment processor + switch ($ccProcessor) { + + 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; + + case $this->config['proc_method_numb']['MerchantSolutions']: + + // 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'] + ); + + 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 + ) { + + + 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.'; + } + + } else { + $messages[] = 'You did not supply all required credit card information.'; + } + + 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', + ) + ); + + } + + } + + break; + + // Pay Pal + // case $this->config['payment_method_numb']['PayPal']: + // break; + + // 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; + + } + break; + case 'makepayment': + + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; + $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); + + // Need to see if there's an account for this member. + $accountID = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE ref_dest = %d", + $this->memberID + ) + ); + $account = $Accounts->getEntry( $accountID ); + + // 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); $view = 'statements'; // Get the list of invoices for this member. - // echo '
$this->memberID: ' . print_r( $this->memberID, true) . '
'; - // echo '
$memberData: ' . print_r( $memberData, true) . '
'; $statements = $BillingSupport->getStatementsByRefDest( $this->memberID ); if ( $statements ) { $transactions = $statements['transactions']; $account_data = $statements['account_data']; $balance_due = $statements['balance_due']; } - // echo '
$statements: ' . print_r( $statements, true ) . '
'; - - break; } // echo '
$this->config: ' . print_r( $this->config, true ) . '
'; diff --git a/setup/databaseScripts/create_database_V0.0.9.sql b/setup/databaseScripts/create_database_V0.0.9.sql index f9e859e..34b8906 100644 --- a/setup/databaseScripts/create_database_V0.0.9.sql +++ b/setup/databaseScripts/create_database_V0.0.9.sql @@ -212,7 +212,7 @@ INSERT INTO {prefix}settings CREATE TABLE {prefix}management ( id INT NOT NULL AUTO_INCREMENT, payment_methods SMALLINT NULL, -- Payment methods available for all registrations - Bitmap - see payment_method in plugin.ini - proc_methods SMALLINT NULL, -- Creadit Cart payment processing methods available - Bitmap - see proc_method in plugin.ini + proc_methods SMALLINT NULL, -- Credit Cart payment processing methods available - Bitmap - see proc_method in plugin.ini cc_accepts SMALLINT NULL, -- Credit Cards Accepted - Bitmap - See credit_card in plugin.ini -- Authorize.net Credentials authorize_net_login TINYTEXT NULL, diff --git a/views/admin/billing/invoiceStore.html b/views/admin/billing/invoiceStore.html index 6a71da0..82081fc 100644 --- a/views/admin/billing/invoiceStore.html +++ b/views/admin/billing/invoiceStore.html @@ -149,7 +149,7 @@ Payment Amount: - + ________ Account #: diff --git a/views/admin/billing/makePayment.html b/views/admin/billing/makePayment.html new file mode 100644 index 0000000..430e2e4 --- /dev/null +++ b/views/admin/billing/makePayment.html @@ -0,0 +1,75 @@ +{include file='admin/member/header.html'} +{include file='admin/billing/memberBillingSubHeader.html'} + +
+
+ + + + + +
+
+ +
+
Select Invoice
+
+ Need to list unpaid invoices here... +
+
+ +
+
Amount
+
+ +
+
+ +
+
Billing Address 1
+
+ +
+
+ +
+
Billing Address 2
+
+ +
+
+ +
+
Billing City
+
+ +
+
+ +
+
Billing State
+
+ +
+
+ +
+
Billing Zip
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +{include file='admin/footer.html'} diff --git a/views/admin/billing/memberBillingSubHeader.html b/views/admin/billing/memberBillingSubHeader.html index 851366b..c54db63 100644 --- a/views/admin/billing/memberBillingSubHeader.html +++ b/views/admin/billing/memberBillingSubHeader.html @@ -1,6 +1,5 @@ diff --git a/views/admin/billing/paymentProcess.html b/views/admin/billing/paymentProcess.html new file mode 100644 index 0000000..09ea881 --- /dev/null +++ b/views/admin/billing/paymentProcess.html @@ -0,0 +1,6 @@ +{include file='admin/member/header.html'} +{include file='admin/billing/memberBillingSubHeader.html'} + +Payment process here !! + +{include file='admin/footer.html'} diff --git a/views/admin/billing/statements.html b/views/admin/billing/statements.html index 3bec960..390ff70 100644 --- a/views/admin/billing/statements.html +++ b/views/admin/billing/statements.html @@ -24,7 +24,7 @@ {$transaction.transaction_data.due_date|date_format:"%D"} {$transaction_types[$transaction.type]} ${$transaction.transaction_data.amount_total} - View / Make Payment + View {elseif $transaction.type == '20'} {$transaction.transaction_data.transaction_time|date_format:"%D"} diff --git a/views/admin/billing/viewInvoice.html b/views/admin/billing/viewInvoice.html index e2f76ba..a799c26 100644 --- a/views/admin/billing/viewInvoice.html +++ b/views/admin/billing/viewInvoice.html @@ -1,7 +1,6 @@ {if $fromMemberMenu} {include file='admin/member/header.html'} {include file='admin/billing/memberBillingSubHeader.html'} -
{else} {include file='admin/billing/header.html'} {include file='admin/billing/subHeader.html'} @@ -12,11 +11,6 @@ {$invoiceHtml} -{if $fromMemberMenu} - Make a Payment -
-{else} -{/if}