Update payment form for validation.
authorSteve Sutton <ssutton@gmail.com>
Sun, 11 Mar 2018 11:19:10 +0000 (07:19 -0400)
committerSteve Sutton <ssutton@gmail.com>
Sun, 11 Mar 2018 11:19:10 +0000 (07:19 -0400)
Adding some validation into the htm5 markup in the form.

models/admin/member/billing.php
views/admin/billing/makePayment.html

index 5576f4b..ea45795 100644 (file)
@@ -233,13 +233,8 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             break;
         case 'createPayment':
 
-            // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
-
             $view = 'paymentProcess';
 
-            // echo '<pre>$this->config: ' . print_r( $this->config, true ) . '</pre>';
-            // Execute selected payment method
-
             // Get the selected credit card processor type
             $ccProcessor = $this->config['billing_settings']['proc_methods'];
 
@@ -282,8 +277,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
             }
 
-            // echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
-
             // Get the credit card input
             $cardData = filter_var_array(
                 $_REQUEST,
@@ -327,21 +320,15 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 'phone'   => $paymentData['bill_phone'],
                 'email'   => $paymentData['email']
             );
-            // echo '<pre>$cardData: ' . print_r( $cardData, true ) . '</pre>';
             $cardMatch = $this->config['credit_card_match'];
-            // echo '<pre>$cardMatch: ' . print_r( $cardMatch, true ) . '</pre>';
-            // echo '<pre>$paymentData: ' . print_r( $paymentData, true ) . '</pre>';
-            // 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 ( $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'])
                 ) {
@@ -349,7 +336,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 }
 
             } else {
-                $messages[] = 'You did not supply all required credit card information.';
+                $messages[] = 'You did not supply all required credit card information correctly.';
             }
 
             if (count($messages) == 0) {
@@ -373,7 +360,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
                 // Now try to run the card processor
                 $ccResult = $CcProcessor->processPayment($payment, $billing);
-                // echo '<pre>ccResult: ' . print_r( $ccResult, true ) . '</pre>';
 
                 // If successful submission - say we're complete
                 if (is_array($ccResult) && isset($ccResult['status']) && $ccResult['status'] == 1) {
@@ -394,8 +380,45 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
                 }
 
+            } else {
+                // 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 );
+
+                // Support class
+                $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+
+                // 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.
             }
-            // echo '<pre>$messages: ' . print_r( $messages, true ) . '</pre>';
 
             break;
         case 'makepayment':
@@ -403,13 +426,12 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             // 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(
@@ -434,10 +456,9 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             }
 
             $cc_accepts = $this->config['billing_settings']['cc_accepts'];
-            // echo '<pre>$cc_accepts: ' . print_r( $cc_accepts, true ) . '</pre>';
+
             // Set the file name for the view file.
             $view = 'makePayment';
-            // echo '<pre>$account: ' . print_r( $account, true ) . '</pre>';
 
             break;
         case 'list':
index 5818b7d..e578b70 100644 (file)
@@ -1,6 +1,13 @@
 {include file='admin/member/header.html'}
 {include file='admin/billing/memberBillingSubHeader.html'}
 
+{if $messages}
+    {foreach $messages as $message}
+        <div class="">{$message}</div>
+    {/foreach}
+{/if}
+
+
 <div id="billing-payment-form" style="max-width:750px;">
     <form action="{$thisUrl}?page={$thisPage}&glm_action=billing&option=makePayment" method="post">
         <input type="hidden" name="page" value="{$thisPage}">
@@ -28,7 +35,9 @@
                             <option value=""></option>
                             {if $invoices}
                                 {foreach $invoices as $invoice}
-                                <option value="{$invoice.id}">${$invoice.amount_total} Due {$invoice.due_date}</option>
+                                <option
+                                    value="{$invoice.id}"
+                                    {if isset($smarty.request.invoice_id) && $smarty.request.invoice_id == $invoice.id} selected{/if}>${$invoice.amount_total} Due {$invoice.due_date}</option>
                                 {/foreach}
                             {/if}
                         </select>
                 <div class="glm-row">
                     <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Amount </div>
                     <div class="glm-columns glm-small-12 glm-medium-8">
-                        <input class="glm-form-text-input-small" type="number" name="amount" step="0.01" min="0.01" required />
+                        <input
+                            class="glm-form-text-input-small"
+                            type="number"
+                            name="amount"
+                            step="0.01"
+                            min="0.01"
+                            required
+                            {if isset($smarty.request.amount) && $smarty.request.amount}value="{$smarty.request.amount}"{/if} />
                     </div>
                 </div>
 
                 <div class="glm-row">
                     <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Name on Card </div>
                     <div class="glm-columns glm-small-12 glm-medium-8">
-                        <input class="glm-form-text-input-medium" type="text" name="cc_name" required>
+                        <input
+                            class="glm-form-text-input-small"
+                            type="text"
+                            name="cc_name"
+                            required
+                            {if isset($smarty.request.cc_name) && $smarty.request.cc_name}value="{$smarty.request.cc_name}"{/if} />
                     </div>
                 </div>
 
@@ -55,7 +76,8 @@
                         <select name="cc_type" required>
                             <option value=""></option>
                             {foreach $management.cc_accepts.names as $cardId => $cardName}
-                                <option value="{$cardId}">{$cardName}</option>
+                                <option value="{$cardId}"
+                                {if isset($smarty.request.cc_type) && $smarty.request.cc_type == $cardId} selected{/if}>{$cardName}</option>
                             {/foreach}
                         </select>
                     </div>
                 <div class="glm-row">
                     <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Card Number </div>
                     <div class="glm-columns glm-small-12 glm-medium-8">
-                        <input class="glm-form-text-input-small" type="text" placeholder="Numbers Only" name="cc_numb" required>
+                        <input
+                            class="glm-form-text-input-small"
+                            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-row">
                     <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Card Expiration </div>
                     <div class="glm-columns glm-small-12 glm-medium-8">
-                        <input class="glm-form-text-input-small" type="text" placeholder="MM/YY" name="cc_exp" required>
+                        <input
+                            class="glm-form-text-input-small"
+                            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-row">
                     <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> C V V </div>
                     <div class="glm-columns glm-small-12 glm-medium-8">
-                        <input class="glm-form-text-input-small" type="text" placeholder="3 or 4 digit security code on back of card" name="cc_cvv" required>
+                        <input
+                            class="glm-form-text-input-small"
+                            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>