- updated to Test::More
[Business-OnlinePayment-PayflowPro.git] / t / credit_card.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use POSIX qw(strftime);
6 use Test::More;
7
8 use Business::OnlinePayment;
9
10 my $runinfo =
11     "to test set environment variables:"
12   . " (required) PFPRO_VENDOR PFPRO_USER PFPRO_PWD;"
13   . " (optional) PFPRO_PARTNER PFPRO_CERT_PATH";
14
15 plan(
16       ( $ENV{"PFPRO_USER"} && $ENV{"PFPRO_VENDOR"} && $ENV{"PFPRO_PWD"} )
17     ? ( tests => 2 )
18     : ( skip_all => $runinfo )
19 );
20
21 my %opts = (
22     "vendor"    => $ENV{PFPRO_VENDOR},
23     "partner"   => $ENV{PFPRO_PARTNER} || "verisign",
24     "cert_path" => $ENV{PFPRO_CERT_PATH} || ".",
25 );
26
27 my %content = (
28     type        => "VISA",
29     login       => $ENV{"PFPRO_USER"},
30     password    => $ENV{"PFPRO_PWD"},
31     action      => "Normal Authorization",
32     description => "Business::OnlinePayment::PayflowPro test",
33     amount      => "0.01",
34     first_name  => "Tofu",
35     last_name   => "Beast",
36     address     => "123 Anystreet",
37     city        => "Anywhere",
38     state       => "GA",
39     zip         => "30004",
40     country     => "US",
41     email       => 'ivan-payflowpro@420.am',
42     expiration  => "12/" . strftime( "%y", localtime ),
43     cvv2        => "123",
44
45     #card_number specified in test case
46 );
47
48 {    # valid card number test
49     my $tx = new Business::OnlinePayment( "PayflowPro", %opts );
50     $tx->content( %content, card_number => "4111111111111111" );
51     $tx->test_transaction(1);
52     $tx->submit;
53     is( $tx->is_success, 1, "valid   card num: " . tx_info($tx) );
54 }
55
56 {    # invalid card number test
57     my $tx = new Business::OnlinePayment( "PayflowPro", %opts );
58     $tx->content( %content, card_number => "4111111111111112" );
59     $tx->test_transaction(1);
60     $tx->submit;
61     is( $tx->is_success, 0, "invalid card num: " . tx_info($tx) );
62 }
63
64 sub tx_info {
65     my $tx = shift;
66
67     no warnings 'uninitialized';
68
69     return (
70         join( "",
71             "order_number(",   $tx->order_number,  ")",
72             " error_message(", $tx->error_message, ")",
73             " result_code(",   $tx->result_code,   ")",
74             " auth_info(",     $tx->authorization, ")",
75             " avs_code(",      $tx->avs_code,      ")",
76             " cvv2_code(",     $tx->cvv2_code,     ")",
77         )
78     );
79 }