 , sum(case when a.payment_transaction_status = 'SUCCESS' then 1 else 0 end) as good
 FROM analytics_payment_captures a
 WHERE 1=1
-AND a.created_date>date_sub(now(),interval 1 day)
-GROUP BY
-  a.plugin_name
-, ifnull(a.plugin_property_4,'unknown')
-, ifnull(a.plugin_property_5,'unknown')
-, a.tenant_record_id
-UNION
-SELECT
-  a.plugin_name as plugin_name
-, ifnull(a.plugin_property_4,'unknown') as merchant_account
-, ifnull(a.plugin_property_5,'unknown') as payment_method
-, 3 as timeframe
+AND a.created_date>now() - interval '34' minute
+AND a.created_date<=now() - interval '4' minute
+GROUP BY
+  a.plugin_name
+, ifnull(a.plugin_property_4,'unknown')
+, ifnull(a.plugin_property_5,'unknown')
+, a.tenant_record_id
+UNION
+SELECT
+  a.plugin_name as plugin_name
+, ifnull(a.plugin_property_4,'unknown') as merchant_account
+, ifnull(a.plugin_property_5,'unknown') as payment_method
+, 4 as timeframe
 , a.tenant_record_id
 , 'CHARGEBACK' as transaction_type
 , count(1) as total

, sum(case when a.payment_transaction_status = 'SUCCESS' then 1 else 0 end) as good
FROM analytics_payment_refunds a
WHERE 1=1
AND a.created_date>date_sub(now(),interval 1 day)
GROUP BY
  a.plugin_name
, ifnull(a.plugin_property_4,'unknown')
, ifnull(a.plugin_property_5,'unknown')
, a.tenant_record_id
UNION
SELECT
  a.plugin_name as plugin_name
, ifnull(a.plugin_property_4,'unknown') as merchant_account
, ifnull(a.plugin_property_5,'unknown') as payment_method
, 3 as timeframe
, a.tenant_record_id
, 'VOID' as transaction_type
, count(1) as total

, sum(case when a.payment_transaction_status = 'SUCCESS' then 1 else 0 end) as good
FROM analytics_payment_credits a
WHERE 1=1
AND a.created_date>now() - interval '34' minute
AND a.created_date<=now() - interval '4' minute
GROUP BY
  a.plugin_name
, ifnull(a.plugin_property_4,'unknown')
, ifnull(a.plugin_property_5,'unknown')
, a.tenant_record_id
UNION
SELECT
  a.plugin_name as plugin_name
, ifnull(a.plugin_property_4,'unknown') as merchant_account
, ifnull(a.plugin_property_5,'unknown') as payment_method
, 4 as timeframe
, a.tenant_record_id
, 'PURCHASE' as transaction_type
, count(1) as total
