Bug 21043 - Add POST endpoint for patron debits
Summary: Add POST endpoint for patron debits
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: master
Hardware: All All
: P5 - low new feature (vote)
Assignee: Agustín Moyano
QA Contact: Kyle M Hall
URL: https://wiki.koha-community.org/wiki/...
Keywords:
Depends on: 21002 29453
Blocks: 15165 28544
  Show dependency treegraph
 
Reported: 2018-07-05 18:49 UTC by Tomás Cohen Arazi
Modified: 2023-07-03 12:07 UTC (History)
8 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00


Attachments
Add routes to add debits (514.58 KB, application/pdf)
2022-12-15 13:26 UTC, Michaela Sieber
Details
Bug 21043: Untested code (3.48 KB, patch)
2022-12-15 15:55 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 21043: Add debit REST endpoint (3.87 KB, patch)
2023-02-27 15:39 UTC, Agustín Moyano
Details | Diff | Splinter Review
Bug 21043: (follow-up) fix minor bugs and add test case (5.36 KB, patch)
2023-02-27 15:39 UTC, Agustín Moyano
Details | Diff | Splinter Review
Bug 21043: Add debit REST endpoint (22.54 KB, patch)
2023-02-27 15:57 UTC, Agustín Moyano
Details | Diff | Splinter Review
Bug 21043: Add debit REST endpoint (22.60 KB, patch)
2023-02-28 16:02 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 21043: Add debit REST endpoint (22.54 KB, patch)
2023-03-01 15:36 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 21043: (follow-up) Handle exceptions and switch to debit response (4.77 KB, patch)
2023-03-01 15:36 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 21043: (follow-up) Return Koha::Account::Debit (1.17 KB, patch)
2023-03-01 15:36 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 21043: Add debit REST endpoint (22.60 KB, patch)
2023-03-02 15:43 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 21043: Handle exceptions and switch to debit response (7.33 KB, patch)
2023-03-02 15:43 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 21043: Add debit REST endpoint (22.72 KB, patch)
2023-05-05 14:52 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 21043: Handle exceptions and switch to debit response (7.38 KB, patch)
2023-05-05 14:52 UTC, Kyle M Hall
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2018-07-05 18:49:43 UTC

    
Comment 1 Katrin Fischer 2022-07-20 09:51:04 UTC
There is certainly a need for this to be able to add charges to the patron accounts from other library services/web applications. An example would be a print management software where the user is charged for the number of printouts.
Comment 2 Michaela Sieber 2022-12-15 13:24:52 UTC
For further information see attached documentation.

Testplan

1. Create a new account debit type (Administration > Debit types)
2. Add a fee with this debit type to a patron’s account via API
3. Make sure that this fee is shown in the accounting overview in the patron’s account in the staff interface
4. Make sure that it is possible to make a payment for this fee
Comment 3 Michaela Sieber 2022-12-15 13:26:01 UTC
Created attachment 144615 [details]
Add routes to add debits
Comment 4 Martin Renvoize 2022-12-15 14:13:41 UTC
I could have swarn I'd already submitted code for this..

I'll see if I can dig out the relevant branch and get it rebased and submitted.
Comment 5 Martin Renvoize 2022-12-15 14:54:32 UTC
See bug 29453
Comment 6 Martin Renvoize 2022-12-15 15:11:00 UTC
The above reworks a bunch of the foundations to make adding this much easier.
Comment 7 Martin Renvoize 2022-12-15 15:55:48 UTC
Created attachment 144623 [details] [review]
Bug 21043: Untested code

This patch adds a rough idea of how we might go about adding such an api
point.
Comment 8 Martin Renvoize 2022-12-15 15:56:40 UTC
I don't really have the capacity to work on this right now.. but I've added a basic patch for how I could see it fitting together.. untested.
Comment 9 Agustín Moyano 2023-02-27 15:39:07 UTC
Created attachment 147457 [details] [review]
Bug 21043: Add debit REST endpoint

This patch adds an endpoint to create a debit for a patron.

Testplan

1. Create a new account debit type (Administration > Debit types)
2. Add a fee with this debit type to a patron’s account via API
3. Make sure that this fee is shown in the accounting overview in the patron’s account in the staff interface
4. Make sure that it is possible to make a payment for this fee
Comment 10 Agustín Moyano 2023-02-27 15:39:09 UTC
Created attachment 147458 [details] [review]
Bug 21043: (follow-up) fix minor bugs and add test case
Comment 11 Agustín Moyano 2023-02-27 15:57:28 UTC
Created attachment 147459 [details] [review]
Bug 21043: Add debit REST endpoint

This patch adds an endpoint to create a debit for a patron.

Testplan

1. Create a new account debit type (Administration > Debit types)
2. Add a fee with this debit type to a patron’s account via API
3. Make sure that this fee is shown in the accounting overview in the patron’s account in the staff interface
4. Make sure that it is possible to make a payment for this fee

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Comment 12 PTFS Europe Sandboxes 2023-02-28 16:02:51 UTC
Created attachment 147498 [details] [review]
Bug 21043: Add debit REST endpoint

This patch adds an endpoint to create a debit for a patron.

Testplan

1. Create a new account debit type (Administration > Debit types)
2. Add a fee with this debit type to a patron’s account via API
3. Make sure that this fee is shown in the accounting overview in the patron’s account in the staff interface
4. Make sure that it is possible to make a payment for this fee

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 13 Martin Renvoize 2023-03-01 15:36:22 UTC
Created attachment 147566 [details] [review]
Bug 21043: Add debit REST endpoint

This patch adds an endpoint to create a debit for a patron.

Testplan

1. Create a new account debit type (Administration > Debit types)
2. Add a fee with this debit type to a patron’s account via API
3. Make sure that this fee is shown in the accounting overview in the patron’s account in the staff interface
4. Make sure that it is possible to make a payment for this fee

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 14 Martin Renvoize 2023-03-01 15:36:24 UTC
Created attachment 147567 [details] [review]
Bug 21043: (follow-up) Handle exceptions and switch to debit response

We were cheating a bit here and expecting a 'debit' to be sent in but a
'line' to be returned.

We should really be sending a debit and returning a debit.. so I've
update the paths schema as such.. but a little more work needs doing to
get it all working.

I've also added some code to catch exceptions that can be thrown by
Koha::Account->add_debit and added the appropriate 400 errors into the
path specs again.
Comment 15 Martin Renvoize 2023-03-01 15:36:27 UTC
Created attachment 147568 [details] [review]
Bug 21043: (follow-up) Return Koha::Account::Debit

This patch updates Koha::Account->add_debit from returning a
Koha::Account::Line object to returning a Koha::Account::Debit object.

This shouldn't make any difference for internal code at the moment, as
we're using Koha::Account::Line as the base class for ::Credit and
::Debit classes.. but we do overload the to_api_mapping and this is
causing some tests to fail.

We still need a little work here.
Comment 16 Martin Renvoize 2023-03-01 15:38:04 UTC
So in review I spotted a few things that need taking care of and started following up. There's still a little more to do, but I've run out of tuits for today.

I think a good chunk of work needs doing on the blocker bug to progress this so I'm going to focus there to get it unblocked.
Comment 17 Martin Renvoize 2023-03-02 15:43:51 UTC
Created attachment 147642 [details] [review]
Bug 21043: Add debit REST endpoint

This patch adds an endpoint to create a debit for a patron.

Testplan

1. Create a new account debit type (Administration > Debit types)
2. Add a fee with this debit type to a patron’s account via API
3. Make sure that this fee is shown in the accounting overview in the patron’s account in the staff interface
4. Make sure that it is possible to make a payment for this fee

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 18 Martin Renvoize 2023-03-02 15:43:55 UTC
Created attachment 147643 [details] [review]
Bug 21043: Handle exceptions and switch to debit response

We were cheating a bit here and expecting a 'debit' to be sent in but a
'line' to be returned.

We should really be sending a debit and returning a debit.. so I've
update the paths schema as such and we're now coercing the
Koha::Account::Line object that's returned by Koha::Account->add_debit
into a Koha::Account::Debit object. Longer term it would be nice to
convert returns from the various Koha::Account methods to their correct
Koha::Account:: objects as apposed to them all being the base ::Line

I've also added some code to catch exceptions that can be thrown by
Koha::Account->add_debit and added the appropriate 400 errors into the
path specs again.

Finally.. I added more unit tests to prove the above

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 19 Martin Renvoize 2023-03-02 15:45:40 UTC
Could you review my follow-up Agustin?
Comment 20 Marcel de Rooy 2023-04-28 06:42:15 UTC
(In reply to Martin Renvoize from comment #19)
> Could you review my follow-up Agustin?

Changing status to reflect need for feedback.
Comment 21 Tomás Cohen Arazi 2023-04-28 11:16:25 UTC
The follow-up is correct.
Comment 22 Kyle M Hall 2023-05-05 14:52:44 UTC
Created attachment 150765 [details] [review]
Bug 21043: Add debit REST endpoint

This patch adds an endpoint to create a debit for a patron.

Testplan

1. Create a new account debit type (Administration > Debit types)
2. Add a fee with this debit type to a patron’s account via API
3. Make sure that this fee is shown in the accounting overview in the patron’s account in the staff interface
4. Make sure that it is possible to make a payment for this fee

Sponsored-by: The Research University in the Helmholtz Association (KIT)
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 23 Kyle M Hall 2023-05-05 14:52:52 UTC
Created attachment 150766 [details] [review]
Bug 21043: Handle exceptions and switch to debit response

We were cheating a bit here and expecting a 'debit' to be sent in but a
'line' to be returned.

We should really be sending a debit and returning a debit.. so I've
update the paths schema as such and we're now coercing the
Koha::Account::Line object that's returned by Koha::Account->add_debit
into a Koha::Account::Debit object. Longer term it would be nice to
convert returns from the various Koha::Account methods to their correct
Koha::Account:: objects as apposed to them all being the base ::Line

I've also added some code to catch exceptions that can be thrown by
Koha::Account->add_debit and added the appropriate 400 errors into the
path specs again.

Finally.. I added more unit tests to prove the above

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 24 Tomás Cohen Arazi 2023-05-05 15:14:17 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 25 Martin Renvoize 2023-05-12 15:03:05 UTC
New feature, not backporting to 22.11.x series (again.. for API's I'm always tempted, so let me know if you're keen for this to make the cut)