From: Steve Sutton Date: Fri, 6 Apr 2018 21:01:40 +0000 (-0400) Subject: Saving Authorize.net CIM data X-Git-Tag: v1.0.0^2~69 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=08d806a6dd1c237ec5fb6175f495e8892cc795b5;p=WP-Plugins%2Fglm-member-db-billing.git Saving Authorize.net CIM data Now billing saves the card profile for renewal. Need to test pay invoice again and update front end renewal form to use the new smarty template for payment section of the renewal payment form. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 445211e..4fb2943 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -1057,7 +1057,7 @@ class GlmBillingSupport ); } - public function processPayment( $account_id, $payment_id ) + public function processPayment( $account_id, $payment_id, $amount ) { $errors = array(); // Get the selected credit card processor type @@ -1145,7 +1145,7 @@ class GlmBillingSupport 'addr2' => $paymentData['billing_addr2'], 'city' => $paymentData['billing_city'], 'state' => $paymentData['billing_state'], - 'country' => '', + 'country' => 'USA', 'zip' => $paymentData['billing_zip'], 'phone' => $paymentData['billing_phone'], 'email' => $paymentData['email'] @@ -1160,8 +1160,10 @@ class GlmBillingSupport ) { $transOpt = 2; $checkCC = false; - $customerProfileId = $regAccount['fieldData']['customer_profile_id']; - $paymentProfileId = $regAccount['fieldData']['payment_profile_id']; + // Get the account data + $billing_account = $this->getAccountById( $account_id ); + $customerProfileId = $billing_account['customer_profile_id']; + $paymentProfileId = $billing_account['payment_profile_id']; } elseif ( isset( $_REQUEST['cc_save'] ) && trim( $_REQUEST['cc_save'] ) != '' @@ -1204,22 +1206,25 @@ class GlmBillingSupport $CcProcessor = new PaymentGateway( $account ); } - // TODO: Need to update the $invoice_id to something better for billing. $payment = array( - 'transOpt' => $transOpt, // 0 = charge card, 1 = charge and store, 2 = charge stored card - 'name' => $this->config['settings']['company_name'], // Company Name - 'charge' => $amount, // Total charges - 'cctype' => $cardData['cc_type'], // Card Type - 'ccname' => $cardData['cc_name'], // Name on Card - 'ccnumb' => $cardData['cc_numb'], // Card Number - 'ccexp' => $cardData['cc_exp'], // Expiration Date - 'cccode' => $cardData['cc_cvv'], // CCV - security code - 'invoice' => 'billing-' . $payment_id // Invoice # is "reg-" plus cart ID + 'transOpt' => $transOpt, // 0 = charge card, 1 = charge and store, 2 = charge stored card + 'name' => $this->config['settings']['company_name'], // Company Name + 'charge' => $amount, // Total charges + 'customerProfileId' => $customerProfileId, // Customer profile ID for charging stored card + 'paymentProfileId' => $paymentProfileId, // Payment profile ID for charging stored card + 'cctype' => $cardData['cc_type'], // Card Type + 'ccname' => $cardData['cc_name'], // Name on Card + 'ccnumb' => $cardData['cc_numb'], // Card Number + 'ccexp' => $cardData['cc_exp'], // Expiration Date + 'cccode' => $cardData['cc_cvv'], // CCV - security code + 'invoice' => 'billing-' . $payment_id // Invoice # is "reg-" plus cart ID ); // 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 ) { @@ -1233,6 +1238,7 @@ class GlmBillingSupport // If saving the credit card was successful if ( $profileStatus ) { + $cc_numb_store = '....'.substr($payment['ccnumb'], -4); // Save the profile information in the submitting account $updated = $this->wpdb->update( GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX.'accounts', @@ -1246,7 +1252,8 @@ class GlmBillingSupport '%s', '%s', '%s' - ) + ), + array( '%d' ) ); } else { @@ -1285,7 +1292,7 @@ class GlmBillingSupport */ public function processMemberRenewal( $account_id, $invoice_id, $amount, $employees = array() ) { - $result = $this->processPayment( $account_id, $invoice_id ); + $result = $this->processPayment( $account_id, $invoice_id, $amount ); if ( $result['status'] === 1 ) { @@ -1337,7 +1344,7 @@ class GlmBillingSupport public function makePayment( $account_id, $invoices, $amount ) { $payment_id = implode( '-', $invoices ); - $result = $this->processPayment( $account_id, $payment_id ); + $result = $this->processPayment( $account_id, $payment_id, $amount ); if ( $result['status'] === 1 ) { // Need to record the payment. diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index cd85405..5a84bbc 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -395,10 +395,9 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling case 'createPayment': - $view = 'paymentProcess'; + echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; - // MOVING TO billing support class - // $payment_status = $BillingSupport->processMemberRenewal(); + $view = 'paymentProcess'; // if error @@ -406,13 +405,53 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $account_id = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT ); $invoices = filter_var( $_REQUEST['invoices'], FILTER_VALIDATE_INT, array( 'flags' => FILTER_REQUIRE_ARRAY ) ); $amount = filter_var( $_REQUEST['amount'], FILTER_VALIDATE_FLOAT ); - // echo '
$account_id: ' . print_r( $account_id, true ) . '
'; - // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; - // echo '
$amount: ' . print_r( $amount, true ) . '
'; - $BillingSupport->makePayment( $account_id, $invoices, $amount ); + $payment_option = filter_var( $_REQUEST['payment_option'], FILTER_SANITIZE_STRING ); + + switch ( $payment_option ) { + case 'pay_by_credit_card': + + // Make the Payment using Billing Support Class + $errors = $BillingSupport->makePayment( $account_id, $invoices, $amount ); + + if ( $errors ) { + // 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 ); + + // 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'; + } + break; + case 'pay_by_check': + break; + } + + $view = 'statements'; break; @@ -436,7 +475,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // Get unpaid invoices $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] ); - // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; if ( !empty( $invoices ) ) { foreach ( $invoices as &$invoice ) { $invoice['due_date'] = date( 'n/d/Y', strtotime( $invoice['due_date'] ) ); diff --git a/views/admin/billing/makePayment.html b/views/admin/billing/makePayment.html index dd67c4e..f71c0fa 100644 --- a/views/admin/billing/makePayment.html +++ b/views/admin/billing/makePayment.html @@ -48,69 +48,8 @@ -
-
Name on Card
-
- -
-
- -
-
Card Type
-
- -
-
- -
-
Card Number
-
- -
-
- -
-
Card Expiration
-
- -
-
- -
-
C V V
-
- -
-
- +{* Include the Payment Form template *} +{include file='common/billing/paymentForm.html'} diff --git a/views/admin/billing/renew.html b/views/admin/billing/renew.html index d6dad41..d5aa304 100644 --- a/views/admin/billing/renew.html +++ b/views/admin/billing/renew.html @@ -107,156 +107,8 @@ -
- Billing Information - -
-
- First Name -
-
- -
-
-
-
- Last Name -
-
- -
-
-
-
- Address -
-
- -
-
-
-
- City -
-
- -
-
-
-
- State / Province -
-
- -
-
-
-
- Zip -
-
- -
-
- -
- -
- Payment Options - -
-
- Select Payment Option -
-
- - -
-
- -
-
- Name on Card -
-
- -
-
- -
-
- Card Type -
-
- -
-
-
-
- Card Number -
-
- -
-
-
-
- Card Expiration -
-
- -
-
-
-
- C V V -
-
- -
-
- -
- +{* Include the Payment Form template *} +{include file='common/billing/paymentForm.html'} @@ -271,18 +123,6 @@ jQuery(document).ready(function($){ $('#billing-amount').val( $(this).find('option:selected').data( 'amount') ); }); - $('.payment_option').change(function(){ - var payment_option = $('.payment_option:checked').val(); - console.log( 'payment_option: ', payment_option ); - if ( payment_option == 'pay_by_check' ) { - $('.glm-billing-credit').hide(); - $('.ccard').prop('disabled', true); - } else { - $('.glm-billing-credit').show(); - $('.ccard').prop('disabled', false); - } - }); - var formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', diff --git a/views/common/billing/paymentForm.html b/views/common/billing/paymentForm.html new file mode 100644 index 0000000..7470083 --- /dev/null +++ b/views/common/billing/paymentForm.html @@ -0,0 +1,211 @@ + +
+ Billing Information + +
+
+ First Name +
+
+ +
+
+
+
+ Last Name +
+
+ +
+
+
+
+ Address +
+
+ +
+
+
+
+ City +
+
+ +
+
+
+
+ State / Province +
+
+ +
+
+
+
+ Zip +
+
+ +
+
+
+
+ Email Address +
+
+ +
+
+ +
+ +
+ Payment Options + +
+
+ Select Payment Option +
+
+ + +
+
+ + {if $account.fieldData.payment_profile_card} +
+
+ +
+
+ {/if} + +
+
+ Name on Card +
+
+ +
+
+ +
+
+ Card Type +
+
+ +
+
+
+
+ Card Number +
+
+ +
+
+
+
+ Card Expiration +
+
+ +
+
+
+
+ C V V +
+
+ +
+
+ +
+
+ You may also have us save your credit card details with our secure credit card processor to + simplify future payments. Doing so will replace any previous credit card details you saved. +
+
+ +
+
+ +
+ +