4 use Test::More tests => 9;
7 ### can only run on test database (company name "Freeside Test")
8 ### will run upgrade, which uses lots of prints & warns beyond regular test output
10 my $fs = FS::Test->new( user => 'admin' );
11 my $conf = new_ok('FS::Conf');
15 like( $conf->config('company_name'), qr/^Freeside Test/, 'using test database' ) or BAIL_OUT('');
17 # some pre-upgrade cleanup, upgrade will fail if these are still configured
18 foreach my $cust_main ( $fs->qsearch('cust_main') ) {
19 my @count = $fs->qsearch('agent_payment_gateway', { agentnum => $cust_main->agentnum } );
21 note("DELETING CARDTYPE GATEWAYS");
22 foreach my $apg (@count) {
23 $err = $apg->delete if $apg->cardtype;
26 @count = $fs->qsearch('agent_payment_gateway', { agentnum => $cust_main->agentnum } );
28 $err = "Still found ".@count." gateways for custnum ".$cust_main->custnum;
33 ok( !$err, "remove obsolete payment gateways" ) or BAIL_OUT($err);
38 $conf->set('business-onlinepayment' => $bopconf);
39 is( join("\n",$conf->config('business-onlinepayment')), $bopconf, "setting first default gateway" ) or BAIL_OUT('');
41 # generate a few void/refund records for upgrading
43 foreach my $cust_pay ( $fs->qsearch('cust_pay',{ payby => 'CARD' }) ) {
45 $err = $cust_pay->void('Testing');
46 $err = "Voiding: $err" if $err;
48 # from realtime_refund_bop, just the important bits
49 while ( $cust_pay->unapplied < $cust_pay->paid ) {
50 my @cust_bill_pay = $cust_pay->cust_bill_pay;
51 last unless @cust_bill_pay;
52 my $cust_bill_pay = pop @cust_bill_pay;
53 $err = $cust_bill_pay->delete;
54 $err = "Refund unapply: $err" if $err;
58 my $cust_refund = new FS::cust_refund ( {
59 'custnum' => $cust_pay->cust_main->custnum,
60 'paynum' => $cust_pay->paynum,
61 'source_paynum' => $cust_pay->paynum,
62 'refund' => $cust_pay->paid,
64 'payby' => $cust_pay->payby,
65 'payinfo' => $cust_pay->payinfo,
66 'reason' => 'Testing',
67 'gatewaynum' => $cust_pay->gatewaynum,
68 'processor' => $cust_pay->payment_gateway ? $cust_pay->payment_gateway->processor : '',
69 'auth' => $cust_pay->auth,
70 'order_number' => $cust_pay->order_number,
72 $err = $cust_refund->insert( reason_type => 'Refund' );
73 $err = "Refunding: $err" if $err;
77 last unless $counter > 0;
79 ok( !$err, "create some refunds and voids" ) or BAIL_OUT($err);
81 $err = system('freeside-upgrade','admin');
82 ok( !$err, 'initial upgrade' ) or BAIL_OUT('Error string: '.$!);
96 /usr/local/etc/freeside/cardfortresstest.txt';
97 $conf->set('business-onlinepayment' => $bopconf);
98 is( join("\n",$conf->config('business-onlinepayment')), $bopconf, "setting tokenizable default gateway" ) or BAIL_OUT('');
100 foreach my $pg ($fs->qsearch('payment_gateway')) {
101 unless ($pg->gateway_module eq 'CardFortress') {
102 note('UPGRADING NON-CF PAYMENT GATEWAY');
104 gateway => $pg->gateway_module,
105 gateway_login => $pg->gateway_username,
106 gateway_password => $pg->gateway_password,
107 private_key => '/usr/local/etc/freeside/cardfortresstest.txt',
109 $pg->gateway_module('CardFortress');
110 $pg->gateway_username('cardfortresstest');
111 $pg->gateway_password('(TEST54)');
112 $err = $pg->replace(\%pgopts);
116 ok( !$err, "remove non-CF payment gateways" ) or BAIL_OUT($err);
118 $err = system('freeside-upgrade','admin');
119 ok( !$err, 'tokenizable upgrade' ) or BAIL_OUT('Error string: '.$!);