diff --git a/ding_debt.make b/ding_debt.make index 29cd0b2..5461777 100644 --- a/ding_debt.make +++ b/ding_debt.make @@ -3,26 +3,26 @@ core = 7.x projects[ding_base][type] = "module" projects[ding_base][download][type] = "git" -projects[ding_base][download][url] = "git@github.com:ding2/ding_base.git" +projects[ding_base][download][url] = "git@github.com: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] = "git@github.com:ding2/ding_dibs.git" +projects[ding_dibs][download][url] = "git@github.com: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] = "git@github.com:ding2/ding_popup.git" +projects[ding_popup][download][url] = "git@github.com: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] = "git@github.com:ding2/ding_user.git" +projects[ding_user][download][url] = "git@github.com: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] = "git@github.com:ding2/ding_provider.git" +projects[ding_provider][download][url] = "git@github.com:ding2tal/ding_provider.git" projects[ding_provider][download][branch] = "development" diff --git a/ding_debt.module b/ding_debt.module index b2988d4..409f445 100644 --- a/ding_debt.module +++ b/ding_debt.module @@ -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'] + ); } diff --git a/plugins/content_types/debts/debts.inc b/plugins/content_types/debts/debts.inc index d230dff..8165465 100644 --- a/plugins/content_types/debts/debts.inc +++ b/plugins/content_types/debts/debts.inc @@ -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; @@ -36,18 +30,19 @@ 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'); @@ -55,7 +50,6 @@ function ding_debt_debts_content_type_render($subtype, $conf, $panel_args, $cont return $block; } - /** * Form for configuring the content type. * @@ -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, @@ -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, ',', ' ') . ' *' : 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, ',', ' ') . ' *' : 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' => '