File: bop.t

package info (click to toggle)
libbusiness-onlinepayment-payflowpro-perl 1.01-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 100 kB
  • ctags: 11
  • sloc: perl: 583; makefile: 2
file content (140 lines) | stat: -rw-r--r-- 3,883 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl

use strict;
use warnings;
use Test::More tests => 30;

use Business::OnlinePayment;

my $package = "Business::OnlinePayment";
my $driver  = "PayflowPro";

{    # new
    my $obj;

    $obj = $package->new($driver);
    isa_ok( $obj, $package );

    # convenience methods
    can_ok( $obj, qw(vendor partner) );
    can_ok( $obj, qw(order_number avs_code cvv2_response) );
    can_ok( $obj, qw(request_id debug expdate_mmyy) );

    # internal methods
    can_ok( $obj, qw(_map_fields _revmap_fields) );

    # defaults
    my $server = "payflowpro.paypal.com";

    is( $obj->server, $server, "server($server)" );
    is( $obj->port, "443", "port(443)" );
}

{    # cvv2_response / cvv2_code
    my $obj = $package->new($driver);

    my $exp = "Z";
    $obj->cvv2_response($exp);

    is( $obj->cvv2_response, $exp, "cvv2_response() is set" );
    is( $obj->cvv2_code,     $exp, "cvv2_code() calls cvv2_response" );
}

{    # client_certification_id
    my $obj = $package->new($driver);

    my $id = $obj->client_certification_id;
    isnt( $id, "", "client_certification_id() is set" );

    $id = "foo";
    is( $obj->client_certification_id($id),
        $id, "client_certification_id() can be set" );
    is( $obj->client_certification_id,
        $id, "client_certification_id() remains set" );
}

{    # client_timeout
    my $obj = $package->new($driver);

    is( $obj->client_timeout, 45, "client_timeout() returns 45 by default" );

    my $to = 60;
    is( $obj->client_timeout($to), $to, "client_timeout() can be set" );
    is( $obj->client_timeout, $to, "client_timeout() remains set" );
}

{    # expdate
    my $obj = $package->new($driver);
    my @exp = (

        #OFF [qw(1999.8   0899)],
        #OFF [qw(1984-11  1184)],
        #OFF [qw(06/7     0706)],
        #OFF [qw(06-12    1206)],
        [qw(12/06    1206)],
        [qw(6/2000   0600)],
        [qw(10/2000  1000)],
        [qw(1/99     0199)],
    );
    foreach my $aref (@exp) {
        my ( $exp, $moyr ) = @$aref;
        my ($mmyy) = $obj->expdate_mmyy($exp);
        is( $mmyy, $moyr, "$exp: MMYY '$mmyy' eq '$moyr' from $exp" );
    }
}

{    # request_id
    my $obj = $package->new($driver);

    my $id = $obj->request_id;
    isnt( $id, "", "request_id() returns something" );

    is( $obj->request_id, $id, "request_id() returns the same value" );

    $obj = $package->new($driver);
    isnt( $obj->request_id, $id, "request_id() is different for each object" );

    $id = "foo";
    is( $obj->request_id($id), $id, "request_id() can be set" );
    is( $obj->request_id, $id, "request_id() remains set" );
}

{    # _get_response - response parsing
    my $obj = $package->new($driver);

    is_deeply(
        $obj->_get_response('%66%6F%78=%71%75%69%63%6B%20%25%26%3B&e=3+3'),
        { fox => 'quick %&;', e => '3 3' },
        "_get_response 1 returns correct value"
    );
    is_deeply(
        $obj->_get_response('Foo=&&&&;;ab=t+t;q=2'),
        { Foo => '', ab => 't t', q => '2' },
        "_get_response 2 returns correct value"
    );
    is_deeply(
        $obj->_get_response('f=s'),
        { f => 's' },
        "_get_response 3 returns correct value"
    );
    is_deeply( $obj->_get_response(''),
        {}, "_get_response 4 returns correct value" );
    is_deeply( $obj->_get_response(undef),
        {}, "_get_response 5 returns correct value" );
    is_deeply(
        $obj->_get_response(
'RESULT=0&PNREF=QAAA1DF4B4F4&RESPMSG=Approved&AUTHCODE=111PNQ&AVSADDR=X&AVSZIP=X&CVV2MATCH=Y&IAVS=X'
        ),
        {
            RESULT    => '0',
            PNREF     => 'QAAA1DF4B4F4',
            RESPMSG   => 'Approved',
            AUTHCODE  => '111PNQ',
            AVSADDR   => 'X',
            AVSZIP    => 'X',
            CVV2MATCH => 'Y',
            IAVS      => 'X'
        },
        "_get_response 6 returns correct value"
    );
}