// Now that the invoice is created. Do payment Processing.
- // If there's any errors then re-show the form.
+ // If there's any rrors then re-show the form.
if ( $error ) {
// Remove the invoice created.
if ( $invoice_id ) {
// Make the Payment using Billing Support Class
$errors = $BillingSupport->makePayment( $account_id, $invoices, $amount );
- // echo '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
+ echo '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
- if ( $errors ) {
+ // Errors will be an array
+ if ( isset( $errors ) && !empty( $errors ) ) {
$paymentError = true;
- $messages[] = '<span style="color: red;">'.$errors.'</span>';
+ foreach ( $errors as $error ) {
+ $messages[] = '<span style="color: red;">'.$error.'</span>';
+ }
// Load DataClass for Management.
require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php';
$Management = new GlmDataBillingManagement( $this->wpdb, $this->config );
{/if}
- <form action="{$thisUrl}?page={$thisPage}&glm_action=billing&option=makePayment" method="post">
+ <form id="PaymentForm" action="{$thisUrl}?page={$thisPage}&glm_action=billing&option=makePayment" method="post">
<input type="hidden" name="page" value="{$thisPage}">
<input type="hidden" name="glm_action" value="billing">
<input type="hidden" name="option" value="createPayment">
{if $invoices}
{foreach $invoices as $invoice}
<label>
- <input type="checkbox" name="invoices[]" data-amount="{$invoice.balance}" value="{$invoice.id}" checked required />
+ <input type="checkbox" name="invoices[]" data-amount="{$invoice.balance}" value="{$invoice.id}" checked />
${$invoice.balance} Due {$invoice.due_date}
</label>
{/foreach}
$('#billing-amount').val( $(this).find('option:selected').data( 'amount') );
});
+ $('#PaymentForm').submit(function(){
+ var invoice_amount = $('#total_amount').val();
+ if ( invoice_amount == 0 ) {
+ alert( 'You have to select at least one invoice with an amount due.' );
+ return false;
+ } else {
+ return true;
+ }
+ return false;
+ });
+
function getPageTotal(){
// Calculate the total for this page.
// Get the member_renewing amount.
- if ( $('input[name^=invoices]:checked').length ) {
+ if ( $('input[name^=invoices]:checked').length === 1 ) {
var invoice_amount = parseFloat( $('input[name^=invoices]:checked').data('amount') );
+ } else if ( $('input[name^=invoices]:checked').length > 1 ) {
+ var invoice_amount = 0.00;
+ $('input[name^=invoices]:checked').each(function(){
+ invoice_amount += parseFloat( $(this).data('amount') );
+ });
} else {
var invoice_amount = 0.00;
}