version 0.01
[Business-OnlinePayment-FirstDataGlobalGateway.git] / 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
9 my $login = $ENV{BOP_TEST_LOGIN};
10 my $password = $ENV{BOP_TEST_PASSWORD};
11 if (!$login) {
12   plan skip_all => "no test credentials provided; set BOP_TEST_LOGIN and BOP_TEST_PASSWORD to test communication with the gateway.",
13   1;
14   exit(0);
15 }
16
17 plan tests => 2;
18
19 ###
20 # Purchase
21 ###
22 my %content = (
23   login    => $login,
24   password => $password,
25   type           => "CC",
26   description    => "Business::OnlinePayment::FirstDataGlobalGateway test",
27   card_number    => '4111111111111111',
28   cvv2           => '123',
29   expiration     => '12/20',
30   amount         => '1.00',
31   first_name     => 'Tofu',
32   last_name      => 'Beast',
33   address        => '1234 Soybean Ln.',
34   city           => 'Soyville',
35   state          => 'CA', #where else?
36   zip            => '94804',
37 );
38
39 my $tx = new Business::OnlinePayment( 'FirstDataGlobalGateway' );
40
41 $tx->content( %content,
42               action => 'Normal Authorization' );
43
44 $tx->test_transaction(1);
45
46 $tx->submit;
47
48 is( $tx->is_success, 1, 'purchase' )
49   or diag('Gateway error: '. $tx->error_message);
50
51 ###
52 # Refund
53 ###
54 my $auth = $tx->authorization;
55 $tx = new Business::OnlinePayment( 'FirstDataGlobalGateway' );
56 $tx->content( %content,
57               action => 'Credit',
58               authorization => $auth );
59 $tx->test_transaction(1);
60
61 $tx->submit;
62
63 is( $tx->is_success, 1, 'refund' )
64   or diag('Gateway error: '. $tx->error_message);
65
66 1;