Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B14 updates #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ding_debt.make
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ core = 7.x

projects[ding_base][type] = "module"
projects[ding_base][download][type] = "git"
projects[ding_base][download][url] = "[email protected]:ding2/ding_base.git"
projects[ding_base][download][url] = "[email protected]:ding2tal/ding_base.git"
projects[ding_base][download][branch] = "development"

projects[ding_dibs][type] = "module"
projects[ding_dibs][download][type] = "git"
projects[ding_dibs][download][url] = "[email protected]:ding2/ding_dibs.git"
projects[ding_dibs][download][url] = "[email protected]:ding2tal/ding_dibs.git"
projects[ding_dibs][download][branch] = "development"

projects[ding_popup][type] = "module"
projects[ding_popup][download][type] = "git"
projects[ding_popup][download][url] = "[email protected]:ding2/ding_popup.git"
projects[ding_popup][download][url] = "[email protected]:ding2tal/ding_popup.git"
projects[ding_popup][download][branch] = "development"

projects[ding_user][type] = "module"
projects[ding_user][download][type] = "git"
projects[ding_user][download][url] = "[email protected]:ding2/ding_user.git"
projects[ding_user][download][url] = "[email protected]:ding2tal/ding_user.git"
projects[ding_user][download][branch] = "development"

projects[ding_provider][type] = "module"
projects[ding_provider][download][type] = "git"
projects[ding_provider][download][url] = "[email protected]:ding2/ding_provider.git"
projects[ding_provider][download][url] = "[email protected]:ding2tal/ding_provider.git"
projects[ding_provider][download][branch] = "development"

25 changes: 24 additions & 1 deletion ding_debt.module
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,31 @@ function ding_debt_ding_provider_user() {

/**
* Callback for successful payment transaction.
*
* @param array $transaction
*
* @return TRUE
*/
function ding_debt_payment_callback($transaction) {
return ding_provider_invoke_page('debt', 'payment_received', $transaction['payment_price'], $transaction['params']['debt_ids'], $transaction['payment_order_id']);
// Get user account.
$account = user_load($transaction['customer_uid']);
// Get user credentials.
$creds = ding_user_get_creds($account);
// Get payment information from provider.
$payment_information = ding_provider_invoke_page(
'debt',
'get_payment_service_information',
$account,
$transaction['payment_price']
);
// Invoke payment service.
return ding_provider_invoke_page(
'debt',
'payment_received',
$transaction['payment_price'],
$transaction['params']['debt_ids'],
$transaction['payment_transaction_id'],
$payment_information['order_id']
);
}

211 changes: 87 additions & 124 deletions plugins/content_types/debts/debts.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ $plugin = array(
);

/**
* Render the block
* Render the block.
*/
function ding_debt_debts_content_type_render($subtype, $conf, $panel_args, $context) {
$preload_debts = &drupal_static('ids');
$account = isset($context->data) ? $context->data : NULL;
$preload_ids = array();
$items = array();
$debt_list = array();
$rows = array();
$row = array();
$total_amount = 0;
$has_invoiced_fees = FALSE;

Expand All @@ -36,26 +30,26 @@ function ding_debt_debts_content_type_render($subtype, $conf, $panel_args, $cont

if (count($debts) == TRUE) {
foreach ($debts as $debt) {
// invoiced fees can't be paid online.
if ( !$debt->invoice_number ) {
// Invoiced fees can't be paid online.
if (!$debt->invoice_number) {
$total_amount += $debt->amount;
$total_amount -= $debt->amount_paid;
$debt->is_invoice = FALSE;
} else {
}
else {
$debt->is_invoice = TRUE;
$has_invoiced_fees = TRUE;
}
}
$build = ding_provider_get_form('ding_debt_debts_form', $debts, $has_invoiced_fees, $total_amount);
$block->content = render($build);
$build = ding_provider_get_form('ding_debt_debts_form', $debts, $has_invoiced_fees, $total_amount);
$block->content = render($build);
}
else {
$block->content = t('No debts');
}
return $block;
}


/**
* Form for configuring the content type.
*
Expand All @@ -66,11 +60,17 @@ function ding_debt_debts_content_type_edit_form($form, &$form_state) {
}

/**
* Implements a drupal form, which implements a pay button and debts data
* Implements a drupal form, which implements a pay button and debts data.
*/
function ding_debt_debts_form($form, &$form_state, $debts = array(), $has_invoiced_fees, $total_amount) {
function ding_debt_debts_form($form, &$form_state, $debts, $has_invoiced_fees, $total_amount) {
ding_debt_form_details($form, $debts, $has_invoiced_fees, $total_amount);

if ($total_amount) {
// Init debts.
if (!isset($debts)) {
$debts = array();
}

$form['debt_data'] = array(
'#type' => 'value',
'#value' => $debts,
Expand All @@ -97,123 +97,80 @@ function ding_debt_debts_form($form, &$form_state, $debts = array(), $has_invoic
}

/**
* Helper function to render the details of the debt form
* Helper function to render the details of the debt form.
*/
function ding_debt_form_details(&$form, $debts, $has_invoiced_fees, $total_amount) {
$options = array();
$header = array(
'fee_date' => t('Fee date'),
'title' => t('Title'),
'type' => t('Fee type'),
'amount' => t('Amount'),
);

foreach ($debts as $debt) {
$options[$debt->id] = array(
'#disabled' => $debt->is_invoice,
'fee_date' => array(
'data' => format_date(strtotime(check_plain($debt->date)), 'date_only'),
'class' => 'feedate',
),
'title' => array(
'data' => $debt->display_name,
'class' => 'feetitle',
),
'type' => array(
'data' => t($debt->type),
'class' => 'feetype',
),
'amount' => array(
'data' => ( $debt->is_invoice ) ? number_format(($debt->amount - $debt->amount_paid), 2, ',', ' ') . ' <span class="note">*</span>' : number_format(($debt->amount - $debt->amount_paid), 2, ',', ' '),
'class' => 'feeamount',
$item = array(
'#type' => 'material_item',
'#id' => $debt->id,
'#title' => $debt->display_name,
'#information' => array(
'fee_date' => array(
'label' => t('Fee date'),
'data' => format_date(strtotime(check_plain($debt->date)), 'date_only'),
'class' => 'fee-date',
'#weight' => 0,
),
'fee_type' => array(
'label' => t('Fee cause'),
'data' => $debt->type,
'class' => 'fee-type',
'#weight' => 4,
),
'amount' => array(
'label' => t('Amount'),
'data' => $debt->is_invoice ? number_format(($debt->amount - $debt->amount_paid), 2, ',', ' ') . ' <span class="note">*</span>' : number_format(($debt->amount - $debt->amount_paid), 2, ',', ' '),
'class' => 'fee_amount',
'#weight' => 8,
),
),
);
}
// add total
$options['total_amount'] = array(
'#disabled' => TRUE,
'fee_date' => array(
'data' => t('Total'),
'class' => 'feedate',
'header' => TRUE
),
'title' => array(
'data' => '',
'class' => 'feetitle',
'header' => TRUE
),
'type' => array(
'data' => '',
'class' => 'feetype',
'header' => TRUE
),
'amount' => array(
'data' => number_format($total_amount, 2, ',', ' '),
'class' => 'feeamount',
'header' => TRUE
),
);

if ($has_invoiced_fees) {
$options['invoice-note'] = array(
'#disabled' => TRUE,
'fee_date' => array(
'data' => '',
'class' => 'fee-invoice-note',
'header' => TRUE
),
'title' => array(
'data' => t("* Invoiced fees can't be paid online."),
'class' => 'fee-invoice-note',
'header' => TRUE
),
'type' => array(
'data' => '',
'class' => 'fee-invoice-note',
'header' => TRUE
),
'amount' => array(
'data' => '',
'class' => 'fee-invoice-note',
'header' => TRUE
),
);
// Add material number if available.
if (isset($debt->material_number)) {
$item['#information']['material-number'] = array(
'label' => t('Material no.'),
'data' => $debt->material_number,
'class' => 'material-number',
'#weight' => -4,
);
}

// Add the debt to the form.
$form['debts'][$debt->id] = $item;
}
$form['debts'] = array(
'#type' => 'tableselect_form',
'#header' => $header,
'#options' => $options,
'#empty' => t('No Debt'),
'#process' => array('ding_base_element_process_tableselect_form', '_ding_debt_debt_disable'),
'#weight' => -1,

// Add item with the total amount.
$form['total'] = array(
'#type' => 'item',
'#prefix' => '<div class="total-amount">',
'#suffix' => '</div>',
'#markup' => t('Total') . ': <span class="amount">' . number_format($total_amount, 2, ',', ' ') . '</span>',
);
}

/**
* Process function to disable checkboxes for unpayable debts.
*/
function _ding_debt_debt_disable($element) {
foreach ($element['#options'] as $key => $choice) {
if (isset($choice['#disabled']) && $choice['#disabled']) {
$element[$key]['#disabled'] = TRUE;
$element[$key]['#attributes']['title'] = t('Not payable here');
}
if ($has_invoiced_fees) {
$form['notice'] = array(
'#type' => 'item',
'#prefix' => '<div class="messages warning">',
'#suffix' => '</div>',
'#markup' => t("* Invoiced fees can't be paid online."),
);
}
return $element;
}


/**
* Submit handler for the pay all submit button.
*/
function ding_debt_debts_form_submit_pay_all($form, &$form_state) {
$amount = 0;
$debts = array_filter($form_state['values']['debt_data']);
$debts = $form_state['values']['debt_data'];
foreach ($debts as $debt_id => $debt_data) {
if ( !$form_state['values']['debt_data'][$debt_id]->invoice_number ) {
if (!$form_state['values']['debt_data'][$debt_id]->invoice_number) {
$amount += $form_state['values']['debt_data'][$debt_id]->amount;
$amount -= $form_state['values']['debt_data'][$debt_id]->amount_paid;
} else {
}
else {
unset($debts[$debt_id]);
}
}
Expand All @@ -225,25 +182,31 @@ function ding_debt_debts_form_submit_pay_all($form, &$form_state) {
*/
function ding_debt_debts_form_submit_pay_selected($form, &$form_state) {
$amount = 0;
$debts = array();
foreach (array_filter($form_state['values']['debts']) as $debt_id => $debt_data) {
if ( !$form_state['values']['debt_data'][$debt_id]->invoice_number ) {
$amount += $form_state['values']['debt_data'][$debt_id]->amount;
$amount -= $form_state['values']['debt_data'][$debt_id]->amount_paid;
$debts[$debt_id] = $form_state['values']['debt_data'][$debt_id];
}
$payments = array();
$debts = $form_state['values']['debt_data'];
foreach ($debts as $debt_id => $debt_data) {
if (!empty($form_state['values'][$debt_id])) {
if (!$debt_data->invoice_number) {
$amount += $form_state['values']['debt_data'][$debt_id]->amount;
$amount -= $form_state['values']['debt_data'][$debt_id]->amount_paid;
$payments[$debt_id] = $form_state['values']['debt_data'][$debt_id];
}
}
}
ding_debt_debts_perform_payment($debts, $amount, $form_state);

ding_debt_debts_perform_payment($payments, $amount, $form_state);
}

/**
* Performs the payment
* Performs the payment.
*/
function ding_debt_debts_perform_payment($debts, $amount, &$form_state) {
global $user;
if ($amount > 0) {
$params = array('params' => array('debt_ids' => array_keys($debts)));
$params = array(
'params' => array(
'debt_ids' => array_keys($debts),
'debts' => $debts,
),
);
$url = ding_provider_invoke('payment', 'get_url', $amount, $params, 'ding_debt_payment_callback');

if ($url) {
Expand Down