Initial import
[Business-OnlinePayment-eWay.git] / t / eWay.t
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl eWay.t'
3
4 use Test;
5 BEGIN { plan tests => 24 };
6 use Business::OnlinePayment::eWay;
7
8 # a test transaction
9 my ($tx, $txnum, $res);
10 ok($tx = new Business::OnlinePayment("eWay"));
11 ok(
12     $tx->content(
13         type           => 'CC',
14         login          => '87654321', #ewayCustomerID
15         action         => 'Normal Authorization',
16         description    => 'Business::OnlinePayment test',
17         amount         => '49.95',
18         invoice_number => '100100',
19         name           => 'Tofu Beast',
20         card_number    => '4646464646464646',
21         expiration     => '11/08',
22     )
23 );
24 ok($tx->test_transaction(1));
25 ok($tx->submit());
26 ok($tx->is_success());
27 ok($tx->error_message(), '00, TRANSACTION APPROVED');
28 ok($tx->authorization(), '123456');
29 ok($res = $tx->server_response());
30 ok($res->{ewayReturnAmount}, 4995);
31 ok($txnum = $res->{ewayTrxnNumber});
32
33 #resubmit test
34 ok($tx->submit());
35 ok(($tx->server_response->{ewayTrxnNumber} - $txnum) > 0);
36
37 # a test transaction with cvn
38 ok(
39     $tx->content(
40         type           => 'CC',
41         login          => '87654321', #ewayCustomerID
42         action         => 'Normal Authorization',
43         description    => 'Business::OnlinePayment test',
44         amount         => '49.95',
45         invoice_number => '100100',
46         name           => 'Tofu Beast',
47         card_number    => '4646464646464646',
48         expiration     => '11/08',
49         option1        => 'first option',
50         cvv2           => '123',
51     )
52 );
53 ok($tx->submit());
54 ok($tx->is_success());
55 ok($tx->error_message(), '00,TRANSACTION APPROVED');
56 ok($tx->authorization(), '123456');
57 ok($tx->server_response->{ewayTrxnOption1}, 'first option');
58
59 # a failing transaction
60 ok(
61     $tx->content(
62         type           => 'CC',
63         login          => '87654321', #ewayCustomerID
64         action         => 'Normal Authorization',
65         description    => 'Business::OnlinePayment test',
66         amount         => '49.95',
67         invoice_number => '100100',
68         name           => 'Tofu Beast',
69         first_name     => 'Tofu',
70         last_name      => 'Beast',
71         email          => 'tofu@example.com',
72         address        => '1234 Bean Curd Lane, Sydney',
73         zip            => '2034',
74         card_number    => '4646464646464646',
75         expiration     => '11/08',
76         cvv2           => '123',
77     )
78 );
79 ok($tx->test_transaction(0),0);
80 ok($tx->submit());
81 ok($tx->is_success(),0);
82 ok($tx->error_message(), 'Error: Invalid eWAYCustomerID. You have not been billed for this transaction.');
83 ok($tx->authorization(), '123456');