- bump version to 1.00, should have probably done this with 0.07 as it
[Business-OnlinePayment-PayflowPro.git] / t / bop.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More tests => 30;
6
7 use Business::OnlinePayment;
8
9 my $package = "Business::OnlinePayment";
10 my $driver  = "PayflowPro";
11
12 {    # new
13     my $obj;
14
15     $obj = $package->new($driver);
16     isa_ok( $obj, $package );
17
18     # convenience methods
19     can_ok( $obj, qw(vendor partner) );
20     can_ok( $obj, qw(order_number avs_code cvv2_response) );
21     can_ok( $obj, qw(request_id debug expdate_mmyy) );
22
23     # internal methods
24     can_ok( $obj, qw(_map_fields _revmap_fields) );
25
26     # defaults
27     my $server = "payflowpro.paypal.com";
28
29     is( $obj->server, $server, "server($server)" );
30     is( $obj->port, "443", "port(443)" );
31 }
32
33 {    # cvv2_response / cvv2_code
34     my $obj = $package->new($driver);
35
36     my $exp = "Z";
37     $obj->cvv2_response($exp);
38
39     is( $obj->cvv2_response, $exp, "cvv2_response() is set" );
40     is( $obj->cvv2_code,     $exp, "cvv2_code() calls cvv2_response" );
41 }
42
43 {    # client_certification_id
44     my $obj = $package->new($driver);
45
46     my $id = $obj->client_certification_id;
47     isnt( $id, "", "client_certification_id() is set" );
48
49     $id = "foo";
50     is( $obj->client_certification_id($id),
51         $id, "client_certification_id() can be set" );
52     is( $obj->client_certification_id,
53         $id, "client_certification_id() remains set" );
54 }
55
56 {    # client_timeout
57     my $obj = $package->new($driver);
58
59     is( $obj->client_timeout, 45, "client_timeout() returns 45 by default" );
60
61     my $to = 60;
62     is( $obj->client_timeout($to), $to, "client_timeout() can be set" );
63     is( $obj->client_timeout, $to, "client_timeout() remains set" );
64 }
65
66 {    # expdate
67     my $obj = $package->new($driver);
68     my @exp = (
69
70         #OFF [qw(1999.8   0899)],
71         #OFF [qw(1984-11  1184)],
72         #OFF [qw(06/7     0706)],
73         #OFF [qw(06-12    1206)],
74         [qw(12/06    1206)],
75         [qw(6/2000   0600)],
76         [qw(10/2000  1000)],
77         [qw(1/99     0199)],
78     );
79     foreach my $aref (@exp) {
80         my ( $exp, $moyr ) = @$aref;
81         my ($mmyy) = $obj->expdate_mmyy($exp);
82         is( $mmyy, $moyr, "$exp: MMYY '$mmyy' eq '$moyr' from $exp" );
83     }
84 }
85
86 {    # request_id
87     my $obj = $package->new($driver);
88
89     my $id = $obj->request_id;
90     isnt( $id, "", "request_id() returns something" );
91
92     is( $obj->request_id, $id, "request_id() returns the same value" );
93
94     $obj = $package->new($driver);
95     isnt( $obj->request_id, $id, "request_id() is different for each object" );
96
97     $id = "foo";
98     is( $obj->request_id($id), $id, "request_id() can be set" );
99     is( $obj->request_id, $id, "request_id() remains set" );
100 }
101
102 {    # _get_response - response parsing
103     my $obj = $package->new($driver);
104
105     is_deeply(
106         $obj->_get_response('%66%6F%78=%71%75%69%63%6B%20%25%26%3B&e=3+3'),
107         { fox => 'quick %&;', e => '3 3' },
108         "_get_response 1 returns correct value"
109     );
110     is_deeply(
111         $obj->_get_response('Foo=&&&&;;ab=t+t;q=2'),
112         { Foo => '', ab => 't t', q => '2' },
113         "_get_response 2 returns correct value"
114     );
115     is_deeply(
116         $obj->_get_response('f=s'),
117         { f => 's' },
118         "_get_response 3 returns correct value"
119     );
120     is_deeply( $obj->_get_response(''),
121         {}, "_get_response 4 returns correct value" );
122     is_deeply( $obj->_get_response(undef),
123         {}, "_get_response 5 returns correct value" );
124     is_deeply(
125         $obj->_get_response(
126 'RESULT=0&PNREF=QAAA1DF4B4F4&RESPMSG=Approved&AUTHCODE=111PNQ&AVSADDR=X&AVSZIP=X&CVV2MATCH=Y&IAVS=X'
127         ),
128         {
129             RESULT    => '0',
130             PNREF     => 'QAAA1DF4B4F4',
131             RESPMSG   => 'Approved',
132             AUTHCODE  => '111PNQ',
133             AVSADDR   => 'X',
134             AVSZIP    => 'X',
135             CVV2MATCH => 'Y',
136             IAVS      => 'X'
137         },
138         "_get_response 6 returns correct value"
139     );
140 }