+ 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: $@";
+ }
+ }
+