case 'renewMembership':
$error = false;
- $view = 'renewMembership';
-
- // Check for account_number
- // If given then this is from unregistered user.
- // Have to verify that this number does match with billing_account.
- if ( isset( $_REQUEST['account_number'] ) && $account_number = filter_var( $_REQUEST['account_number'], FILTER_SANITIZE_STRING ) ) {
- // Verify account number.
- $accountID = $this->wpdb->get_var(
- $this->wpdb->prepare(
- "SELECT id
- FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
- WHERE account_number = %s",
- $account_number
- )
- );
- }
- $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId );
- echo '<pre>$this->memberId: ' . print_r( $this->memberId, true ) . '</pre>';
- echo '<pre>$member_invoice_id: ' . print_r( $member_invoice_id, true ) . '</pre>';
- if ( $member_invoice_id ) {
- $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
+ if ( isset( $_SESSION['billing_renewal_paid'] ) && $_SESSION['billing_renewal_paid'] ) {
+ // They're refreshing the page with the invoice on it.
+ // Reshow the invoice.
} else {
- $error = true;
- $paymentError = true;
- trigger_error( 'member_invoice_id not found', E_USER_NOTICE );
- }
+ $view = 'renewMembership';
- if ( $this->config['settings']['allow_employees'] ) {
- $employees = $BillingSupport->getListOfAccountEmployees( $this->memberId );
- }
+ $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+ if ( $member_invoice_id ) {
+ $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
+ } else {
+ $error = true;
+ }
- $invoice_data = array(
- 'account_id' => $accountID,
- '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' => isset( $_REQUEST['employees'] ) ? $_REQUEST['employees'] : array(),
- );
- if ( !$invoice_data ) {
- $error = true;
- }
+ $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
- // Start database transaction
- $this->wpdb->show_errors();
- $this->wpdb->query('START TRANSACTION');
+ $invoice_data = array(
+ 'account_id' => $accountID,
+ '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' => isset( $_REQUEST['employees'] ) ? $_REQUEST['employees'] : array(),
+ );
+ if ( !$invoice_data ) {
+ $error = true;
+ }
- // Before we create an invoice for this member see if they already have one.
- // If we find one then delete it.
- $old_invoice_ids = $this->wpdb->get_results(
- $this->wpdb->prepare(
- "SELECT id
- FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
- WHERE paid <> true
- AND renewal = true
- AND account = %d",
- $accountID
- ),
- ARRAY_A
- );
- if ( isset( $old_invoice_ids ) && $old_invoice_ids ) {
- foreach ( $old_invoice_ids as $old_invoices ) {
- if ( $inv_id = filter_var( $old_invoices['id'], FILTER_VALIDATE_INT ) ) {
- $BillingSupport->removeInvoiceById( $inv_id );
+ // Before we create an invoice for this member see if they already have one.
+ // If we find one then delete it.
+ $old_invoice_ids = $this->wpdb->get_results(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+ WHERE paid <> true
+ AND renewal = true
+ AND account = %d",
+ $accountID
+ ),
+ ARRAY_A
+ );
+ if ( isset( $old_invoice_ids ) && $old_invoice_ids ) {
+ foreach ( $old_invoice_ids as $old_invoices ) {
+ if ( $inv_id = filter_var( $old_invoices['id'], FILTER_VALIDATE_INT ) ) {
+ $BillingSupport->removeInvoiceById( $inv_id );
+ }
}
}
- }
- // Create the invoice for this member.
- $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data );
- if ( !$invoice_id ) {
- $error = true;
- $paymentError = true;
- trigger_error( 'invoice_id not found', E_USER_NOTICE );
+ // 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.
$account = $Accounts->editEntry( $accountID );
} else {
- // Look at the payment option given
- $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 ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) {
- $error = true;
- $BillingSupport->removeInvoiceById( $invoice_id );
- foreach ( $processErrors as $error ) {
- $messages[] = '<span style="color: red;">'.$error.'</span>';
+ if ( isset( $_SESSION['billing_renewal_paid'] ) && $_SESSION['billing_renewal_paid'] ) {
+ // They're refreshing the page with the invoice on it.
+ // Reshow the invoice.
+ $invoice_id = $_SESSION['billing_renewal_paid'];
+ } else {
+ // Look at the payment option given
+ $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 ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) {
+ $error = true;
+ $BillingSupport->removeInvoiceById( $invoice_id );
+ foreach ( $processErrors as $error ) {
+ $messages[] = '<span style="color: red;">'.$error.'</span>';
+ }
+ } else if ( isset( $processErrors ) && $processErrors ) {
+ $error = true;
+ $messages[] = '<span style="color: red;">'.$processErrors.'</span>';
+ } else {
+ $paymentSuccess = true;
}
- } else if ( isset( $processErrors ) && $processErrors ) {
- $error = true;
- $messages[] = '<span style="color: red;">'.$processErrors.'</span>';
- } else {
- $paymentSuccess = true;
- }
- $view = 'renew';
+ $view = 'renew';
- // Get list of payable invoice_types
- $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+ // Get list of payable invoice_types
+ $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
- $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId );
- if ( $member_invoice_id ) {
- $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
- }
- if ( $this->config['settings']['allow_employees'] ) {
+ $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+ if ( $member_invoice_id ) {
+ $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
+ }
+
// Get a list of this accounts employees. If they have any.
- $employees = $BillingSupport->getListOfAccountEmployees( $this->memberId );
- }
+ $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 );
+ // 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.
- $account = $Accounts->editEntry( $accountID );
+ // Need to see if there's an account for this member.
+ $account = $Accounts->editEntry( $accountID );
+ }
+ break;
+ case 'pay_by_check':
+ break;
}
- break;
- case 'pay_by_check':
- break;
}
// If there's no error reported then show the invoice
if ( !$error ) {
- $this->wpdb->query( 'COMMIT' );
+
+ // Create a session for renewal paid.
+ $_SESSION['billing_renewal_paid'] = $invoice_id;
// Now need to show the invoice.
$view = 'viewInvoice';