Bug 23213 - Add hook to OPAC payments to allow plugins to set minimum payment threshold
Summary: Add hook to OPAC payments to allow plugins to set minimum payment threshold
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Agustín Moyano
QA Contact: Testopia
URL:
Keywords:
Depends on: 23214
Blocks: 20211 23118 23868
  Show dependency treegraph
 
Reported: 2019-06-26 03:31 UTC by Agustín Moyano
Modified: 2021-06-14 21:28 UTC (History)
5 users (show)

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


Attachments
Bug 23213: Enable minimum payment threshold check in OPAC (8.40 KB, patch)
2019-06-28 19:19 UTC, Agustín Moyano
Details | Diff | Splinter Review
Bug 23213: Enable minimum payment threshold check in OPAC (8.46 KB, patch)
2019-09-24 13:37 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 23213: Enable minimum payment threshold check in OPAC (8.53 KB, patch)
2019-09-24 14:57 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 Agustín Moyano 2019-06-26 03:31:37 UTC
Add the ability in OPAC to check if the plugin has a minimum payment threshold.

If the amount that the patron is lower than the threshold declared by the plugin then payment is not allowed.

For example, if PayPal is going to charge $2 for every transaction, don't allow payments through that plugin to be less than $3.

The logic to determine the minimum threshold is hold in the plugin itself. 

Plugins that defines a threshold should declare a new hook named
Comment 1 Agustín Moyano 2019-06-26 03:34:13 UTC
Change this line 

> If the amount that the patron is lower than the threshold declared by the
> plugin then payment is not allowed.

for:

If the amount the patron is about to pay is lower than the threshold declared by the plugin then payment is not allowed for that specific plugin.
Comment 2 Agustín Moyano 2019-06-26 03:35:58 UTC
> Plugins that defines a threshold should declare a new hook named

named opac_online_payment_threshold
Comment 3 Agustín Moyano 2019-06-28 19:19:14 UTC
Created attachment 91122 [details] [review]
Bug 23213: Enable minimum payment threshold check in OPAC

This patch enables OPAC to check for the miminum payment threshold per payment method.

If the total amount to pay is less than the threshold, payment for that method is disabled.

To test:
1) apply dependencies
2) get 2 payment plugins, one with threshold as https://gitlab.com/thekesolutions/plugins/koha-plugin-pay-via-paypal/uploads/4c66444ff697586dff3d8759c1e5746c/koha-plugin-pay-via-paypal-v1.0.0.kpz and one without threshold as https://github.com/bywatersolutions/koha-plugin-pay-via-paygov/releases/download/v1.0.5/koha-plugin-pay-via-paygov-v1.0.5.kpz
3) install both plugins
4) Configure both plugins to work correctly (can be invented data.. we are not interested in the actual payment page, but to test if payment method is allowed)
5) In plugin with threshold, set minimum threshold to 10
6) Fetch any user, and create 2 manual invoices, both for the amount of 5
7) Enter OPAC as user, and go to "my fines" tab
CHECK => both plugins appear as payment method
8) Check the checkbox of one of the fines
SUCCESS => plugin with threshold is now disabled, and has a warning message that says "Minimum amount needed by this service is 10.00"
        => plugin without threshold is enabled
        => if plugin with threshold was selected, "Make payment" button is disabled until an enabled payment method is selected
9) Check the second checkbox
SUCCESS => both payment methods are now enabled
10) Sign off
Comment 4 Martin Renvoize 2019-07-01 16:03:38 UTC
As a note to this one.. I think it really ought to have been written independently of bug 23214 really.. it was a surprise to see that as a dependency here as really they're pretty unrelated changes.

I will however on this occasion look to testing both to save you a refactor.
Comment 5 Martin Renvoize 2019-07-01 16:06:33 UTC
On second thoughts.. the tree beneath bug 23214 is fairly large and currently blocked by an FQA bug.. will wait on that to test this, but in effect, it means this bug is blocked..
Comment 6 Agustín Moyano 2019-07-02 12:33:44 UTC
(In reply to Martin Renvoize from comment #4)
> As a note to this one.. I think it really ought to have been written
> independently of bug 23214 really.. it was a surprise to see that as a
> dependency here as really they're pretty unrelated changes.
> 
> I will however on this occasion look to testing both to save you a refactor.

My bad. I'll try to take that into account the next time

Thanks
Comment 7 Martin Renvoize 2019-09-24 13:37:08 UTC
Created attachment 93140 [details] [review]
Bug 23213: Enable minimum payment threshold check in OPAC

This patch enables OPAC to check for the miminum payment threshold per payment method.

If the total amount to pay is less than the threshold, payment for that method is disabled.

To test:
1) apply dependencies
2) get 2 payment plugins, one with threshold as https://gitlab.com/thekesolutions/plugins/koha-plugin-pay-via-paypal/uploads/4c66444ff697586dff3d8759c1e5746c/koha-plugin-pay-via-paypal-v1.0.0.kpz and one without threshold as https://github.com/bywatersolutions/koha-plugin-pay-via-paygov/releases/download/v1.0.5/koha-plugin-pay-via-paygov-v1.0.5.kpz
3) install both plugins
4) Configure both plugins to work correctly (can be invented data.. we are not interested in the actual payment page, but to test if payment method is allowed)
5) In plugin with threshold, set minimum threshold to 10
6) Fetch any user, and create 2 manual invoices, both for the amount of 5
7) Enter OPAC as user, and go to "my fines" tab
CHECK => both plugins appear as payment method
8) Check the checkbox of one of the fines
SUCCESS => plugin with threshold is now disabled, and has a warning message that says "Minimum amount needed by this service is 10.00"
        => plugin without threshold is enabled
        => if plugin with threshold was selected, "Make payment" button is disabled until an enabled payment method is selected
9) Check the second checkbox
SUCCESS => both payment methods are now enabled
10) Sign off

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 8 Martin Renvoize 2019-09-24 13:37:27 UTC
Does what is says on the tin, Signing off.
Comment 9 Kyle M Hall 2019-09-24 14:57:58 UTC
Created attachment 93144 [details] [review]
Bug 23213: Enable minimum payment threshold check in OPAC

This patch enables OPAC to check for the miminum payment threshold per payment method.

If the total amount to pay is less than the threshold, payment for that method is disabled.

To test:
1) apply dependencies
2) get 2 payment plugins, one with threshold as https://gitlab.com/thekesolutions/plugins/koha-plugin-pay-via-paypal/uploads/4c66444ff697586dff3d8759c1e5746c/koha-plugin-pay-via-paypal-v1.0.0.kpz and one without threshold as https://github.com/bywatersolutions/koha-plugin-pay-via-paygov/releases/download/v1.0.5/koha-plugin-pay-via-paygov-v1.0.5.kpz
3) install both plugins
4) Configure both plugins to work correctly (can be invented data.. we are not interested in the actual payment page, but to test if payment method is allowed)
5) In plugin with threshold, set minimum threshold to 10
6) Fetch any user, and create 2 manual invoices, both for the amount of 5
7) Enter OPAC as user, and go to "my fines" tab
CHECK => both plugins appear as payment method
8) Check the checkbox of one of the fines
SUCCESS => plugin with threshold is now disabled, and has a warning message that says "Minimum amount needed by this service is 10.00"
        => plugin without threshold is enabled
        => if plugin with threshold was selected, "Make payment" button is disabled until an enabled payment method is selected
9) Check the second checkbox
SUCCESS => both payment methods are now enabled
10) Sign off

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 10 Martin Renvoize 2019-09-27 13:07:04 UTC
Nice work!

Pushed to master for 19.11.00
Comment 11 Fridolin Somers 2019-10-08 07:20:55 UTC
Depends on Bug 23214 not in 19.05.x
Comment 12 Katrin Fischer 2019-11-19 00:17:47 UTC
Should we add this to https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks?
Comment 13 Martin Renvoize 2019-11-19 19:39:07 UTC
We certainly should, well spotted Katrin.  Agustin, could you take care of adding this?
Comment 14 Agustín Moyano 2019-11-20 14:57:33 UTC
(In reply to Martin Renvoize from comment #13)
> We certainly should, well spotted Katrin.  Agustin, could you take care of
> adding this?

Thanks Katrin for spotting it.

Hook description was added.