From df6d813eee42e22880b57a0c429afd3039e7b4cf Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 24 Apr 2018 16:19:23 -0400 Subject: [PATCH] Update become member form. Now it is saving the member custom field data correctly. Keeping the transaction. --- models/front/billing/becomeMember.php | 86 ++++++++++++++++++++++----- views/front/billing/thankyou.html | 2 + 2 files changed, 74 insertions(+), 14 deletions(-) diff --git a/models/front/billing/becomeMember.php b/models/front/billing/becomeMember.php index 84e4116..9e3f46c 100644 --- a/models/front/billing/becomeMember.php +++ b/models/front/billing/becomeMember.php @@ -89,6 +89,8 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling $paymentSuccess = false; $paymentError = false; $payable_types = false; + $error = false; + $invoiceHtml = ''; // Check to see if a user is logged in // If they are then they should not see the Become a member form at all. @@ -154,15 +156,15 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling $error = true; $messages[] = 'An error occurred! invoice_type_data'; } - echo '
$invoice_type_data: ' . print_r( $invoice_type_data, true ) . '
'; + // echo '
$invoice_type_data: ' . print_r( $invoice_type_data, true ) . '
'; $member_type = $invoice_type_data['member_type']; if ( !$member_type ) { $error = true; $messages[] = 'An error occurred! member_type'; } - echo '
$member_type: ' . print_r( $member_type, true ) . '
'; + // echo '
$member_type: ' . print_r( $member_type, true ) . '
'; // Start database transaction - // $this->wpdb->show_errors(); + $this->wpdb->show_errors(); $this->wpdb->query('START TRANSACTION'); // $access = $this->config['access_numb']['Full']; $this->wpdb->insert( @@ -183,7 +185,7 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling ) ); $member_id = $this->wpdb->insert_id; - echo '
$member_id: ' . print_r( $member_id, true ) . '
'; + // echo '
$member_id: ' . print_r( $member_id, true ) . '
'; if ( !$member_id ) { $error = true; $messages[] = 'An error occurred! member_id'; @@ -196,13 +198,13 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling $member_id ) ); - echo '
$member: ' . print_r( $member, true ) . '
'; + // echo '
$member: ' . print_r( $member, true ) . '
'; } // 2. Setup the member_info $billing_addr1 = filter_var( $_REQUEST['billing_addr1'] ); $billing_city = filter_var( $_REQUEST['billing_city'] ); $billing_city_id = $this->getCityId( $billing_city ); - echo '
$billing_city_id: ' . print_r( $billing_city_id, true ) . '
'; + // echo '
$billing_city_id: ' . print_r( $billing_city_id, true ) . '
'; $billing_state = filter_var( $_REQUEST['billing_state'] ); $billing_zip = filter_var( $_REQUEST['billing_zip'] ); $phone = filter_var( $_REQUEST['phone'] ); @@ -253,7 +255,7 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling $member_info_id ) ); - echo '
$member_info: ' . print_r( $member_info, true ) . '
'; + // echo '
$member_info: ' . print_r( $member_info, true ) . '
'; } // 3. Setup the contact (and wpUser) // Determine the Worpress Role to be used for contact import - Using Entity Manager right now @@ -304,7 +306,7 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling $newContactID ) ); - echo '
$new_contact: ' . print_r( $new_contact, true ) . '
'; + // echo '
$new_contact: ' . print_r( $new_contact, true ) . '
'; } else { // $this->wpdb->print_error(); $error = true; @@ -325,7 +327,7 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling // Store the contact ID and active status into user meta data. update_user_meta($wpUserID, 'glmMembersContactID', $newContactID); update_user_meta($wpUserID, 'glmMembersContactActive', true); - echo '
$wpUserID: ' . print_r( $wpUserID, true ) . '
'; + // echo '
$wpUserID: ' . print_r( $wpUserID, true ) . '
'; } else { $error = true; $messages[] = 'An error occurred! wpUserID'; @@ -337,6 +339,9 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling $customFieldKey = filter_var( $customFieldKey, FILTER_VALIDATE_INT ); $customFieldValue = filter_var( $customFieldValue ); if ( $customFieldKey && $customFieldValue ) { + if ( in_array( $customFieldKey, array( 2, 3 ) ) ) { + $customFieldValue = 'Yes'; + } $this->wpdb->insert( GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_data', array( @@ -352,7 +357,7 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling ); $customFieldId = $this->wpdb->insert_id; if ( $customFieldId ) { - echo '
$customFieldId: ' . print_r( $customFieldId, true ) . '
'; + // echo '
$customFieldId: ' . print_r( $customFieldId, true ) . '
'; } else { $error = true; $messages[] = 'An error occurred! customFieldId'; @@ -369,11 +374,12 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling 'anniversary_date' => date( 'Y-m-d' ), 'boss' => false, 'invoice_type' => $invoice_type, - 'billing_fname' => $billing_fname, - 'billing_lname' => $billing_lname, + 'billing_fname' => $member_fname, + 'billing_lname' => $member_lname, 'billing_addr1' => $billing_addr1, 'billing_city' => $billing_city, 'billing_state' => $billing_state, + 'billing_zip' => $billing_zip, 'billing_phone' => $billing_phone, 'email' => $memberContactEmail, ), @@ -388,16 +394,67 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling '%s', // billing_addr1 '%s', // billing_city '%s', // billing_state + '%s', // billing_zip '%s', // billing_phone '%s', // email ) ); + $accountID = $this->wpdb->insert_id; + if ( !$accountID ) { + $error = true; + $messages[] = 'An error occurred! accountID'; + } // Save or rollback if ( $error ) { $this->wpdb->query('ROLLBACK'); } else { $this->wpdb->query('COMMIT'); - $view = 'thankyou'; + // $this->wpdb->query('ROLLBACK'); + + // Fetch the invoice type chosen by the member. + $member_invoice = $BillingSupport->getInvoiceTypeById( $invoice_type ); + // Here we'll create the invoice for the member. + $invoice_data = array( + 'account_id' => $accountID, + 'renew_type_id' => $invoice_type, + 'amount' => $_REQUEST['total_renew_amount'], + 'due_date' => date( 'Y-m-d' ), + 'member_invoice' => $member_invoice, + 'employee_data' => array(), + 'employees' => array(), + ); + $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data ); + if ( !$invoice_id ) { + $this->wpdb->print_error(); + $error = true; + $messages[] = 'An error occurred! invoice_id'; + } + if ( !$error ) { + + // Get payment type and process. + $payment_option = filter_var( $_REQUEST['payment_option'], FILTER_SANITIZE_STRING ); + switch ( $payment_option ) { + case 'pay_by_credit_card': + // Do the Payment Processing. + $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] ); + if ( $processErrors ) { + if ( count( $processErrors ) > 0 ) { + $error = true; + $messages[] = 'An error occurred! processErrors'; + } + } + break; + case 'pay_by_check': + break; + } + + } + + if ( $error ) { + } else { + $invoiceHtml = $BillingSupport->viewInvoice( $invoice_id ); + $view = 'thankyou'; + } } break; @@ -422,7 +479,8 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling 'paymentSuccess' => $paymentSuccess, 'paymentError' => $paymentError, 'payable_types' => $payable_types, - 'states' => $this->config['states'] + 'states' => $this->config['states'], + 'invoiceHtml' => $invoiceHtml, ); // Return status, any suggested view, and any data to controller. diff --git a/views/front/billing/thankyou.html b/views/front/billing/thankyou.html index ca2a270..266e4a5 100644 --- a/views/front/billing/thankyou.html +++ b/views/front/billing/thankyou.html @@ -1,3 +1,5 @@ {* Thank you page template *}

Thank You

Welcome to MiGCSA. As a member ...

+ + {$invoiceHtml} -- 2.17.1