From 490f510507e60c06ee3ed4455f564f3338871a66 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Sun, 11 Mar 2018 07:19:10 -0400 Subject: [PATCH] Update payment form for validation. Adding some validation into the htm5 markup in the form. --- models/admin/member/billing.php | 71 ++++++++++++++++++---------- views/admin/billing/makePayment.html | 57 +++++++++++++++++++--- 2 files changed, 96 insertions(+), 32 deletions(-) diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 5576f4b..ea45795 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -233,13 +233,8 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling break; case 'createPayment': - // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; - $view = 'paymentProcess'; - // echo '
$this->config: ' . print_r( $this->config, true ) . '
'; - // 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 '
$account: ' . print_r( $account, true ) . '
'; - // 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 '
$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 ( $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 '
ccResult: ' . print_r( $ccResult, true ) . '
'; // 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 '
$messages: ' . print_r( $messages, true ) . '
'; 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 '
$cc_accepts: ' . print_r( $cc_accepts, true ) . '
'; + // Set the file name for the view file. $view = 'makePayment'; - // echo '
$account: ' . print_r( $account, true ) . '
'; break; case 'list': diff --git a/views/admin/billing/makePayment.html b/views/admin/billing/makePayment.html index 5818b7d..e578b70 100644 --- a/views/admin/billing/makePayment.html +++ b/views/admin/billing/makePayment.html @@ -1,6 +1,13 @@ {include file='admin/member/header.html'} {include file='admin/billing/memberBillingSubHeader.html'} +{if $messages} + {foreach $messages as $message} +
{$message}
+ {/foreach} +{/if} + +
@@ -28,7 +35,9 @@ {if $invoices} {foreach $invoices as $invoice} - + {/foreach} {/if} @@ -38,14 +47,26 @@
Amount
- +
Name on Card
- +
@@ -55,7 +76,8 @@
@@ -64,21 +86,42 @@
Card Number
- +
Card Expiration
- +
C V V
- +
-- 2.17.1