line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::PxPay; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: PX Pay Interface for www.paymentexpress.com |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
68822
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
8
|
1
|
|
|
1
|
|
454
|
use URI::Escape qw/uri_escape/; |
|
1
|
|
|
|
|
1437
|
|
|
1
|
|
|
|
|
54
|
|
9
|
1
|
|
|
1
|
|
646
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
45388
|
|
|
1
|
|
|
|
|
41
|
|
10
|
1
|
|
|
1
|
|
805
|
use XML::Simple qw/XMLin XMLout/; |
|
1
|
|
|
|
|
8695
|
|
|
1
|
|
|
|
|
8
|
|
11
|
1
|
|
|
1
|
|
104
|
use vars qw/%TRANSACTIONS/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
732
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
%TRANSACTIONS = ( |
16
|
|
|
|
|
|
|
purchase => 'Purchase', |
17
|
|
|
|
|
|
|
credit => 'Refund', |
18
|
|
|
|
|
|
|
authorization => 'Auth', |
19
|
|
|
|
|
|
|
capture => 'Complete', |
20
|
|
|
|
|
|
|
validate => 'Validate' |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
25
|
0
|
0
|
|
|
|
|
my $args = scalar @_ % 2 ? shift : { @_ }; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# validate |
28
|
0
|
0
|
|
|
|
|
$args->{userid} or croak 'userid is required'; |
29
|
0
|
0
|
|
|
|
|
$args->{key} or croak 'key is required'; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
$args->{url} ||= 'https://sec.paymentexpress.com/pxpay/pxaccess.aspx'; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
unless ( $args->{ua} ) { |
34
|
0
|
|
0
|
|
|
|
my $ua_args = delete $args->{ua_args} || {}; |
35
|
0
|
|
|
|
|
|
$args->{ua} = LWP::UserAgent->new(%$ua_args); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
bless $args, $class; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub request { |
42
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
43
|
0
|
0
|
|
|
|
|
my $args = scalar @_ % 2 ? shift : { @_ }; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $xml = $self->request_xml($args); |
46
|
0
|
|
|
|
|
|
my $resp = $self->{ua}->post($self->{url}, Content => $xml); |
47
|
0
|
0
|
|
|
|
|
unless ($resp->is_success) { |
48
|
0
|
|
|
|
|
|
croak $resp->status_line; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
my $rtn = XMLin($resp->content, SuppressEmpty => undef); |
51
|
0
|
|
|
|
|
|
return $rtn; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub request_xml { |
55
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
56
|
0
|
0
|
|
|
|
|
my $args = scalar @_ % 2 ? shift : { @_ }; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# validate |
59
|
0
|
|
0
|
|
|
|
my $TxnType = $args->{TxnType} || croak 'TxnType is required'; |
60
|
0
|
|
0
|
|
|
|
my $Amount = $args->{Amount} || $self->{Amount} || croak 'Amount is required'; |
61
|
0
|
|
|
|
|
|
$Amount = sprintf ("%.2f", $Amount); # .XX format |
62
|
0
|
|
0
|
|
|
|
my $Currency = $args->{Currency} || $self->{Currency} || croak 'Currency is required'; |
63
|
0
|
|
0
|
|
|
|
my $UrlFail = $args->{UrlFail} || $self->{UrlFail} || croak 'UrlFail is required'; |
64
|
0
|
|
0
|
|
|
|
my $UrlSuccess = $args->{UrlSuccess} || $self->{UrlSuccess} || croak 'UrlSuccess is required'; |
65
|
0
|
|
0
|
|
|
|
my $MerchantReference = $args->{MerchantReference} || croak 'MerchantReference is required'; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# UrlFail can't contain '?' or '&' |
68
|
0
|
0
|
0
|
|
|
|
if ( $UrlFail =~ /\?/ or $UrlFail =~ /\&/ ) { |
69
|
0
|
|
|
|
|
|
croak "UrlFail can't contain '?' or '&', please use TxnData1, TxnData2, TxnData3 or Opt\n"; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
0
|
|
|
|
if ( $UrlSuccess =~ /\?/ or $UrlSuccess =~ /\&/ ) { |
72
|
0
|
|
|
|
|
|
croak "UrlSuccess can't contain '?' or '&', please use TxnData1, TxnData2, TxnData3 or Opt\n"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $request = { |
76
|
|
|
|
|
|
|
GenerateRequest => { |
77
|
|
|
|
|
|
|
PxPayUserId => [ $self->{userid} ], |
78
|
|
|
|
|
|
|
PxPayKey => [ $self->{key} ], |
79
|
|
|
|
|
|
|
AmountInput => [ $Amount ], |
80
|
|
|
|
|
|
|
CurrencyInput => [ $Currency ], |
81
|
|
|
|
|
|
|
MerchantReference => [ $MerchantReference ], |
82
|
|
|
|
|
|
|
EmailAddress => [ $args->{EmailAddress} ], |
83
|
|
|
|
|
|
|
TxnData1 => [ $args->{TxnData1} ], |
84
|
|
|
|
|
|
|
TxnData2 => [ $args->{TxnData2} ], |
85
|
|
|
|
|
|
|
TxnData3 => [ $args->{TxnData3} ], |
86
|
|
|
|
|
|
|
TxnType => [ $TxnType ], |
87
|
|
|
|
|
|
|
TxnId => [ $args->{TxnId} ], |
88
|
|
|
|
|
|
|
BillingId => [ $args->{BillingId} ], |
89
|
|
|
|
|
|
|
EnableAddBillCard => [ $args->{EnableAddBillCard} ], |
90
|
|
|
|
|
|
|
UrlSuccess => [ $UrlSuccess ], |
91
|
|
|
|
|
|
|
UrlFail => [ $UrlFail ], |
92
|
0
|
|
|
|
|
|
Opt => [ $args->{Opt} ], |
93
|
|
|
|
|
|
|
}, |
94
|
|
|
|
|
|
|
}; |
95
|
0
|
|
|
|
|
|
return XMLout( $request, KeepRoot => 1 ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub result { |
99
|
0
|
|
|
0
|
1
|
|
my ( $self, $ResponseCode ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $xml = $self->result_xml($ResponseCode); |
102
|
0
|
|
|
|
|
|
my $resp = $self->{ua}->post($self->{url}, Content => $xml); |
103
|
0
|
0
|
|
|
|
|
unless ($resp->is_success) { |
104
|
0
|
|
|
|
|
|
croak $resp->status_line; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
my $rtn = XMLin($resp->content, SuppressEmpty => undef); |
107
|
0
|
|
|
|
|
|
return $rtn; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub result_xml { |
111
|
0
|
|
|
0
|
0
|
|
my ( $self, $ResponseCode ) = @_; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $request = { |
114
|
|
|
|
|
|
|
ProcessResponse => { |
115
|
|
|
|
|
|
|
PxPayUserId => [ $self->{userid} ], |
116
|
0
|
|
|
|
|
|
PxPayKey => [ $self->{key} ], |
117
|
|
|
|
|
|
|
Response => [ $ResponseCode ], |
118
|
|
|
|
|
|
|
}, |
119
|
|
|
|
|
|
|
}; |
120
|
0
|
|
|
|
|
|
return XMLout( $request, KeepRoot => 1 ); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
__END__ |