897e6f785311f6c1d68fc664ce09dc316c26805f
[Business-OnlinePayment-vSecureProcessing.git] / t / t_transaction.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use POSIX qw(strftime);
6 use Test::More;
7 use Business::OnlinePayment;
8 require "t/lib/test_account.pl";
9
10 my %opts = test_account('card');
11
12 if (!$opts{'gid'} || !$opts{'appid'}) {
13   plan skip_all => "no test credentials provided; fill out t/lib/test_account.pl to test communication with the gateway.",
14   1;
15   exit(0);
16 }
17
18 plan tests => 2;
19
20 ###
21 # Purchase
22 ###
23 my %content = (
24     appid          => $opts{'appid'},
25     action         => 'Normal Authorization',
26     description    => 'Business::OnlinePayment visa test',
27     card_number    => '4111111111111111',
28     cvv2           => '111',
29     expiration     => expiration_date(),
30     amount         => '24.42',
31     name           => 'Murphy Law',
32     email          => 'fake@acme.com',
33     address        => '123 Anystreet',
34     zip            => '84058',
35 );
36
37 my $tx = new Business::OnlinePayment( 'vSecureProcessing', \%opts );
38
39 $tx->content( %content,
40               action => 'Normal Authorization' );
41
42 $tx->test_transaction(1);
43
44 $tx->submit;
45
46 is( $tx->is_success, 1, 'purchase' )
47   or diag('Gateway error: '. $tx->error_message);
48
49 ###
50 # Refund
51 ###
52 my $auth = $tx->authorization;
53 $tx = new Business::OnlinePayment( 'vSecureProcessing' );
54 $tx->content( %content,
55               action => 'Credit',
56               authorization => $auth );
57 $tx->test_transaction(1);
58
59 $tx->submit;
60
61 is( $tx->is_success, 1, 'refund' )
62   or diag('Gateway error: '. $tx->error_message);
63
64 1;