For my current project for CivicActions I needed a report that displays actual payments against orders. So I added support for most of the payment fields in the uc_payment_receipts table. Payments can work as a base table, or joined in for an order-based or user-based view.

For my report I needed the transaction ID from the payment processor. Since that value (along with the processor transaction type & the payment module) are saved serialized in the 'data' column I added field handlers for those as well (can't have filter handlers for those obviously.)

I hope this will be helpful to some people. Would appreciate a review of this patch.

Comments

laken’s picture

Bump - can anyone review my patch?

hanoii’s picture

got your mail, will try to review it when I have a chance, quite busy at the moment.

charlie-s’s picture

This is awesome, taking a look now.

charlie-s’s picture

In uc_views_handler_field_payment_txn_id.inc it was returning an empty value for me. My transaction ID was coming from PayPal if that has anything to do with anything.

I changed

return parent::render($values);

to

return $payment->comment;

and am getting the transaction ID that I need. Thank you very much for providing this code.

m.stenta’s picture

StatusFileSize
new7.51 KB

Wow! Thank you so much for this. Really saved me some time today.

I rerolled the patch from root folder of the the latest dev snapshot (to comply with patching standards: http://drupal.org/node/707484).

I did not factor in the changes suggested in #4 above because I'm not sure how that would affect non-PayPal payments. Someone should do some testing with that, or maybe see if there's already another issue with the way PayPal payments are registered (perhaps it doesn't follow the correct rules in the first place?).

Attached is the new patch.

jvieille’s picture

Edit: $data['uc_payment_receipts']['receipt_id'] = array( needs a numeric handler for the filter (It used to work, but suddenly broke!)

Thanks for submitting this.
Bellow the code that works with Ubercart standard - the tx part of this patch seems specific, this did not match my configuration

For my report I needed the transaction ID from the payment processor. Since that value (along with the processor transaction type & the payment module) are saved serialized in the 'data' column I added field handlers for those as well (can't have filter handlers for those obviously.)

Bellow the code that was helpful for me, i.e including the payment method that missed and removing the transaction stuff. Only the file uc_views.views.inc is affected

function uc_views_views_data() {
/* at the end of this function */

+  // uc_payment_receipts table
+  $data['uc_payment_receipts']['table']['group'] = t('Ubercart payment');
+  $data['uc_payment_receipts']['table']['base'] = array(
+    'field' => 'receipt_id',
+    'title' => t('Ubercart payment receipt'),
+    'help' => t("Payments posted against Ubercart orders."),
+  );
+
+  $data['uc_payment_receipts']['table']['join']['uc_orders'] = array(
+    'left_field' => 'order_id',
+    'field' => 'order_id',
+  );
+
+  $data['uc_payment_receipts']['table']['join']['users'] = array(
+    'left_field' => 'uid',
+    'field' => 'uid',
+  );
+
+  $data['uc_payment_receipts']['receipt_id'] = array(
+    'title' => t('Receipt ID'),
+    'help' => t('ID of the payment reciept'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+  );
+
+  $data['uc_payment_receipts']['amount'] = array(
+    'title' => t('Amount'),
+    'help' => t('Amount of the payment'),
+    'field' => array(
+      'handler' => 'uc_views_handler_field_money_amount',
+      'click sortable' => TRUE,
+      'float' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_float',
+    ),
+  );
+
+  $data['uc_payment_receipts']['comment'] = array(
+    'title' => t('Comment'),
+    'help' => t('Payment comment'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+
+  $data['uc_payment_receipts']['received'] = array(
+    'title' => t('Received date'),
+    'help' => t('Date/time payment was received'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+  );
+  $data['uc_payment_receipts']['method'] = array(
+    'title' => t('Method'),
+    'help' => t('Payment method'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );

  return $data;
}
function uc_views_views_handlers() {

/* at the end of this function */

      'uc_views_handler_filter_cart_current' => array('parent' => 'views_handler_filter_boolean_operator'),
+      'uc_views_handler_field_payment_module' => array('parent' => 'views_handler_field'),
    ),
  );
}