- } elsif ( $self->payby eq 'CARD' ) {
-
- if ( $options{'batch_card'} ne 'yes' ) {
-
- unless ( $processor ) {
- $dbh->rollback if $oldAutoCommit;
- return "Real time card processing not enabled!";
- }
-
- my $address = $self->address1;
- $address .= ", ". $self->address2 if $self->address2;
-
- #fix exp. date
- #$self->paydate =~ /^(\d+)\/\d*(\d{2})$/;
- $self->paydate =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
- my $exp = "$2/$1";
-
- if ( $processor =~ /^cybercash/ ) {
-
- #fix exp. date for cybercash
- #$self->paydate =~ /^(\d+)\/\d*(\d{2})$/;
- $self->paydate =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
- my $exp = "$2/$1";
-
- my $paybatch = $cust_bill->invnum.
- '-' . time2str("%y%m%d%H%M%S", time);
-
- my $payname = $self->payname ||
- $self->getfield('first'). ' '. $self->getfield('last');
-
-
- my $country = $self->country eq 'US' ? 'USA' : $self->country;
-
- my @full_xaction = ( $xaction,
- 'Order-ID' => $paybatch,
- 'Amount' => "usd $amount",
- 'Card-Number' => $self->getfield('payinfo'),
- 'Card-Name' => $payname,
- 'Card-Address' => $address,
- 'Card-City' => $self->getfield('city'),
- 'Card-State' => $self->getfield('state'),
- 'Card-Zip' => $self->getfield('zip'),
- 'Card-Country' => $country,
- 'Card-Exp' => $exp,
- );
-
- my %result;
- if ( $processor eq 'cybercash2' ) {
- $^W=0; #CCLib isn't -w safe, ugh!
- %result = &CCLib::sendmserver(@full_xaction);
- $^W=1;
- } elsif ( $processor eq 'cybercash3.2' ) {
- %result = &CCMckDirectLib3_2::SendCC2_1Server(@full_xaction);
- } else {
- $dbh->rollback if $oldAutoCommit;
- return "Unknown real-time processor $processor";
- }
-
- #if ( $result{'MActionCode'} == 7 ) { #cybercash smps v.1.1.3
- #if ( $result{'action-code'} == 7 ) { #cybercash smps v.2.1
- if ( $result{'MStatus'} eq 'success' ) { #cybercash smps v.2 or 3
- my $cust_pay = new FS::cust_pay ( {
- 'invnum' => $cust_bill->invnum,
- 'paid' => $amount,
- '_date' => '',
- 'payby' => 'CARD',
- 'payinfo' => $self->payinfo,
- 'paybatch' => "$processor:$paybatch",
- } );
- my $error = $cust_pay->insert;
- if ( $error ) {
- # gah, even with transactions.
- $dbh->commit if $oldAutoCommit; #well.
- my $e = 'WARNING: Card debited but database not updated - '.
- 'error applying payment, invnum #' . $cust_bill->invnum.
- " (CyberCash Order-ID $paybatch): $error";
- warn $e;
- return $e;
- }
- } elsif ( $result{'Mstatus'} ne 'failure-bad-money'
- || $options{'report_badcard'} ) {
- $dbh->commit if $oldAutoCommit;
- return 'Cybercash error, invnum #' .
- $cust_bill->invnum. ':'. $result{'MErrMsg'};
- } else {
- $dbh->commit or die $dbh->errstr if $oldAutoCommit;
- return '';
- }
-
- } elsif ( $processor =~ /^Business::OnlinePayment::(.*)$/ ) {
-
- my($payname, $payfirst, $paylast);
- if ( $self->payname ) {
- $payname = $self->payname;
- $payname =~ /^\s*([\w \,\.\-\']*\w)?\s+([\w\,\.\-\']+)$/
- or do {
- $dbh->rollback if $oldAutoCommit;
- return "Illegal payname $payname";
- };
- ($payfirst, $paylast) = ($1, $2);
- } else {
- $payfirst = $self->getfield('first');
- $paylast = $self->getfield('first');
- $payname = "$payfirst $paylast";
- }
-
- my $transaction = new Business::OnlinePayment( $1, @bop_options );
- $transaction->content(
- 'type' => 'CC',
- 'login' => $bop_login,
- 'password' => $bop_password,
- 'action' => $bop_action,
- 'amount' => $amount,
- 'invoice_number' => $cust_bill->invnum,
- 'customer_id' => $self->custnum,
- 'last_name' => $paylast,
- 'first_name' => $payfirst,
- 'name' => $payname,
- 'address' => $address,
- 'city' => $self->city,
- 'state' => $self->state,
- 'zip' => $self->zip,
- 'country' => $self->country,
- 'card_number' => $self->payinfo,
- 'expiration' => $exp,
- );
- $transaction->submit();
-
- if ( $transaction->is_success()) {
- my $cust_pay = new FS::cust_pay ( {
- 'invnum' => $cust_bill->invnum,
- 'paid' => $amount,
- '_date' => '',
- 'payby' => 'CARD',
- 'payinfo' => $self->payinfo,
- 'paybatch' => "$processor:". $transaction->authorization,
- } );
- my $error = $cust_pay->insert;
- if ( $error ) {
- # gah, even with transactions.
- $dbh->commit if $oldAutoCommit; #well.
- my $e = 'WARNING: Card debited but database not updated - '.
- 'error applying payment, invnum #' . $cust_bill->invnum.
- " ($processor): $error";
- warn $e;
- return $e;
- }
- } elsif ( $options{'report_badcard'} ) {
- $dbh->commit if $oldAutoCommit;
- return "$processor error, invnum #". $cust_bill->invnum. ': '.
- $transaction->result_code. ": ". $transaction->error_message;
- } else {
- $dbh->commit or die $dbh->errstr if $oldAutoCommit;
- return ''
- }
-
- } else {
- $dbh->rollback if $oldAutoCommit;
- return "Unknown real-time processor $processor\n";
- }
-
- } else { #batch card
-
- my $cust_pay_batch = new FS::cust_pay_batch ( {
- 'invnum' => $cust_bill->getfield('invnum'),
- 'custnum' => $self->getfield('custnum'),
- 'last' => $self->getfield('last'),
- 'first' => $self->getfield('first'),
- 'address1' => $self->getfield('address1'),
- 'address2' => $self->getfield('address2'),
- 'city' => $self->getfield('city'),
- 'state' => $self->getfield('state'),
- 'zip' => $self->getfield('zip'),
- 'country' => $self->getfield('country'),
- 'trancode' => 77,
- 'cardnum' => $self->getfield('payinfo'),
- 'exp' => $self->getfield('paydate'),
- 'payname' => $self->getfield('payname'),
- 'amount' => $amount,
- } );
- my $error = $cust_pay_batch->insert;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "Error adding to cust_pay_batch: $error";
- }
-
- }
-
- } else {
- $dbh->rollback if $oldAutoCommit;
- return "Unknown payment type ". $self->payby;