X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_main%2FBilling_Realtime.pm;h=364d4a7d8accfc8b72d061e4e619e87dbf30ed54;hp=763f70fbbe9c5a1961f1561335d53821de6226f4;hb=c5e31619e5a3071506cff19578e9e377753a96f4;hpb=9dafe1bcc38121281d62ffe2d48eba6b8fd748e7 diff --git a/FS/FS/cust_main/Billing_Realtime.pm b/FS/FS/cust_main/Billing_Realtime.pm index 763f70fbb..364d4a7d8 100644 --- a/FS/FS/cust_main/Billing_Realtime.pm +++ b/FS/FS/cust_main/Billing_Realtime.pm @@ -138,7 +138,8 @@ I is a session identifier associated with this payment. I allows payment capture to unlock export jobs -I attempts to take a discount by prepaying for discount_term +I attempts to take a discount by prepaying for discount_term. +The payment will fail if I is incorrect for this discount term. A direct (Business::OnlinePayment) transaction will return nothing on success, or an error message on failure. @@ -412,6 +413,24 @@ sub realtime_bop { return "Banned credit card" if $ban && $ban->bantype ne 'warn'; ### + # check for term discount validity + ### + + my $discount_term = $options{discount_term}; + if ( $discount_term ) { + my $bill = ($self->cust_bill)[-1] + or return "Can't apply a term discount to an unbilled customer"; + my $plan = FS::discount_plan->new( + cust_bill => $bill, + months => $discount_term + ) or return "No discount available for term '$discount_term'"; + + if ( $plan->discounted_total != $options{amount} ) { + return "Incorrect term prepayment amount (term $discount_term, amount $options{amount}, requires ".$plan->discounted_total.")"; + } + } + + ### # massage data ###