From 492630904d3acd0e976352586a6bcc3a36b89030 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 16 Apr 2019 16:12:38 -0400 Subject: [PATCH] Working on the billing invoices and payment forms Adding new field for receipt text. This is placed on the receipt. Receipt being a different view file than the invoice. --- classes/billingSupport.php | 52 ++++++++++++++++++- classes/data/dataSettings.php | 7 +++ index.php | 2 +- models/admin/billing/invoices.php | 1 + models/front/billing/paymentForm.php | 3 +- ...0.0.37.sql => create_database_V0.0.38.sql} | 1 + setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.0.38.sql | 9 ++++ views/admin/billing/paymentReceipt.html | 9 +++- views/admin/settings/billing.html | 8 +++ views/common/billing/paymentForm.html | 2 +- 11 files changed, 89 insertions(+), 6 deletions(-) rename setup/databaseScripts/{create_database_V0.0.37.sql => create_database_V0.0.38.sql} (99%) create mode 100644 setup/databaseScripts/update_database_V0.0.38.sql diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 6089987..6f14d2d 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -1442,6 +1442,7 @@ class GlmBillingSupport 'status' => 1, 'errors' => array(), 'ccResult' => $ccResult, + 'response' => ( $ccResult['response'] ) ? $ccResult['response'] : false, ); } else { @@ -1515,10 +1516,57 @@ class GlmBillingSupport if ( $result['status'] === 1 ) { + // Get transaction time setup $_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' ); - // Create new payment. - $payment_id = $this->createPayment( $account_id, $amount, 'Credit Card' ); + // For Square check if there's a response object returned. + $ccProcessor = $this->config['billing_settings']['proc_methods']; + switch ( $ccProcessor ) { + case $this->config['billing_proc_method_numb']['Authorize.net']: + break; + case $this->config['billing_proc_method_numb']['MerchantSolutions']: + break; + case $this->config['billing_proc_method_numb']['Square']: + break; + case $this->config['billing_proc_method_numb']['Merchant']: + case $this->config['billing_proc_method_numb']['TestAlwaysGood']: + case $this->config['billing_proc_method_numb']['TestByCardNumber']: + default: + break; + } + if ( isset( $result['response'] ) && $ccProcessor == $this->config['billing_proc_method_numb']['Square'] ) { + // Get the card detail + $chargeObject = $result['response']; + $transaction = $chargeObject->getTransaction(); + $tenders = $transaction->getTenders(); + // get first tender object + $tender = $tenders[0]; + $cardDetails = $tender->getCardDetails(); + $card = $cardDetails->getCard(); + $lastFour = $card->getLast4(); + $cardBrand = $card->getCardBrand(); + + // Create new payment. + $payment_id = $this->createPayment( $account_id, $amount, "$cardBrand Credit Card Ending in *$lastFour" ); + } else { + $cardBrand = ''; + $lastFour = ''; + if ( isset( $_REQUEST['cc_type'] ) && $_REQUEST['cc_type'] ) { + // need to know number to card type + $cardBrand = $_REQUEST['cc_type']; + } + if ( isset( $_REQUEST['cc_numb'] ) && $_REQUEST['cc_numb'] ) { + // Get last four numbers + preg_match( '%([0-9]{4})$%', $_REQUEST['cc_numb'], $matches ); + $lastFour = $matches[1]; + } + // Create new payment. + if ( $cardBrand && $lastFour ) { + $payment_id = $this->createPayment( $account_id, $amount, "$cardBrand Credit Card Ending in *$lastFour" ); + } else { + $payment_id = $this->createPayment( $account_id, $amount, 'Credit Card' ); + } + } // Record the payment. $this->recordPayment( $payment_id, $account_id, $amount, $invoice_id ); diff --git a/classes/data/dataSettings.php b/classes/data/dataSettings.php index 53ff9d3..c4fa253 100644 --- a/classes/data/dataSettings.php +++ b/classes/data/dataSettings.php @@ -216,6 +216,13 @@ class GlmDataBillingSettings extends GlmDataAbstract 'use' => 'a', ), + // Receipt Text + 'receipt_text' => array( + 'field' => 'receipt_text', + 'type' => 'text', + 'use' => 'a', + ), + // Days Before Renewal Allowed 'days_before_renewal' => array( 'field' => 'days_before_renewal', diff --git a/index.php b/index.php index 27f39d0..8a91e54 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.26'); -define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.37'); +define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.38'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index f478d10..eebe5eb 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -524,6 +524,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); $invoiceHtml = $BillingSupport->viewInvoice( $_REQUEST['id'] ); + // $invoiceHtml = $BillingSupport->viewReceipt( $_REQUEST['id'] ); // Set the file name for the view file. $view = 'viewInvoice'; diff --git a/models/front/billing/paymentForm.php b/models/front/billing/paymentForm.php index b2666e9..ed133f1 100644 --- a/models/front/billing/paymentForm.php +++ b/models/front/billing/paymentForm.php @@ -182,6 +182,7 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling case 'paymentProcess': $error = false; $view = 'paymentFormProcess'; + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; // Here we need to get the chosen Membership plan and adjust the invoice with a new line_item if needed. $selectedPaymentType = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ); @@ -305,7 +306,7 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling $view = 'viewInvoice'; // Get the invoice. - $invoiceHtml = $BillingSupport->viewInvoice( $invoiceId ); + $invoiceHtml = $BillingSupport->viewReceipt( $invoiceId ); } else { $this->wpdb->query( 'ROLLBACK' ); } diff --git a/setup/databaseScripts/create_database_V0.0.37.sql b/setup/databaseScripts/create_database_V0.0.38.sql similarity index 99% rename from setup/databaseScripts/create_database_V0.0.37.sql rename to setup/databaseScripts/create_database_V0.0.38.sql index 1ccb218..64e88cf 100644 --- a/setup/databaseScripts/create_database_V0.0.37.sql +++ b/setup/databaseScripts/create_database_V0.0.38.sql @@ -252,6 +252,7 @@ CREATE TABLE {prefix}settings ( company_email TINYTEXT NULL, -- Company Email company_url TINYTEXT NULL, -- Company URL payment_terms TEXT NULL, -- Payment Terms + receipt_text TEXT NULL, -- Receipt Text invoice_show_account_number BOOLEAN DEFAULT '0', -- Show Billing Account number on invoices invoice_show_invoice_number BOOLEAN DEFAULT '1', -- Show Invoice Number on invoices days_before_renewal INT NULL, -- Number of days before renewal date to allow renewals diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 7d7a871..e03da49 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -51,5 +51,6 @@ $glmMembersBillingDbVersions = array( '0.0.35' => array('version' => '0.0.35', 'tables' => 16, 'date' => '03/20/2019'), '0.0.36' => array('version' => '0.0.36', 'tables' => 16, 'date' => '04/02/2019'), '0.0.37' => array('version' => '0.0.37', 'tables' => 16, 'date' => '04/11/2019'), + '0.0.38' => array('version' => '0.0.38', 'tables' => 16, 'date' => '04/16/2019'), ); diff --git a/setup/databaseScripts/update_database_V0.0.38.sql b/setup/databaseScripts/update_database_V0.0.38.sql new file mode 100644 index 0000000..c50131f --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.38.sql @@ -0,0 +1,9 @@ +-- Gaslight Media Billing Database +-- File Created: 04/11/2019 +-- Database Version: 0.0.37 +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Update the settings table +ALTER TABLE {prefix}settings ADD receipt_text TEXT NULL; -- Receipt Text diff --git a/views/admin/billing/paymentReceipt.html b/views/admin/billing/paymentReceipt.html index 2cdcf0e..2564c83 100644 --- a/views/admin/billing/paymentReceipt.html +++ b/views/admin/billing/paymentReceipt.html @@ -69,7 +69,7 @@ body { Member Name - Anniversary + Date   Description Rate @@ -112,6 +112,13 @@ body {   + {if $settings.receipt_text} + + + {$settings.receipt_text} + + + {/if}   {* Footer of invoice *} diff --git a/views/admin/settings/billing.html b/views/admin/settings/billing.html index e0d08db..4fe4e52 100644 --- a/views/admin/settings/billing.html +++ b/views/admin/settings/billing.html @@ -154,6 +154,14 @@ + + Receipt Text + + + {if $billingSettings.fieldFail.receipt_text}

{$billingSettings.fieldFail.receipt_text}

{/if}
+ + + diff --git a/views/common/billing/paymentForm.html b/views/common/billing/paymentForm.html index 1d3a60d..48bcc6e 100644 --- a/views/common/billing/paymentForm.html +++ b/views/common/billing/paymentForm.html @@ -131,7 +131,7 @@ -- 2.17.1