use FS::payby;
use FS::cust_pay;
use FS::cust_pay_pending;
+use FS::cust_bill_pay;
use FS::cust_refund;
use FS::banned_pay;
}
}
- $options->{payinfo} = $self->payinfo unless exists( $options->{payinfo} );
+ unless ( exists( $options->{'payinfo'} ) ) {
+ $options->{'payinfo'} = $self->payinfo;
+ $options->{'paymask'} = $self->paymask;
+ }
# Default invoice number if the customer has exactly one open invoice.
if( ! $options->{'invnum'} ) {
'_date' => '',
'payby' => $cust_pay_pending->payby,
'payinfo' => $options{'payinfo'},
- 'paymask' => $options{'paymask'},
+ 'paymask' => $options{'paymask'} || $cust_pay_pending->paymask,
'paydate' => $cust_pay_pending->paydate,
'pkgnum' => $cust_pay_pending->pkgnum,
'discount_term' => $options{'discount_term'},
Available methods are: I<CC>, I<ECHECK> and I<LEC>
-Available options are: I<amount>, I<reason>, I<paynum>, I<paydate>
+Available options are: I<amount>, I<reasonnum>, I<paynum>, I<paydate>
Most gateways require a reference to an original payment transaction to refund,
so you probably need to specify a I<paynum>.
I<amount> defaults to the original amount of the payment if not specified.
-I<reason> specifies a reason for the refund.
+I<reasonnum> specifies a reason for the refund.
I<paydate> specifies the expiration date for a credit card overriding the
value from the customer record or the payment record. Specified as yyyy-mm-dd
$options{method} = $method;
}
+ my ($reason, $reason_text);
+ if ( $options{'reasonnum'} ) {
+ # do this here, because we need the plain text reason string in case we
+ # void the payment
+ $reason = FS::reason->by_key($options{'reasonnum'});
+ $reason_text = $reason->reason;
+ } else {
+ # support old 'reason' string parameter in case it's still used,
+ # or else set a default
+ $reason_text = $options{'reason'} || 'card or ACH refund';
+ local $@;
+ $reason = FS::reason->new_or_existing(
+ reason => $reason_text,
+ type => 'Refund reason',
+ class => 'F',
+ );
+ if ($@) {
+ return "failed to add refund reason: $@";
+ }
+ }
+
if ( $DEBUG ) {
warn "$me realtime_refund_bop (new): $options{method} refund\n";
warn " $_ => $options{$_}\n" foreach keys %options;
}
+ my %content = ();
+
###
# look up the original payment and optionally a gateway for that payment
###
or return "Unknown paynum $options{'paynum'}";
$amount ||= $cust_pay->paid;
+ my @cust_bill_pay = qsearch('cust_bill_pay', { paynum=>$cust_pay->paynum });
+ $content{'invoice_number'} = $cust_bill_pay[0]->invnum if @cust_bill_pay;
+
if ( $cust_pay->get('processor') ) {
($gatewaynum, $processor, $auth, $order_number) =
(
eval "use $namespace";
die $@ if $@;
- my %content = (
+ %content = (
+ %content,
'type' => $options{method},
'login' => $login,
'password' => $password,
if $conf->exists('business-onlinepayment-test_transaction');
$void->submit();
if ( $void->is_success ) {
- my $error = $cust_pay->void($options{'reason'});
+ my $error = $cust_pay->void($reason_text);
if ( $error ) {
# gah, even with transactions.
my $e = 'WARNING: Card/ACH voided but database not updated - '.
'_date' => '',
'payby' => $bop_method2payby{$options{method}},
'payinfo' => $payinfo,
- 'reason' => $options{'reason'} || 'card or ACH refund',
+ 'reasonnum' => $reason->reasonnum,
'gatewaynum' => $gatewaynum, # may be null
'processor' => $processor,
'auth' => $refund->authorization,