Saving Authorize.net CIM data
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 6 Apr 2018 21:01:40 +0000 (17:01 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 6 Apr 2018 21:01:40 +0000 (17:01 -0400)
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.

classes/billingSupport.php
models/admin/member/billing.php
views/admin/billing/makePayment.html
views/admin/billing/renew.html
views/common/billing/paymentForm.html [new file with mode: 0644]

index 445211e..4fb2943 100644 (file)
@@ -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 '<pre>$ccResult: ' . print_r( $ccResult, true ) . '</pre>';
+
             // 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.
index cd85405..5a84bbc 100644 (file)
@@ -395,10 +395,9 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
         case 'createPayment':
 
-            $view = 'paymentProcess';
+            echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
 
-            // 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 '<pre>$account_id: ' . print_r( $account_id, true ) . '</pre>';
-            // echo '<pre>$invoices: ' . print_r( $invoices, true ) . '</pre>';
-            // echo '<pre>$amount: ' . print_r( $amount, true ) . '</pre>';
-            $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 '<pre>$invoices: ' . print_r( $invoices, true ) . '</pre>';
             if ( !empty( $invoices ) ) {
                 foreach ( $invoices as &$invoice ) {
                     $invoice['due_date'] = date( 'n/d/Y', strtotime( $invoice['due_date'] ) );
index dd67c4e..f71c0fa 100644 (file)
                     </div>
                 </div>
 
-                <div class="glm-billing-field">
-                    <div class="glm-billing-label glm-required"> Name on Card </div>
-                    <div class="glm-billing-input">
-                        <input
-                            type="text"
-                            name="cc_name"
-                            required
-                            {if isset($smarty.request.cc_name) && $smarty.request.cc_name}value="{$smarty.request.cc_name}"{/if} />
-                    </div>
-                </div>
-
-                <div class="glm-billing-field glm-billing-left-half">
-                    <div class="glm-billing-label glm-required"> Card Type </div>
-                    <div class="glm-billing-input">
-                        <select name="cc_type" required>
-                            <option value=""></option>
-                            {foreach $management.cc_accepts.names as $cardId => $cardName}
-                                <option value="{$cardId}"
-                                {if isset($smarty.request.cc_type) && $smarty.request.cc_type == $cardId} selected{/if}>{$cardName}</option>
-                            {/foreach}
-                        </select>
-                    </div>
-                </div>
-
-                <div class="glm-billing-field glm-billing-right-half">
-                    <div class="glm-billing-label glm-required"> Card Number </div>
-                    <div class="glm-billing-input">
-                        <input
-                            type="text"
-                            placeholder="Numbers Only"
-                            name="cc_numb"
-                            required
-                            pattern="\d*"
-                            {if isset($smarty.request.cc_numb) && $smarty.request.cc_numb}value="{$smarty.request.cc_numb}"{/if} />
-                    </div>
-                </div>
-
-                <div class="glm-billing-field glm-billing-left-half">
-                    <div class="glm-billing-label glm-required"> Card Expiration </div>
-                    <div class="glm-billing-input">
-                        <input
-                            type="text"
-                            placeholder="MM/YY"
-                            name="cc_exp"
-                            required
-                            pattern="{literal}\d{2}/\d{2}{/literal}"
-                            {if isset($smarty.request.cc_exp) && $smarty.request.cc_exp}value="{$smarty.request.cc_exp}"{/if} />
-                    </div>
-                </div>
-
-                <div class="glm-billing-field glm-billing-right-half">
-                    <div class="glm-billing-label glm-required"> C V V </div>
-                    <div class="glm-billing-input">
-                        <input
-                            type="text"
-                            placeholder="3 or 4 digit security code on back of card"
-                            name="cc_cvv"
-                            required
-                            pattern="{literal}\d{3,4}{/literal}"
-                            {if isset($smarty.request.cc_cvv) && $smarty.request.cc_cvv}value="{$smarty.request.cc_cvv}"{/if} />
-                    </div>
-                </div>
-
+{* Include the Payment Form template *}
+{include file='common/billing/paymentForm.html'}
 
                 <input class="button button-primary" type="submit" value="Make Payment">
 
index d6dad41..d5aa304 100644 (file)
             </div>
         </div>
 
-    <fieldset>
-        <legend>Billing Information</legend>
-
-        <div class="glm-billing-field glm-billing-left-half">
-            <div class="glm-billing-label glm-required">
-                First Name
-            </div>
-            <div class="glm-billing-input">
-                <input type="text" name="billing_fname" value="{$account.fieldData.billing_fname}" required />
-            </div>
-        </div>
-        <div class="glm-billing-field glm-billing-right-half">
-            <div class="glm-billing-label glm-required">
-                Last Name
-            </div>
-            <div class="glm-billing-input">
-                <input type="text" name="billing_lname" value="{$account.fieldData.billing_lname}" required />
-            </div>
-        </div>
-        <div class="glm-billing-field">
-            <div class="glm-billing-label glm-required">
-                Address
-            </div>
-            <div class="glm-billing-input">
-                <input type="text" name="billing_addr1" value="{$account.fieldData.billing_addr1}" required />
-            </div>
-        </div>
-        <div class="glm-billing-field glm-billing-left-half">
-            <div class="glm-billing-label glm-required">
-                City
-            </div>
-            <div class="glm-billing-input">
-                <input type="text" name="billing_city" value="{$account.fieldData.billing_city}" required />
-            </div>
-        </div>
-        <div class="glm-billing-field glm-billing-right-half">
-            <div class="glm-billing-label glm-required">
-                State / Province
-            </div>
-            <div class="glm-billing-input">
-                <select name="billing_state" required>
-                    <option value=""></option>
-                    {foreach $account.fieldData.billing_state.list as $s}
-                        <option value="{$s.value}"{if $account.fieldData.billing_state.value == $s.value} selected="selected"{/if}>
-                            {$s.name}
-                        </option>
-                    {/foreach}
-                </select>
-            </div>
-        </div>
-        <div class="glm-billing-field">
-            <div class="glm-billing-label glm-required">
-                Zip
-            </div>
-            <div class="glm-billing-input">
-                <input type="text" name="billing_zip" value="{$account.fieldData.billing_zip}" required />
-            </div>
-        </div>
-
-        </fieldset>
-
-    <fieldset>
-        <legend>Payment Options</legend>
-
-        <div class="glm-billing-field">
-            <div class="glm-billing-label">
-                Select Payment Option
-            </div>
-            <div class="glm-billing-input">
-                <label> <input class="payment_option" type="radio" name="payment_option" value="pay_by_credit_card" checked> Pay by Credit Card </label>
-                <label> <input class="payment_option" type="radio" name="payment_option" value="pay_by_check"> Pay by Check </label>
-            </div>
-        </div>
-
-        <div class="glm-billing-field glm-billing-credit">
-            <div class="glm-billing-label glm-required">
-                Name on Card
-            </div>
-            <div class="glm-billing-input">
-                <input
-                    class="ccard"
-                    type="text"
-                    name="cc_name"
-                    required
-                    {if isset($smarty.request.cc_name) && $smarty.request.cc_name}value="{$smarty.request.cc_name}"{/if} />
-            </div>
-        </div>
-
-        <div class="glm-billing-field glm-billing-left-half glm-billing-credit">
-            <div class="glm-billing-label glm-required">
-                Card Type
-            </div>
-            <div class="glm-billing-input">
-                <select name="cc_type" class="ccard" required>
-                    <option value=""></option>
-                    {foreach $management.cc_accepts.names as $cardId => $cardName}
-                        <option value="{$cardId}"
-                        {if isset($smarty.request.cc_type) && $smarty.request.cc_type == $cardId} selected{/if}>{$cardName}</option>
-                    {/foreach}
-                </select>
-            </div>
-        </div>
-        <div class="glm-billing-field glm-billing-right-half glm-billing-credit">
-            <div class="glm-billing-label glm-required">
-                Card Number
-            </div>
-            <div class="glm-billing-input">
-                <input
-                    class="ccard"
-                    type="text"
-                    placeholder="Numbers Only"
-                    name="cc_numb"
-                    required
-                    pattern="\d*"
-                    {if isset($smarty.request.cc_numb) && $smarty.request.cc_numb}value="{$smarty.request.cc_numb}"{/if} />
-            </div>
-        </div>
-        <div class="glm-billing-field glm-billing-left-half glm-billing-credit">
-            <div class="glm-billing-label glm-required">
-                Card Expiration
-            </div>
-            <div class="glm-billing-input">
-                <input
-                    class="ccard"
-                    type="text"
-                    placeholder="MM/YY"
-                    name="cc_exp"
-                    required
-                    pattern="{literal}\d{2}/\d{2}{/literal}"
-                    {if isset($smarty.request.cc_exp) && $smarty.request.cc_exp}value="{$smarty.request.cc_exp}"{/if} />
-            </div>
-        </div>
-        <div class="glm-billing-field glm-billing-right-half glm-billing-credit">
-            <div class="glm-billing-label glm-required">
-            C V V
-            </div>
-            <div class="glm-billing-input">
-                <input
-                    class="ccard"
-                    type="text"
-                    placeholder="3 or 4 digit security code on back of card"
-                    name="cc_cvv"
-                    required
-                    pattern="{literal}\d{3,4}{/literal}"
-                    {if isset($smarty.request.cc_cvv) && $smarty.request.cc_cvv}value="{$smarty.request.cc_cvv}"{/if} />
-            </div>
-        </div>
-
-        </fieldset>
-
+{* Include the Payment Form template *}
+{include file='common/billing/paymentForm.html'}
 
         <input class="button button-primary" type="submit" value="Submit Membership Renewal">
 
@@ -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 (file)
index 0000000..7470083
--- /dev/null
@@ -0,0 +1,211 @@
+
+    <fieldset>
+        <legend>Billing Information</legend>
+
+        <div class="glm-billing-field glm-billing-left-half">
+            <div class="glm-billing-label glm-required">
+                First Name
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_fname" value="{$account.fieldData.billing_fname}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-right-half">
+            <div class="glm-billing-label glm-required">
+                Last Name
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_lname" value="{$account.fieldData.billing_lname}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Address
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_addr1" value="{$account.fieldData.billing_addr1}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-left-half">
+            <div class="glm-billing-label glm-required">
+                City
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_city" value="{$account.fieldData.billing_city}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-right-half">
+            <div class="glm-billing-label glm-required">
+                State / Province
+            </div>
+            <div class="glm-billing-input">
+                <select name="billing_state" required>
+                    <option value=""></option>
+                    {foreach $account.fieldData.billing_state.list as $s}
+                        <option value="{$s.value}"{if $account.fieldData.billing_state.value == $s.value} selected="selected"{/if}>
+                            {$s.name}
+                        </option>
+                    {/foreach}
+                </select>
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Zip
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_zip" value="{$account.fieldData.billing_zip}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Email Address
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="email" value="{$account.fieldData.email}" required />
+            </div>
+        </div>
+
+        </fieldset>
+
+    <fieldset>
+        <legend>Payment Options</legend>
+
+        <div class="glm-billing-field">
+            <div class="glm-billing-label">
+                Select Payment Option
+            </div>
+            <div class="glm-billing-input">
+                <label> <input class="payment_option" type="radio" name="payment_option" value="pay_by_credit_card" checked> Pay by Credit Card </label>
+                <label> <input class="payment_option" type="radio" name="payment_option" value="pay_by_check"> Pay by Check </label>
+            </div>
+        </div>
+
+        {if $account.fieldData.payment_profile_card}
+            <div class="glm-billing-field glm-billing-credit">
+                <div class="glm-billing-input">
+                    <label>
+                        <input id="glm-billing-use-saved-card" type="checkbox" name="use_saved_cc_profile">
+                        <strong>Use the saved credit card ending in {$account.fieldData.payment_profile_card}</strong>
+                    </label>
+                </div>
+            </div>
+        {/if}
+
+        <div class="glm-billing-field glm-billing-credit glm-billing-card">
+            <div class="glm-billing-label glm-required">
+                Name on Card
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    class="ccard"
+                    type="text"
+                    name="cc_name"
+                    required
+                    {if isset($smarty.request.cc_name) && $smarty.request.cc_name}value="{$smarty.request.cc_name}"{/if} />
+            </div>
+        </div>
+
+        <div class="glm-billing-field glm-billing-left-half glm-billing-credit glm-billing-card">
+            <div class="glm-billing-label glm-required">
+                Card Type
+            </div>
+            <div class="glm-billing-input">
+                <select name="cc_type" class="ccard" required>
+                    <option value=""></option>
+                    {foreach $management.cc_accepts.names as $cardId => $cardName}
+                        <option value="{$cardId}"
+                        {if isset($smarty.request.cc_type) && $smarty.request.cc_type == $cardId} selected{/if}>{$cardName}</option>
+                    {/foreach}
+                </select>
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-right-half glm-billing-credit glm-billing-card">
+            <div class="glm-billing-label glm-required">
+                Card Number
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    class="ccard"
+                    type="text"
+                    placeholder="Numbers Only"
+                    name="cc_numb"
+                    required
+                    pattern="\d*"
+                    {if isset($smarty.request.cc_numb) && $smarty.request.cc_numb}value="{$smarty.request.cc_numb}"{/if} />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-left-half glm-billing-credit glm-billing-card">
+            <div class="glm-billing-label glm-required">
+                Card Expiration
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    class="ccard"
+                    type="text"
+                    placeholder="MM/YY"
+                    name="cc_exp"
+                    required
+                    pattern="{literal}\d{2}/\d{2}{/literal}"
+                    {if isset($smarty.request.cc_exp) && $smarty.request.cc_exp}value="{$smarty.request.cc_exp}"{/if} />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-right-half glm-billing-credit glm-billing-card">
+            <div class="glm-billing-label glm-required">
+            C V V
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    class="ccard"
+                    type="text"
+                    placeholder="3 or 4 digit security code on back of card"
+                    name="cc_cvv"
+                    required
+                    pattern="{literal}\d{3,4}{/literal}"
+                    {if isset($smarty.request.cc_cvv) && $smarty.request.cc_cvv}value="{$smarty.request.cc_cvv}"{/if} />
+            </div>
+        </div>
+
+        <div class="glm-billing-field glm-billing-credit glm-billing-card">
+            <div clas="glm-billing-label">
+                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.
+            </div>
+            <div class="glm-billing-input">
+                <label>
+                    <input type="checkbox" name="cc_save">
+                    <strong>Yes, please save my card detail for future use.</strong>
+                </label>
+            </div>
+        </div>
+
+        </fieldset>
+
+<script>
+jQuery(document).ready(function($){
+
+    $('.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);
+        }
+    });
+
+    $('#glm-billing-use-saved-card').change(function(){
+        var isChecked = $(this).prop( 'checked' );
+        if ( isChecked ) {
+            $('.glm-billing-card').hide();
+            $('.ccard').prop('disabled', true);
+        } else {
+            $('.glm-billing-card').show();
+            $('.ccard').prop('disabled', false);
+        }
+    });
+
+});
+</script>