Business-OnlinePayment-Ogone
view release on metacpan or search on metacpan
t/20_account.t view on Meta::CPAN
bail_on_fail;
ok($ENV{OGONE_USERID}, "test can only proceed with environment OGONE_USERID set");
bail_on_fail;
ok($ENV{OGONE_PSPID}, "test can only proceed with environment OGONE_PSPID set");
bail_on_fail;
ok($ENV{OGONE_PSWD}, "test can only proceed with environment OGONE_PSWD set");
restore_fail;
my %base_args = (
PSPID => $ENV{OGONE_PSPID},
login => $ENV{OGONE_USERID},
password => $ENV{OGONE_PSWD},
invoice_number => time,
amount => '49.99',
card_number => '4111111111111111',
# card_number => '4000 0000 0000 0002',
cvc => '423',
# flag3d => 'Y',
# win3ds => 'POPUP',
expiration => '12/15',
country => 'BE',
address => 'Nieuwstraat 32',
sha_key => 'xxxtestingx123xpassphrasexxx',
sha_type => 512,
zip => 1000
);
sub new_test_tx {
my $tx = new Business::OnlinePayment('Ogone');
$tx->test_transaction(1);
return $tx;
}
sub override_base_args_with {
my $in = shift;
my %hash = $in ? ref $in eq 'HASH' ? %$in : ($in,@_) : ();
my %res = map { $_ => ( $hash{$_} || $base_args{$_} ) } (keys %base_args, keys %hash);
return %res;
}
my $tx = new_test_tx();
#########################################################################################################
# test setup
#########################################################################################################
isa_ok($tx,'Business::OnlinePayment');
my %test = %base_args; $test{'foobar'} = "123";
cmp_deeply(\%test, { override_base_args_with(foobar=> 123) }, "override_base_args_with method test HASH");
cmp_deeply(\%test, { override_base_args_with({foobar=> 123}) }, "override_base_args_with method test REF");
#########################################################################################################
# test obvious failures (wrong pass, wrong cardno, wrong cvc)
#########################################################################################################
$base_args{action} = 'authorization only';
SKIP: {
skip "this test will block your account if you run it too frequently", 3;
# NOTE: if account is blocked, you can reenable it in the 'Users' section of the Ogone backend.
$tx = new_test_tx();
$tx->content(override_base_args_with(password=>123456)); eval { $tx->submit() };
like($@, qr/^$/, "there should have been no warnings");
like($tx->error_message, qr/Some of the data entered is incorrect. Please retry./, "error message must be set");
like($tx->result_code, qr/50001119/, "should return wrong password code");
}
### test wrong card number ...............................................................................
$tx = new_test_tx();
$tx->content(override_base_args_with(card_number=>123456)); eval { $tx->submit() };
is($@, '', "there should have been no warnings");
is($tx->is_success, 0, "must NOT be successful")
or diag explain { req => $tx->http_args, res => $tx->result_xml};
like($tx->error_message, qr/no brand/, "error message must be set");
like($tx->result_code, qr/50001111/, "result_code should return 50001111");
## test empty cvc code ..................................................................................
$tx = new_test_tx();
$tx->content(override_base_args_with(cvc => 'abc')); eval { $tx->submit() }; #diag(Dumper($tx->http_args));
is($@, '', "there should have been no warnings");
is($tx->is_success, 0, "must NOT be successful")
or diag explain { req => $tx->http_args, res => $tx->result_xml};
like($tx->error_message, qr/./, "error message must be set"); # testing wrong cvc seems impossible
like($tx->error_message, qr/The CVC code is mandatory for this type of card/, "error message must be like: 'The CVC code is mandatory for this type of card'");
like($tx->result_code, qr/50001090/, "result_code should return 50001090");
#########################################################################################################
# test normal flow: 'authorization only' (RES) request followed by 'post authorization' (SAS) request
#########################################################################################################
my $invoice_number = time;
$tx = new_test_tx();
$tx->content(override_base_args_with({invoice_number => $invoice_number})); eval { $tx->submit() }; # diag(Dumper($tx->http_args));
is($@, '', "there should have been no warnings");
is($tx->is_success, 1, "must be successful")
or diag explain { req => $tx->http_args, res => $tx->result_xml};
is($tx->error_message, undef, "error message must be undef");
ok($tx->result_code == 0, "result_code should return 0");
## test invalid invoice number ..........................................................................
$base_args{action} = 'post authorization';
$tx = new_test_tx();
$tx->content(override_base_args_with({invoice_number => 99999})); eval { $tx->submit() };
is($@, '', "there should have been no warnings");
is($tx->is_success, 0, "must NOT be successful")
or diag explain { req => $tx->http_args, res => $tx->result_xml};
like($tx->error_message, qr/unknown orderid 99999 for merchant/, "error message must be set");
like($tx->result_code, qr/50001130/, "result_code should return 50001130 error code");
## test with previously known correct invoice number ....................................................
( run in 1.586 second using v1.01-cache-2.11-cpan-b301d465b3d )