summaryrefslogtreecommitdiff
path: root/t/credit_card.t
blob: 7b574845c49fe45ecef2056151850cf25e9af79b (plain)
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
#!/usr/bin/perl

use strict;
use warnings;
use POSIX qw(strftime);
use Test::More;

use Business::OnlinePayment;

my $runinfo =
    "to test set environment variables:"
  . " (required) PFPRO_VENDOR PFPRO_USER PFPRO_PWD;"
  . " (optional) PFPRO_PARTNER PFPRO_CERT_PATH";

plan(
      ( $ENV{"PFPRO_USER"} && $ENV{"PFPRO_VENDOR"} && $ENV{"PFPRO_PWD"} )
    ? ( tests => 2 )
    : ( skip_all => $runinfo )
);

my %opts = (
    "vendor"    => $ENV{PFPRO_VENDOR},
    "partner"   => $ENV{PFPRO_PARTNER} || "verisign",
    "cert_path" => $ENV{PFPRO_CERT_PATH} || ".",
);

my %content = (
    type        => "VISA",
    login       => $ENV{"PFPRO_USER"},
    password    => $ENV{"PFPRO_PWD"},
    action      => "Normal Authorization",
    description => "Business::OnlinePayment::PayflowPro test",
    amount      => "0.01",
    first_name  => "Tofu",
    last_name   => "Beast",
    address     => "123 Anystreet",
    city        => "Anywhere",
    state       => "GA",
    zip         => "30004",
    country     => "US",
    email       => 'ivan-payflowpro@420.am',
    expiration  => "12/" . strftime( "%y", localtime ),
    cvv2        => "123",

    #card_number specified in test case
);

{    # valid card number test
    my $tx = new Business::OnlinePayment( "PayflowPro", %opts );
    $tx->content( %content, card_number => "4111111111111111" );
    $tx->test_transaction(1);
    $tx->submit;
    is( $tx->is_success, 1, "valid   card num: " . tx_info($tx) );
}

{    # invalid card number test
    my $tx = new Business::OnlinePayment( "PayflowPro", %opts );
    $tx->content( %content, card_number => "4111111111111112" );
    $tx->test_transaction(1);
    $tx->submit;
    is( $tx->is_success, 0, "invalid card num: " . tx_info($tx) );
}

sub tx_info {
    my $tx = shift;

    no warnings 'uninitialized';

    return (
        join( "",
            "order_number(",   $tx->order_number,  ")",
            " error_message(", $tx->error_message, ")",
            " result_code(",   $tx->result_code,   ")",
            " auth_info(",     $tx->authorization, ")",
            " avs_code(",      $tx->avs_code,      ")",
            " cvv2_code(",     $tx->cvv2_code,     ")",
        )
    );
}