I am using payments module to let users restock a sort of "virtual credit". In some cases a refund or discount is given, and the easiest way to apply that would be to allow admins to mark a payment against the user with a negative amount.

Is there a way to allow negative payments?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano’s picture

Good one. A while ago, I changed the validation to allow payments with a total amount of 0 (which wasn't allowed in 7.x-1.0), and that seemed to work fine, as nobody complained. I wonder if we can just remove that validation completely and let it be handled by payment method controllers instead, or if that will cause problems for some users of Payment. It's already possible in 8.x-2.x and I'd love to backport this improvement.

Chris Gillis’s picture

Great! I agree, it seems the logical place for that validation is in the payment method controller. I'd love to see this backported.

If we are concerned about legacy support, perhaps it could be retained as an optional checkbox or something?

Xano’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
2.84 KB

Let's see what this does.

Xano’s picture

I ran the tests of all Payment and all modules that I know depend on it, and there were no fails.

Xano’s picture

By the way, what payment method controller are you using this with? Any controller can override payment validation. So if this is just about Basic, then we should make that method ignore the validation result if the amount is below the global minimum.

Xano’s picture

FileSize
903 bytes

This should remove the check from Basic payment methods, so they'll process any payment amount.

Status: Needs review » Needs work

The last submitted patch, 6: payment_2114785_6.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
2.69 KB
Xano’s picture

Title: Option to allow negative amounts. » "Basic" payment method should support negative amounts
Xano’s picture

@Chris Gillis: can you confirm the patch works?

Xano’s picture

8: payment_2114785_8.patch queued for re-testing.

Chris Gillis’s picture

Hi Xano,

Thanks for all of your work, unfortunately I cannot currently test this as I am no longer a part of the team for the project I was working on. If that changes in the future (potentially later this year) I will let you know and test this patch. Sorry to stuff you around.

Regards,
Chris

  • Commit ac73adc on 7.x-1.x by Xano:
    Issue #2114785 by Xano: "Basic" payment method should support negative...
Xano’s picture

Status: Needs review » Fixed

Thanks for the update! I just committed the patch. If it breaks anything, we'll know soon enough.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Chris Gillis’s picture

Status: Closed (fixed) » Active

Hi Xano,

I'm back! :) I can confirm that in the latest release (7.x-1.15), negative payments do not work...

I've taken a look at the code, and I can see that the PaymentValidationAmountBelowMinimumException is being caught successfuly (it runs the catch block)... however this does not meant that the payment gets processed. I still see an error message saying Debug: The amount should be higher than $0.00. on line 922 in /sites/all/modules/payment/payment.classes.inc (Do not log or display Payment debugging messages). and the payment does not go through. Do you have any ideas where I could look?

Regards,
Chris