initial import
[Business-OnlinePayment-PaySystems.git] / t / Business-OnlinePayment-PaySystems.t
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl Business-OnlinePayment-PaySystems.t'
3
4 #########################
5
6 # change 'tests => 1' to 'tests => last_test_to_print';
7
8 use Test::More tests => 22;
9 use Term::ReadLine;
10
11 BEGIN { use_ok('Business::OnlinePayment::PaySystems') };
12
13 #########################
14
15 # Insert your test code below, the Test::More module is use()ed here so read
16 # its man page ( perldoc Test::More ) for help writing this test script.
17
18
19 my $term = new Term::ReadLine 'foo';
20 diag("Please enter a test account for PaySystems");
21 my $prompt = "login: ";
22 my $login = $term->readline($prompt);
23 diag("Please enter the password for the test account $login");
24 $prompt = "password: ";
25 my $pass = $term->readline($prompt);
26 diag("Please enter a valid creditcard to test against ");
27 diag("It will be charged 2 dollars ");
28 $prompt = "card number: ";
29 my $cc = $term->readline($prompt);
30 diag("Please enter an expiry in the form MMYY"); 
31 $prompt = "MMYY: ";
32 my $exp = $term->readline($prompt);
33 diag("Please enter a cvv2"); 
34 $prompt = "cvv2: ";
35 my $cvv2 = $term->readline($prompt);
36
37
38 diag("\n\nTrying Normal Authorization\n\n");
39
40 my $transaction;
41 ok($transaction = new Business::OnlinePayment('PaySystems'), 'new PaySystems');
42 ok($transaction->content(
43                         type       => 'Visa',
44                         amount     => '1.00',
45                         card_number => $cc,
46                         cvv2       => $cvv2,
47                         expiration => $exp,
48                         first_name => 'John',
49                         last_name  => 'Public',
50                         action     => 'NORMAL authorization',
51                         login      => $login,
52                         password   => $pass,
53                         address    => '123 foo street',
54                         city       => 'fooville',
55                         state      => 'California',
56                         zip        => '90210',
57                         country    => 'US',
58                         email      => 'foo@bar.com',
59                         customer_ip => '123.123.123.123',
60                         phone      => '1123342234',
61                         ),
62     'content');
63 ok($transaction->submit(), 'submit');
64
65 ok($transaction->is_success(), 'is success');
66
67 my $authcode;
68 ok($authcode = $transaction->authorization(), "authorization $authcode");
69 my $err;
70 ok($err = $transaction->error_message(), "error $err");
71 my $on;
72 ok($on = $transaction->order_number(), "order number $on");
73
74 diag("\n\norder number: $on auth: $authcode Error: $err\n\n");
75
76
77 diag("\n\nTrying Authorization Only\n\n");
78 ok($tx = new Business::OnlinePayment('PaySystems'), 'new PaySystems 2');
79 ok($tx ->content(
80                         type       => 'Visa',
81                         amount     => '1.00',
82                         card_number => $cc,
83                         cvv2       => $cvv2,
84                         expiration => $exp,
85                         first_name => 'John',
86                         last_name  => 'Public',
87                         action     => 'authorization only',
88                         login      => $login,
89                         password   => $pass,
90                         address    => '123 foo street',
91                         city       => 'fooville',
92                         state      => 'California',
93                         zip        => '90210',
94                         country    => 'US',
95                         email      => 'foo@bar.com',
96                         customer_ip => '123.123.123.123',
97                         phone      => '1123342234',
98
99                        ),
100     'new content');
101
102 ok($tx->submit(), 'submit');
103 $authcode = $err = $on = '';
104 ok($tx->is_success(), 'is success');
105 ok($authcode = $tx->authorization(), "authorization $authcode");
106 ok($err = $tx->error_message(), "error $err");
107 ok($on = $tx->order_number(), "order number $on");
108 my $ordernum = $on;
109
110 diag("\n\norder_number: $on auth: $authcode err: $err\n\n");
111
112
113 diag("\n\nTrying Post Authorization\n\n");
114 ok($tx2 = new Business::OnlinePayment('PaySystems'), 'new PaySystems 3');
115 ok($tx2->content( 
116                         amount     => '1.00',
117                         action     => 'post authorization',
118                         login      => $login,
119                         password   => $pass,
120                         order_number => $ordernum,
121                        ),
122     'new content');
123 ok($tx2->submit, 'submit');
124 $authcode = $err = $on = '';
125 ok($tx2->is_success(), 'is success');
126 ok($authcode = $tx2->authorization(), "authorization $authcode");
127 ok($err = $tx2->error_message(), "error $err");
128 ok($on = $tx2->order_number(), "order number $on");
129
130 diag("\n\norder_number: $on auth: $authcode err: $err\n\n");
131