WIP renewal payment processing.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 27 Mar 2018 20:41:31 +0000 (16:41 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 27 Mar 2018 20:41:31 +0000 (16:41 -0400)
Create the invoice,
Process Payment,
mark invoice paid and add payment.

classes/billingSupport.php
css/admin.css
models/admin/member/billing.php
views/admin/billing/renew.html

index 353aab3..dbe3dc8 100644 (file)
@@ -769,6 +769,19 @@ class GlmBillingSupport
         );
     }
 
+    public function getAllPayableInvoiceTypes()
+    {
+        return $this->wpdb->get_results(
+            "SELECT *
+               FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+              WHERE amount > 0
+                AND recurring
+                AND recurrence = 20
+            ORDER BY name",
+            ARRAY_A
+        );
+    }
+
     public function getListOfAccountEmployees( $member_id )
     {
         $accounts = array();
@@ -782,7 +795,7 @@ class GlmBillingSupport
             if ( $invoice_type_id ) {
                 $invoice = $this->getInvoicTypeById( $invoice_type_id );
             }
-            $accounts[] = array(
+            $accounts[$billing_account['id']] = array(
                 'id'       => $billing_account['id'],
                 'ref_dest' => $billing_account['ref_dest'],
                 'ref_name' => $billing_account['ref_name'],
@@ -797,6 +810,7 @@ class GlmBillingSupport
     {
         // Make sure the required parts of $invoice_data exists.
         if ( !isset( $invoice_data['account_id'] )
+            || !isset( $invoice_data['renew_type_id'] )
             || !isset( $invoice_data['amount'] )
             || !isset( $invoice_data['due_date'] )
             || !isset( $invoice_data['member_invoice'] )
@@ -834,25 +848,41 @@ class GlmBillingSupport
         );
         $invoice_id = $this->wpdb->insert_id;
         // Add the line item for from the member invoice
+        // First get this invoice_type
+        $new_member_invoice_type = $this->getInvoicTypeById( $renew_type_id );
         $this->createLineItemForInvoice(
             array(
                 'invoice_id'     => $invoice_id,
-                'line_item_type' => $member_invoice['id'],
-                'name'           => $member_invoice['name'],
-                'amount'         => $member_invoice['amount'],
+                'line_item_type' => $new_member_invoice_type['id'],
+                'name'           => $new_member_invoice_type['name'],
+                'amount'         => $new_member_invoice_type['amount'],
                 'due_date'       => $due_date,
-                'recurring'      => $recurring,
-                'recurrence'     => $recurrence,
+                'recurring'      => $new_member_invoice_type['recurring'],
+                'recurrence'     => $new_member_invoice_type['recurrence'],
             )
         );
+        // echo '<pre>$invoice_id: ' . print_r( $invoice_id, true ) . '</pre>';
         if ( $invoice_id ) {
             // Add line items for each employee.
-            foreach ( $employees as $ref_dest ) {
-                // Get the account from the ref_dest.
-                $line_account_id = $this->getAccountByRefDest( $ref_dest );
-
+            foreach ( $employees as $account_id ) {
+                if ( $employee_data[$account_id]['invoice'] ) {
+                    $this->createLineItemForInvoice(
+                        array(
+                            'invoice_id'     => $invoice_id,
+                            'line_item_type' => $employee_data[(int)$account_id]['invoice']['id'],
+                            'name'           => $employee_data[(int)$account_id]['invoice']['name'],
+                            'amount'         => $employee_data[(int)$account_id]['invoice']['amount'],
+                            'due_date'       => $due_date,
+                            'recurring'      => $employee_data[(int)$account_id]['invoice']['recurring'],
+                            'recurrence'     => $employee_data[(int)$account_id]['invoice']['recurrence'],
+                        )
+                    );
+                }
             }
         }
+        // Calling the support class to save the invoice to transaction table.
+        $this->recordInvoice( $invoice_id, $account_id, $amount );
+        return $invoice_id;
     }
 
     public function createLineItemForInvoice( $data )
@@ -895,11 +925,158 @@ class GlmBillingSupport
                 '%s', // created
                 '%s', // first_due_date
                 '%s', // next_due_date
-                '%d', // recurring
+                '%s', // recurring
                 '%d', // recurrence
             )
         );
     }
 
+    public function processMemberRenewal( $account_id, $invoice_id, $amount )
+    {
+        $errors = array();
+        // Get the selected credit card processor type
+        $ccProcessor = $this->config['billing_settings']['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['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']
+            );
+
+            break;
+
+        case $this->config['proc_method_numb']['MerchantSolutions']:
+
+            // 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']
+            );
+
+            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 = 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,
+            )
+        );
+
+        $paymentData = filter_var_array(
+            $_REQUEST,
+            array(
+                'billing_fname' => FILTER_SANITIZE_STRING,
+                'billing_lname' => FILTER_SANITIZE_STRING,
+                '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,
+                'email'         => FILTER_SANITIZE_STRING,
+            )
+        );
+
+        // 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['billing_phone'],
+            'email'   => $paymentData['email']
+        );
+        $cardMatch = $this->config['credit_card_match'];
+
+        // 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'])
+            ) {
+                $errors[] = 'The credit card number you entered does not match the selected type of credit card.';
+            }
+
+        } else {
+            $errors[] = 'You did not supply all required credit card information correctly.';
+        }
+
+        if (count($errors) == 0) {
+
+            // Determine the directory of the payment processor to load and instantiate 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);
+            }
+
+            $payment = array(
+                'name'    => $this->config['settings']['company_name'],  // Company Name
+                'charge'  => $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);
+
+            // If successful submission - say we're complete
+            if (is_array($ccResult) && isset($ccResult['status']) && $ccResult['status'] == 1) {
+                // Need to record the payment
+
+                // Set transaction_time to current time.
+                $_REQUEST['transaction_time'] = date('Y-m-d H:i:s');
+                // Create new payment.
+                $payment_id = $this->createPayment( $account_id, $amount );
+                // Record the payment.
+                $this->recordPayment( $payment_id, $account_id, $amount, $invoice_id );
+
+                $errors[] = $ccResult['statusText'];
+                $errors[] = $ccResult['description'];
+
+            }
+
+        }
+
+        return $errors;
+
+    }
+
 }
 
index a39ce51..192bd16 100644 (file)
     border-radius: 5px;
     padding: 20px;
 }
+
+/* glm-billing-form */
+.glm-billing-form {
+    max-width: 750px;
+}
+.glm-billing-field {
+    width: 100%;
+}
+.glm-billing-label {
+    font-size: 1rem;
+    padding: 7px 0 3px;
+}
+.glm-billing-input {
+    font-size: 1rem;
+    padding: 3px 0;
+}
+.glm-billing-input label {
+    width: 100%;
+    display: block;
+}
index 4e35163..afa64b4 100644 (file)
@@ -122,6 +122,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
         $hasBillingAccount  = false;
         $employees          = false;
         $member_invoice     = false;
+        $payable_types     = false;
 
         // For lockedToMember.
         $lockedToMember = false;
@@ -180,44 +181,112 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
         case 'renew':
             $view = 'renew';
 
+            // Get list of payable invoice_types
+            $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+            // echo '<pre>$payable_types: ' . print_r( $payable_types, true ) . '</pre>';
+
             $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
-            // echo '<pre>$member_invoice_id: ' . print_r( $member_invoice_id, true ) . '</pre>';
             if ( $member_invoice_id ) {
                 $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id );
             }
-
             // echo '<pre>$member_invoice: ' . print_r( $member_invoice, true ) . '</pre>';
-            $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
-            // echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
 
             // Get a list of this accounts employees. If they have any.
+            $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+
+            // 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.
+            require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
+            $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+            $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->editEntry( $accountID );
 
             break;
 
         case 'renewMembership':
-            $view = 'renewMembership';
+            $error = false;
+            $view  = 'renewMembership';
             $messages[] = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
 
             $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
             if ( $member_invoice_id ) {
                 $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id );
+            } else {
+                $error = true;
             }
-            $messages[] = '<pre>$member_invoice: ' . print_r( $member_invoice, true ) . '</pre>';
 
             $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
-            $messages[] = '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
 
             $invoice_data = array(
                 'account_id'     => filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT ),
-                'amount'         => filter_var( $_REQUEST['total_renew_amount'], FILTER_VALIDATE_STRING ),
+                'renew_type_id'  => filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ),
+                'amount'         => $_REQUEST['total_renew_amount'],
                 'due_date'       => date( 'Y-m-d' ),
                 'member_invoice' => $member_invoice,
                 'employee_data'  => $employees,
                 'employees'      => $_REQUEST['employees']
             );
-            $messages[] = '<pre>$invoice_data: ' . print_r( $invoice_data, true ) . '</pre>';
+            if ( !$invoice_data ) {
+                $error = true;
+            }
 
             // Create the invoice for this member.
+            $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data );
+            if ( !$invoice_id ) {
+                $error = true;
+            }
+
+            // Now that the invoice is created. Do payment Processing.
+
+            // If there's any errors then re-show the form.
+            if ( $error ) {
+                // TODO: Here we'll need to remove the invoice created if any.
+                $view = 'renew';
+
+                // Get list of payable invoice_types
+                $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+
+                $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+                if ( $member_invoice_id ) {
+                    $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id );
+                }
+
+                // Get a list of this accounts employees. If they have any.
+                $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+
+                // 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.
+                require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
+                $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+                $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->editEntry( $accountID );
+            } else {
+                // Do the Payment Processing.
+                $errors = $BillingSupport->processMemberRenewal( $invoice_data['account_id'], $invoice_id, $invoice_data['amount'] );
+                echo '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
+            }
 
 
             break;
@@ -288,189 +357,12 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
             $view = 'paymentProcess';
 
-            // Get the selected credit card processor type
-            $ccProcessor = $this->config['billing_settings']['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['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']
-                    );
+            // MOVING TO billing support class
+            // $payment_status = $BillingSupport->processMemberRenewal();
 
-                    break;
+            // if error
 
-                case $this->config['proc_method_numb']['MerchantSolutions']:
 
-                    // 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']
-                    );
-
-                    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 = 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,
-                )
-            );
-
-            $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_fname' => FILTER_SANITIZE_STRING,
-                    'billing_lname' => FILTER_SANITIZE_STRING,
-                    '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,
-                    'email'         => FILTER_SANITIZE_STRING,
-                )
-            );
-
-            // 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['billing_phone'],
-                'email'   => $paymentData['email']
-            );
-            $cardMatch = $this->config['credit_card_match'];
-
-            // 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 correctly.';
-            }
-
-            if (count($messages) == 0) {
-                $paymentSuccess = true;
-
-                // 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);
-                }
-
-                $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);
-
-                // If successful submission - say we're complete
-                if (is_array($ccResult) && isset($ccResult['status']) && $ccResult['status'] == 1) {
-                    // Need to record the payment
-
-                    // 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'], $paymentData['invoice_id'] );
-
-                    $messages[] = $ccResult['statusText'];
-                    $messages[] = $ccResult['description'];
-
-                }
-
-            } else {
-                $paymentError = true;
-                // 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(
-                    $this->wpdb->prepare(
-                        "SELECT id
-                           FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
-                          WHERE ref_dest = %d",
-                        $this->memberID
-                    )
-                );
-                $account = $Accounts->editEntry( $accountID );
-
-                // Get unpaid invoices
-                $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
-                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'];
-
-                // Set the file name for the view file.
-                $view = 'makePayment';
-
-                // TODO: make sure the existing field data get setup in the form.
-            }
 
             break;
 
@@ -558,6 +450,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             'hasBillingAccount'  => $hasBillingAccount,
             'employees'          => $employees,
             'member_invoice'     => $member_invoice,
+            'payable_types'      => $payable_types,
         );
 
         // Return status, any suggested view, and any data to controller.
index ab4f35c..c769e90 100644 (file)
@@ -1,7 +1,8 @@
 {include file='admin/member/header.html'}
 {include file='admin/billing/memberBillingSubHeader.html'}
 
-<div id="billing-payment-form" style="max-width:750px;">
+<h3>Membership Renewal</h3>
+<div id="billing-payment-form" class="glm-billing-form">
 
     {if $paymentSuccess}<span class="glm-notice glm-flash-updated">Payment Completed</span>{/if}
     {if $paymentError}<span class="glm-notice glm-flash-updated">Error With Payment</span>{/if}
@@ -11,9 +12,8 @@
             <div class="">{$message}</div>
         {/foreach}
     {/if}
-<h3>Renew membership</h3>
 
-    <form action="{$thisUrl}?page={$thisPage}&glm_action=billing&option=makePayment" method="post">
+    <form action="{$thisUrl}?page={$thisPage}" method="post">
         <input type="hidden" name="page" value="{$thisPage}" />
         <input type="hidden" name="glm_action" value="billing" />
         <input type="hidden" name="option" value="renewMembership" />
         <input type="hidden" name="account_id" value="{$account_data.id}" />
         <input type="hidden" id="total_renew_amount" name="total_renew_amount" value="" />
 
-        <h4>Employees:</h4>
 
         {if $member_invoice}
-        <div>
-            <label>
-                <input type="checkbox" name="member_renewing" data-amount="{$member_invoice.amount}" value="{$account_data.id}" checked disabled>{$account_data.ref_name}
-                {$member_invoice.name}
-                {$member_invoice.amount}
-            </label>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label">
+                Member Renewing
+            </div>
+            <div class="glm-billing-input">
+                <label>
+                    {$account_data.ref_name}
+
+                    {foreach $payable_types as $type}
+                        <label>
+                            <input type="radio" name="member_renewing" data-amount="{$type.amount}" value="{$type.id}"
+                            {if $type.id == $member_invoice.id}checked{/if}
+                            />
+                            {$type.name} {$type.amount}
+                        </label>
+                    {/foreach}
+                </label>
+            </div>
         </div>
         {/if}
 
-        {foreach $employees as $employee}
-            <div>
-                <label>
-                    <input
-                    type="checkbox"
-                    name="employees[]"
-                    data-amount="{$employee.invoice.amount}"
-                    value="{$employee.id}"
-                    checked='checked'>{$employee.ref_name}
-                    {$employee.invoice.name}
-                    {$employee.invoice.amount}
-                </label>
+        {if $employees}
+            <div class="glm-billing-field">
+                <div class="glm-billing-label">
+                    Employees to Renew
+                </div>
+                <div class="glm-billing-input">
+                    {foreach $employees as $employee}
+                        <label>
+                            <input type="checkbox" name="employees[]" data-amount="{$employee.invoice.amount}" value="{$employee.id}" checked='checked' />
+                            {$employee.ref_name} {$employee.invoice.name} {$employee.invoice.amount}
+                        </label>
+                    {/foreach}
+                </div>
             </div>
-        {/foreach}
+        {/if}
+
+        <div class="glm-billing-field">
+            <div class="glm-billing-label">
+                Total Due
+            </div>
+            <div class="glm-billing-input">
+                <div id="renew_total">
+                </div>
+            </div>
+        </div>
+
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                First Name
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_fname" value="{$account.fieldData.billing_fname}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Last Name
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_lname" value="{$account.fieldData.billing_lname}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Address
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_addr1" value="{$account.fieldData.billing_addr1}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                City
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_city" value="{$account.fieldData.billing_city}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                State / Province
+            </div>
+            <div class="glm-billing-input">
+                <select name="billing_state" required>
+                    <option value=""></option>
+                    {foreach $account.fieldData.billing_state.list as $s}
+                        <option value="{$s.value}"{if $account.fieldData.billing_state.value == $s.value} selected="selected"{/if}>
+                            {$s.name}
+                        </option>
+                    {/foreach}
+                </select>
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Zip
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_zip" value="{$account.fieldData.billing_zip}" required />
+            </div>
+        </div>
 
-        <div id="renew_total">
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Name on Card
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    type="text"
+                    name="cc_name"
+                    required
+                    {if isset($smarty.request.cc_name) && $smarty.request.cc_name}value="{$smarty.request.cc_name}"{/if} />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Card Type
+            </div>
+            <div class="glm-billing-input">
+                <select name="cc_type" required>
+                    <option value=""></option>
+                    {foreach $management.cc_accepts.names as $cardId => $cardName}
+                        <option value="{$cardId}"
+                        {if isset($smarty.request.cc_type) && $smarty.request.cc_type == $cardId} selected{/if}>{$cardName}</option>
+                    {/foreach}
+                </select>
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Card Number
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    type="text"
+                    placeholder="Numbers Only"
+                    name="cc_numb"
+                    required
+                    pattern="\d*"
+                    {if isset($smarty.request.cc_numb) && $smarty.request.cc_numb}value="{$smarty.request.cc_numb}"{/if} />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Card Expiration
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    type="text"
+                    placeholder="MM/YY"
+                    name="cc_exp"
+                    required
+                    pattern="{literal}\d{2}/\d{2}{/literal}"
+                    {if isset($smarty.request.cc_exp) && $smarty.request.cc_exp}value="{$smarty.request.cc_exp}"{/if} />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+            C V V
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    type="text"
+                    placeholder="3 or 4 digit security code on back of card"
+                    name="cc_cvv"
+                    required
+                    pattern="{literal}\d{3,4}{/literal}"
+                    {if isset($smarty.request.cc_cvv) && $smarty.request.cc_cvv}value="{$smarty.request.cc_cvv}"{/if} />
+            </div>
         </div>
 
-        <input class="button button-primary" type="submit" value="Renew Memberships">
+        <input class="button button-primary" type="submit" value="Renew">
 
     </form>
 </div>
@@ -68,7 +212,7 @@ jQuery(document).ready(function($){
 
         // Calculate the total for this page.
         // Get the member_renewing amount.
-        var member_renewing_amount = parseFloat( $('input[name=member_renewing]').data('amount') );
+        var member_renewing_amount = parseFloat( $('input[name=member_renewing]:checked').data('amount') );
 
         // Get each employee and add their amounts.
         $('input[name^=employees]').each(function(){
@@ -84,6 +228,11 @@ jQuery(document).ready(function($){
 
     getPageTotal();
 
+    // trigger total if changing Membership
+    $('input[name=member_renewing]').change(function(){
+        getPageTotal();
+    });
+
     // trigger total if changing employees
     $('input[name^=employees]').change(function(){
         getPageTotal();