<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://secure.freeside.biz/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=OudarAlget</id>
		<title>Freeside - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://secure.freeside.biz/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=OudarAlget"/>
		<link rel="alternate" type="text/html" href="https://secure.freeside.biz/mediawiki/index.php/Special:Contributions/OudarAlget"/>
		<updated>2026-05-28T19:16:40Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.7</generator>

	<entry>
		<id>https://secure.freeside.biz/mediawiki/index.php?title=Batch_Refactor&amp;diff=4008</id>
		<title>Batch Refactor</title>
		<link rel="alternate" type="text/html" href="https://secure.freeside.biz/mediawiki/index.php?title=Batch_Refactor&amp;diff=4008"/>
				<updated>2008-12-19T09:56:14Z</updated>
		
		<summary type="html">&lt;p&gt;OudarAlget: varlid&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ouricalolo&lt;br /&gt;
eltcla&lt;br /&gt;
domc4ta&lt;br /&gt;
== Spec ==&lt;br /&gt;
&lt;br /&gt;
=== Multiple batches in transit ===&lt;br /&gt;
&lt;br /&gt;
It needs to be possible for multiple batches to be in transit.&lt;br /&gt;
Currently you download the &amp;quot;pending batch&amp;quot; and have to upload results&lt;br /&gt;
before download again, otherwise you download duplicates.  I'm&lt;br /&gt;
thinking the download act could create a distinct batch number and assign it to the downloaded records (schema change: add&lt;br /&gt;
cust_pay_batch.batchnum and also create a table with batchnum primary&lt;br /&gt;
key to store batch date, status (pending result upload, done, etc.) ).&lt;br /&gt;
I guess this means the upload result wouldn't have to *wipe* records&lt;br /&gt;
from cust_pay_batch either, they could be marked with an individal&lt;br /&gt;
item status too?&lt;br /&gt;
&lt;br /&gt;
Note on schema changes: See /SCHEMA_CHANGE for instructions.&lt;br /&gt;
&lt;br /&gt;
  I am thinking the &amp;quot;right&amp;quot; way to do this is to add the batchnum as&lt;br /&gt;
  you suggest (i think that used to be there, but was usurped for a automatic&lt;br /&gt;
  primary key), and extra fields that show the response.   This way one&lt;br /&gt;
  need to consult a single row to know the status of a particular batch &amp;quot;event.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
I'm pretty sure we're on the same page here.  I agree we want batchnum&lt;br /&gt;
and status fields added to cust_pay_batch.  I still want to add a&lt;br /&gt;
separate table (say, &amp;quot;pay_batch&amp;quot; or &amp;quot;batch&amp;quot; or something). with batchnum&lt;br /&gt;
primary key a status column.  pay_batch.status would be the batch status&lt;br /&gt;
as a shole, and cust_pay_batch.status would be the status of the&lt;br /&gt;
individual line item (I don't think we would want the individual&lt;br /&gt;
cust_pay_batch.status columns to be a &amp;quot;denormalized&amp;quot; whole batch status&lt;br /&gt;
just for a speculative optimization - joins are easy).&lt;br /&gt;
&lt;br /&gt;
=== Support echeck batching in addition to credit card ===&lt;br /&gt;
&lt;br /&gt;
Add fields and a payby flag for CARD vs CHECK to cust_pay_batch.&lt;br /&gt;
&lt;br /&gt;
Add the fields necessary for ACH/echeck (account number, routing&lt;br /&gt;
number, bank name, probably a couple other things) to cust_pay_batch.&lt;br /&gt;
&lt;br /&gt;
pay_batch table should get a &amp;quot;payby&amp;quot; field to&lt;br /&gt;
distinguish CARD vs CHEK batch type.&lt;br /&gt;
&lt;br /&gt;
  The 'payby' need only be in one place in the batching system.  One option&lt;br /&gt;
  is to do as in the svc_ tables, and the other is to generalize the fields&lt;br /&gt;
  in the table.  I tend towards the latter, but it doesn't really matter&lt;br /&gt;
  to me.  Possibly abandonment/deprecation of the existing table would help&lt;br /&gt;
  avoid breakage for anyone relying on the current schema.  Are there many&lt;br /&gt;
  out there?&lt;br /&gt;
&lt;br /&gt;
  This is my only customer using batching.  Moving to a new table instead&lt;br /&gt;
  of modifying cust_pay_batch is totally acceptable to me if you want to do that.&lt;br /&gt;
&lt;br /&gt;
=== Make sure old invoices don't generate multiple &amp;quot;batch card&amp;quot; events while the first one is in transit ===&lt;br /&gt;
&lt;br /&gt;
This is from old notes, I'm not very sure about my implementation idea:&lt;br /&gt;
batched payments need an (optional i guess) invnum&lt;br /&gt;
or better yet some sort of ref back to a freeside table where&lt;br /&gt;
invnums are referenced.&lt;br /&gt;
&lt;br /&gt;
  It seems to me what this requires is just a&lt;br /&gt;
  sense of the batch being &amp;quot;done&amp;quot; (posted).  If their are no pending batches&lt;br /&gt;
  with this invoice number and it still isn't paid, we need to try&lt;br /&gt;
  again.&lt;br /&gt;
&lt;br /&gt;
Ah, I had some time to think about my old notes and remembered why I had&lt;br /&gt;
thought a new table would be useful:&lt;br /&gt;
&lt;br /&gt;
One batched payment should be able to refer to multiple invoices.  We&lt;br /&gt;
don't currently consolidate outstanding payments from multiple invoices,&lt;br /&gt;
but we could (and should eventually).  So the batch table should have&lt;br /&gt;
the invnum removed, and a new table should be added with 3-4 columns:&lt;br /&gt;
&lt;br /&gt;
  primary key (serial)&lt;br /&gt;
  paybatchnum (foreign key into cust_pay_batch)&lt;br /&gt;
  invnum (foreign key into cust_bill)&lt;br /&gt;
  maybe amount?  so we know how much was triggered by each invoice&lt;br /&gt;
&lt;br /&gt;
Currently they'll just be a single entry for each paybatchnum &lt;br /&gt;
(cust_pay_batch record) with one invoice, but eventually one&lt;br /&gt;
cust_pay_batch record could be a batched payment for multiple invoices.&lt;br /&gt;
&lt;br /&gt;
Does that make sense?  We can consider this still part of the required &lt;br /&gt;
items - &amp;quot;make sure old invoices don't generate multiple &amp;quot;batch card&amp;quot;&lt;br /&gt;
events while the first one is in transit&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
See my previous email wrt removing invnum from cust_pay_batch and adding&lt;br /&gt;
a new table.&lt;br /&gt;
&lt;br /&gt;
So that and then basically the batching code just needs a quick check&lt;br /&gt;
added to make sure there's no batched transaction for that invoice,&lt;br /&gt;
either awaiting download or downloaded but awaiting response upload.&lt;br /&gt;
Then no matter how old an invoice is and how many batch retries are in&lt;br /&gt;
the invoice events, duplicate transactions can't be batched.&lt;br /&gt;
&lt;br /&gt;
=== Trigger events on batch decline ===&lt;br /&gt;
&lt;br /&gt;
When processing results, ability to trigger events on batch decline (extend invoice events probably?  so anything you can trigger there&lt;br /&gt;
you can trigger on a batch decline.&lt;br /&gt;
&lt;br /&gt;
=== Support Canadian PAP echeck download and upload format ===&lt;br /&gt;
&lt;br /&gt;
Support Canadian PAP echeck download for batches and upload&lt;br /&gt;
format for batch results.&lt;br /&gt;
&lt;br /&gt;
=== Route transactions to real-time gateway or batch ===&lt;br /&gt;
&lt;br /&gt;
Send real-time transactions to the B:OP realtime gateway but&lt;br /&gt;
batch all non-realtime transactions.  Probably add an option to&lt;br /&gt;
FS::cust_main::collect method to specify &amp;quot;this is a real-time&lt;br /&gt;
transaciton&amp;quot;, send anything without that flag to batch, and have&lt;br /&gt;
the web UI and self-service set the flag.&lt;br /&gt;
&lt;br /&gt;
* FS::ClientAPI::Signup&lt;br /&gt;
* FS::MyAccount::order_pkg and process_payment&lt;br /&gt;
* httemplate/misc/bill.cgi&lt;br /&gt;
* httemplate/misc/process/payment.cgi&lt;br /&gt;
&lt;br /&gt;
=== Consolidate multiple payments ===&lt;br /&gt;
&lt;br /&gt;
Have the system only batch a single payment when there are multiple outstanding  &lt;br /&gt;
invoices.  This could be tricky to do right and support the real-time &lt;br /&gt;
transactions too, so for now, just hack things so that the &lt;br /&gt;
bits that add an entry to the batch table could check to see if &lt;br /&gt;
there's already an open/not-yet-downloaded transaction for that &lt;br /&gt;
customer, and instead of adding a new entry, update the existing one and &lt;br /&gt;
add an additional record in the new table above.  Hoepfully that makes  &lt;br /&gt;
sense too.  :)&lt;br /&gt;
&lt;br /&gt;
=== Reporting ===&lt;br /&gt;
&lt;br /&gt;
High level view of the batches that have been submitted.&lt;br /&gt;
&lt;br /&gt;
(these are rough examples, actual columns don't need to be exactly labeled/ordered like this)&lt;br /&gt;
&lt;br /&gt;
(use httemplate/search/elements/search.html framework)&lt;br /&gt;
&lt;br /&gt;
{| border=1 cellspacing=0&lt;br /&gt;
! BatchID !! SubmitDate !! Updated !! Type !! Submitted !! Collected !! Rejected !! Pending&lt;br /&gt;
|-&lt;br /&gt;
| AA0011 || 2006-05-01 || 2006-05-10 || echeck || $12,505.33 || $ 8,000.00 || $1,000.00 || $3,505.33&lt;br /&gt;
|-&lt;br /&gt;
| AA0012 || 2006-05-02 || 2006-05-09 || creditcard || $3,355.00 || $2,355.00 || $1,000.00&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Selectale drill down of each batch structured like:&lt;br /&gt;
&lt;br /&gt;
Batch : AA0012&lt;br /&gt;
{| border=1 cellspacing=0&lt;br /&gt;
! AccountNumber !! Amount !! Status !! DateUpdated&lt;br /&gt;
|- &lt;br /&gt;
| 1122 || $3.16 || collected&lt;br /&gt;
|-&lt;br /&gt;
| 1321 || $3.16 || (no update)&lt;br /&gt;
|- &lt;br /&gt;
| 1011 || $3.16 || NSF&lt;br /&gt;
|- &lt;br /&gt;
| 2112 || $3.16 || collected&lt;br /&gt;
|-&lt;br /&gt;
| 1672 || $3.16 || payment recalled&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Feeping Creature Reporting ===&lt;br /&gt;
&lt;br /&gt;
Declined (batch) CC/echeck transaction reports... by date range, agent, anything else?&lt;br /&gt;
&lt;br /&gt;
(okay if feeping creatures go over the estimate a little)&lt;br /&gt;
&lt;br /&gt;
== First draft revisions ==&lt;br /&gt;
&lt;br /&gt;
=== Just not done yet... ===&lt;br /&gt;
&lt;br /&gt;
* 1.6 Route trasactions to real-time gateway or batch&lt;br /&gt;
* 1.9 Feeping Creature Reporting&lt;br /&gt;
&lt;br /&gt;
=== browse/cust_pay_batch.cgi and browse/pay_batch.cgi ===&lt;br /&gt;
&lt;br /&gt;
* browse/cust_pay_batch.cgi and browse/pay_batch.cgi should use include('elements/browse.html' ... ), or probably just move to the search/ directory and use include('elements/search.html' ...), same difference&lt;br /&gt;
&lt;br /&gt;
* pay_batch.cgi should get an &amp;quot;advanced search&amp;quot; prepage that lets you pick status and enter dates (use the calendar popup like other date entries)&lt;br /&gt;
&lt;br /&gt;
=== Linking table, or, that's very clever, but bankers are boring ===&lt;br /&gt;
&lt;br /&gt;
* Add the linking table described in 1.3 and use it to explicitly record the invoices and amounts which make up the aggregate batched payment.  The checking code can continue to work like it does now, I don't care.&lt;br /&gt;
&lt;br /&gt;
=== False laziness ===&lt;br /&gt;
&lt;br /&gt;
* A very large chunk of code for running invoice events was copied from FS::cust_main to FS::cust_pay_batch.  Refactor that so it isn't so bad.  Perhaps a class method in FS::part_bill_event for the search and most of the rest as one or more regular FS::part_bill_event methods.&lt;br /&gt;
&lt;br /&gt;
=== Hmm... ===&lt;br /&gt;
&lt;br /&gt;
* FS::cust_bill::batch_card has a race condition and could wind up creating multiple open batches.  Unlikely.  Need to think about how to solve this more.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Oh, just one last thing...&amp;quot; ===&lt;br /&gt;
&lt;br /&gt;
* (I can take care of this -[[User:Ivan|Ivan]]) Add useful links to main menu and ACL.&lt;br /&gt;
&lt;br /&gt;
== Future directions? ==&lt;br /&gt;
&lt;br /&gt;
Separate buckets for batch transactions and agent overrides to&lt;br /&gt;
send/mark particular agent transactions (for particular kinds&lt;br /&gt;
of cards or echeck) against particular buckets.  This may make more&lt;br /&gt;
sense if you take a look at the payment_gateway and&lt;br /&gt;
agent_payment_gateway tables and the web UI off view/edit agents that&lt;br /&gt;
sets them up - basically agent-specific batch buckets to go along&lt;br /&gt;
with the agent-specific realtime gateways.&lt;/div&gt;</summary>
		<author><name>OudarAlget</name></author>	</entry>

	</feed>