* @access public
* @return payment id
*/
- public function createPayment( $account, $payment )
+ public function createPayment( $account, $payment, $payment_method = '', $payment_data = '' )
{
// Insert the payment
$this->wpdb->insert(
'transaction_time' => date('Y-m-d H:i:s'),
'account' => $account,
'amount' => $payment,
- 'payment_method' => '',
- 'payment_data' => '',
+ 'payment_method' => $payment_method,
+ 'payment_data' => $payment_data,
),
array(
'%s',
// Determine the directory of the payment processor to load and instantiate it.
if ( $ccProcessor && isset( $this->config['proc_dir'][$ccProcessor] ) ) {
- require_once GLM_MEMBERS_BILLING_PLUGIN_LIB_PATH.'/paymentProcessors/'.$this->config['proc_dir'][$ccProcessor].'/paymentGateway.php';
+ require_once GLM_MEMBERS_BILLING_PLUGIN_LIB_PATH . '/paymentProcessors/' . $this->config['proc_dir'][$ccProcessor] . '/paymentGateway.php';
$CcProcessor = new PaymentGateway( $account );
}
'ccnumb' => $cardData['cc_numb'], // Card Number
'ccexp' => $cardData['cc_exp'], // Expiration Date
'cccode' => $cardData['cc_cvv'], // CCV - security code
- 'invoice' => 'billing-'//.$invoice_id // Invoice # is "reg-" plus cart ID
+ 'invoice' => 'billing-'//.$invoice_id // Invoice # is "reg-" plus cart ID
);
// Now try to run the card processor
$result = array(
'status' => 1,
'errors' => array(),
- 'ccResult' => $ccResult
+ 'ccResult' => $ccResult,
);
}
$_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' );
// Create new payment.
- $payment_id = $this->createPayment( $account_id, $amount );
+ $payment_id = $this->createPayment( $account_id, $amount, 'Credit Card' );
// Record the payment.
$this->recordPayment( $payment_id, $account_id, $amount, $invoice_id );
$_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' );
// Create new payment.
- $payment_id = $this->createPayment( $account_id, $amount );
+ $payment_id = $this->createPayment( $account_id, $amount, 'Credit Card' );
// Record the payment.
$this->recordPayment( $payment_id, $account_id, $amount, $invoices );
// Support class
$BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
- // Set transaction_time to current time.
- $_REQUEST['transaction_time'] = date('Y-m-d H:i:s');
- // grab data for the payments
- $payments = $this->insertEntry();
- $this->payment_id = $payments['fieldData']['id'];
- $BillingSupport->recordPayment( $this->payment_id, $_REQUEST['account'], $payments['fieldData']['amount'] );
+ // Make sure there's an amount
+ if ( $amount = filter_var( $_REQUEST['amount'], FILTER_VALIDATE_FLOAT ) ) {
+ $invoices = filter_var( $_REQUEST['invoices'], FILTER_VALIDATE_INT, array( 'flags' => FILTER_REQUIRE_ARRAY ) );
+ // echo '<pre>$amount: ' . print_r( $amount, true ) . '</pre>';
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ // Set transaction_time to current time.
+ $_REQUEST['transaction_time'] = date('Y-m-d H:i:s');
+ // grab data for the payments
+ $payments = $this->insertEntry();
+ $this->payment_id = $payments['fieldData']['id'];
+ $BillingSupport->recordPayment( $this->payment_id, $_REQUEST['account'], $amount, $invoices );
+ $paymentsAdded = true;
+ }
$view = 'editPayment';
break;
{include file='admin/billing/paymentHeader.html'}
-{if $paymentUpdated}<span class="glm-notice glm-flash-updated">Notification Updated</span>{/if}
-{if $paymentUpdateError}<span class="glm-notice glm-flash-updated">Notification Update Error</span>{/if}
-{if $paymentInsertError}<span class="glm-notice glm-flash-updated">Notification Insert Error</span>{/if}
-{if $paymentAdded}<span class="glm-notice glm-flash-updated">Notification Added</span>{/if}
+{if $paymentUpdated}<span class="glm-notice glm-flash-updated">Payment Updated</span>{/if}
+{if $paymentUpdateError}<span class="glm-notice glm-flash-updated">Payment Update Error</span>{/if}
+{if $paymentInsertError}<span class="glm-notice glm-flash-updated">Payment Insert Error</span>{/if}
+{if $paymentAdded}<span class="glm-notice glm-flash-updated">Payment Added</span>{/if}
<div id="billing-payment-form" class="glm-billing-form">
<form action="{$thisUrl}?page={$thisPage}&glm_action=payments" method="post">
+ <input type="hidden" id="total_payment_amount" name="amount" />
{if $payment_id}
- <input type="hidden" name="option" value="update">
- <input type="hidden" name="id" value="{$payment_id}">
+ <input type="hidden" name="option" value="update" />
+ <input type="hidden" name="id" value="{$payment_id}" />
{else}
- <input type="hidden" name="option" value="insert">
+ <input type="hidden" name="option" value="insert" />
{/if}
- <div class="glm-billing-field">
- <div class="glm-billing-label glm-required">
- Lookup Member Invoices By Account
- </div>
- <div class="glm-billing-input">
- <input id="member-account" name="account" type="hidden" name="filterAccounts" />
- <input id="account_name" name="member_account" />
- </div>
- </div>
- <div class="glm-billing-field">
- <div class="glm-billing-label glm-required">
- Select Invoices
- </div>
- <div class="glm-billing-input">
- </div>
- </div>
- <div class="glm-billing-field">
- <div class="glm-billing-label glm-required">
- Amount
- </div>
- <div class="glm-billing-input">
- <div id="total_amount"></div>
- <input type="text" id="total_payment_amount" type="hidden" name="amount" required>
- </div>
- </div>
- <div class="glm-billing-field">
- <div class="glm-billing-label glm-required">
- Notes
- </div>
- <div class="glm-billing-input">
- <textarea name="notes"></textarea>
- </div>
- </div>
+ <div class="glm-billing-field">
+ <div class="glm-billing-label glm-required">
+ Lookup Member Invoices By Account
+ </div>
+ <div class="glm-billing-input">
+ <input id="member-account" name="account" type="hidden" name="filterAccounts" />
+ <input id="account_name" name="member_account" />
+ </div>
+ </div>
+ <div class="glm-billing-field">
+ <div class="glm-billing-label glm-required">
+ Select Invoices
+ </div>
+ <div class="glm-billing-input" id="glm-payment-invoices">
+ </div>
+ </div>
+ <div class="glm-billing-field">
+ <div class="glm-billing-label glm-required">
+ Amount
+ </div>
+ <div class="glm-billing-input">
+ <div id="total_amount">$0.00</div>
+ </div>
+ </div>
+ <div class="glm-billing-field">
+ <div class="glm-billing-label">
+ Payment Method
+ </div>
+ <div class="glm-billing-input">
+ <input name="payment_method" />
+ </div>
+ </div>
+ <div class="glm-billing-field">
+ <div class="glm-billing-label">
+ Payment Notes
+ </div>
+ <div class="glm-billing-input">
+ <input name="payment_data" />
+ </div>
+ </div>
<input class="button button-primary" type="submit" value="{if $payment_id}Save{else}Create{/if} Payment">
</form>
{/foreach}
]
+ function updateInvoiceList( invoices ) {
+ // Clear the invoices
+ $('#glm-payment-invoices').html('');
+ for ( var i = 0; i < invoices.length; i++ ) {
+ $('#glm-payment-invoices').append( '<label>' +
+ '<input type="checkbox" class="glm-invoice-item" name="invoices[' + invoices[i].id + ']" data-amount="' + invoices[i].balance + '" />$' +
+ invoices[i].balance + '</label><br />' );
+ }
+ }
+
+ function getPageTotal(){
+ // Caclulate the total for this page.
+ var page_total = parseFloat( '0.00' );
+ $('.glm-invoice-item').each(function(){
+ var isChecked = $(this).prop('checked');
+ if ( isChecked ) {
+ page_total = page_total + parseFloat( $(this).data('amount') );
+ }
+ });
+ $('#total_amount').html( '$' + page_total );
+ $('#total_payment_amount').val( page_total );
+ }
+
+ $('#glm-payment-invoices').on( 'click', '.glm-invoice-item', function(){
+ getPageTotal();
+ });
+
// Setup autocomplete
$('#account_name').autocomplete({
source: availableAccounts,
account: ui.item.id
},
success: function( results ) {
- console.log( results );
+ updateInvoiceList( results );
+ //console.log( results );
},
});
},
change: function( event, ui) {
if( ui.item == null ) {
$('#member-account').val( '' );
+ $('#glm-payment-invoices').html('');
+ getPageTotal();
}
},
});