2fbab5ad59621d770fddf5734f879e1a66108615
[Business-OnlinePayment-PayflowPro.git] / t / bop.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More tests => 24;
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.verisign.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 }