- if ( $transaction->is_success() ) {
-
- my $cust_pay = new FS::cust_pay ( {
- 'invnum' => $self->invnum,
- 'paid' => $amount,
- '_date' => '',
- 'payby' => 'CARD',
- 'payinfo' => $cust_main->payinfo,
- 'paybatch' => "$processor:". $transaction->authorization,
- } );
- my $error = $cust_pay->insert;
- if ( $error ) {
- # gah, even with transactions.
- my $e = 'WARNING: Card debited but database not updated - '.
- 'error applying payment, invnum #' . $self->invnum.
- " ($processor): $error";
- warn $e;
- return $e;
- } else {
- return '';
- }
- #} elsif ( $options{'report_badcard'} ) {
- } else {
-
- my $perror = "$processor error, invnum #". $self->invnum. ': '.
- $transaction->result_code. ": ". $transaction->error_message;
-
- if ( $conf->exists('emaildecline')
- && grep { $_ ne 'POST' } $cust_main->invoicing_list
- ) {
- my @templ = $conf->config('declinetemplate');
- my $template = new Text::Template (
- TYPE => 'ARRAY',
- SOURCE => [ map "$_\n", @templ ],
- ) or return "($perror) can't create template: $Text::Template::ERROR";
- $template->compile()
- or return "($perror) can't compile template: $Text::Template::ERROR";
-
- my $templ_hash = { error => $transaction->error_message };
-
- #false laziness w/FS::cust_pay::delete & fs_signup_server && ::send
- $ENV{MAILADDRESS} = $invoice_from;
- my $header = new Mail::Header ( [
- "From: $invoice_from",
- "To: ". join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list ),
- "Sender: $invoice_from",
- "Reply-To: $invoice_from",
- "Date: ". time2str("%a, %d %b %Y %X %z", time),
- "Subject: Your credit card could not be processed",
- ] );
- my $message = new Mail::Internet (
- 'Header' => $header,
- 'Body' => [ $template->fill_in(HASH => $templ_hash) ],
- );
- $!=0;
- $message->smtpsend( Host => $smtpmachine )
- or $message->smtpsend( Host => $smtpmachine, Debug => 1 )
- or return "($perror) (customer # ". $self->custnum.
- ") can't send card decline email to ".
- join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list ).
- " via server $smtpmachine with SMTP: $!";
- }
-
- return $perror;
- }