line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::PinPayment; |
2
|
2
|
|
|
2
|
|
27965
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
86
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
1873
|
use Net::SSL; |
|
2
|
|
|
|
|
87932
|
|
|
2
|
|
|
|
|
38
|
|
5
|
2
|
|
|
2
|
|
3570
|
use HTTP::Request; |
|
2
|
|
|
|
|
59369
|
|
|
2
|
|
|
|
|
72
|
|
6
|
2
|
|
|
2
|
|
2432
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
72796
|
|
|
2
|
|
|
|
|
73
|
|
7
|
2
|
|
|
2
|
|
1214
|
use JSON; |
|
2
|
|
|
|
|
14510
|
|
|
2
|
|
|
|
|
16
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# build 4.1 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
1
|
1556
|
my ($class, %args) = (@_); |
15
|
1
|
|
|
|
|
3
|
my $self = bless {}, $class; |
16
|
1
|
|
50
|
|
|
12
|
$args{config} ||= {}; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
24
|
$self->{config} = { |
19
|
|
|
|
|
|
|
api_version => '1', # the '1' in the API endpoint host names, e.g. https://test-api.pin.net.au/1/charges |
20
|
|
|
|
|
|
|
api_key => undef, # Secret API Key |
21
|
|
|
|
|
|
|
api => 'charges', # 'customers', 'refunds' |
22
|
|
|
|
|
|
|
amount => '100', # 100 cents. Must be greater or equal to $1.00 |
23
|
|
|
|
|
|
|
currency => 'AUD', # 'USD', 'NZD', or 'SGD' |
24
|
|
|
|
|
|
|
description => 'charges', |
25
|
|
|
|
|
|
|
email => 'tester@work.com.au', |
26
|
|
|
|
|
|
|
ip_address => undef, |
27
|
|
|
|
|
|
|
charge_token => undef, # for refunds API |
28
|
|
|
|
|
|
|
card_token => undef, |
29
|
|
|
|
|
|
|
customer_token => undef, |
30
|
|
|
|
|
|
|
card => { |
31
|
|
|
|
|
|
|
number => '5520000000000000', |
32
|
|
|
|
|
|
|
expiry_month => '05', |
33
|
|
|
|
|
|
|
expiry_year => '2014', |
34
|
|
|
|
|
|
|
cvc => '123', |
35
|
|
|
|
|
|
|
name => 'John Smith', |
36
|
|
|
|
|
|
|
address_line1 => '1 Test St', |
37
|
|
|
|
|
|
|
address_line2 => undef, |
38
|
|
|
|
|
|
|
address_city => 'Sydney', |
39
|
|
|
|
|
|
|
address_postcode => '2000', |
40
|
|
|
|
|
|
|
address_state => 'NSW', |
41
|
|
|
|
|
|
|
address_country => 'Australia' |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
3
|
foreach my $key (qw(api_key api amount currency description email ip_address charge_token card_token customer_token)) { |
46
|
10
|
50
|
|
|
|
27
|
next unless defined $args{config}->{$key}; |
47
|
0
|
|
|
|
|
0
|
$self->{config}->{$key} = $args{config}->{$key}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
50
|
33
|
|
|
14
|
if ($self->{config}->{card_token} || $self->{config}->{customer_token}) { |
51
|
0
|
|
|
|
|
0
|
delete $self->{config}->{card}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
1
|
|
|
|
|
3
|
foreach my $key (qw(number expiry_month expiry_year cvc name address_line1 address_line2 address_city address_postcode address_state address_country)) { |
55
|
11
|
50
|
|
|
|
31
|
next unless defined $args{config}->{card}->{$key}; |
56
|
0
|
|
|
|
|
0
|
$self->{config}->{card}->{$key} = $args{config}->{card}->{$key}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
2
|
my $url; |
61
|
1
|
|
|
|
|
2
|
my $live = $args{live}; |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
4
|
my $api = delete ($self->{config}->{api}); |
64
|
1
|
|
|
|
|
2
|
my $api_version = delete ($self->{config}->{api_version}); |
65
|
1
|
|
|
|
|
3
|
my $api_key = delete ($self->{config}->{api_key}); |
66
|
|
|
|
|
|
|
|
67
|
1
|
50
|
|
|
|
5
|
unless ($api_key) { |
68
|
1
|
|
|
|
|
5
|
$self->{error} = 'Missing Secret API Key'; |
69
|
1
|
|
|
|
|
6
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
0
|
if ($live) { |
73
|
0
|
|
|
|
|
0
|
$url = 'https://api.pin.net.au/' . $api_version; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else { |
76
|
0
|
|
|
|
|
0
|
$url = 'https://test-api.pin.net.au/' . $api_version |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
0
|
|
|
0
|
if ($api eq 'refunds' && $self->{config}->{charge_token}) { |
80
|
0
|
|
|
|
|
0
|
$url .= '/charges/' . $self->{config}->{charge_token} .'/' .$api; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
0
|
$url .= '/' . $api; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
my $ua = LWP::UserAgent->new(); |
87
|
0
|
|
|
|
|
0
|
my $p = HTTP::Request->new(POST => $url); |
88
|
0
|
|
|
|
|
0
|
$p->content_type('application/json'); |
89
|
0
|
|
|
|
|
0
|
$p->authorization_basic($api_key); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
my $json_request = to_json( $self->{config}, {utf8 => 1} ); |
92
|
0
|
0
|
|
|
|
0
|
$p->content($json_request) unless $api eq 'refunds'; |
93
|
0
|
|
|
|
|
0
|
$self->{response} = $ua->request($p); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
my $json_response; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
0
|
if ($self->{response}->content) { |
98
|
0
|
|
|
|
|
0
|
$json_response = from_json( $self->{response}->content, {utf8 => 1} ); |
99
|
0
|
|
|
|
|
0
|
$self->{json_response} = $json_response; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
0
|
if ($json_response) { |
103
|
0
|
0
|
|
|
|
0
|
if ($json_response->{response}->{success}) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
$self->{successful} = 1; |
105
|
0
|
|
|
|
|
0
|
$self->{id} = $json_response->{response}->{token}; |
106
|
0
|
|
|
|
|
0
|
$self->{status} = $json_response->{response}->{status_message}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
elsif ($json_response->{response}->{token}) { |
109
|
0
|
|
|
|
|
0
|
$self->{successful} = 1; |
110
|
0
|
|
|
|
|
0
|
$self->{id} = $json_response->{response}->{token}; |
111
|
0
|
|
0
|
|
|
0
|
$self->{status} = $json_response->{response}->{status_message} || ''; # customers has non status message |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
elsif (exists $json_response->{error}) { |
114
|
0
|
|
|
|
|
0
|
$self->{status} = $json_response->{error}; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
my @errors = ($json_response->{error_description} . '.'); |
117
|
0
|
0
|
|
|
|
0
|
if (exists $json_response->{messages}) { |
118
|
0
|
|
|
|
|
0
|
foreach my $message (@{$json_response->{messages}}) { |
|
0
|
|
|
|
|
0
|
|
119
|
0
|
|
|
|
|
0
|
push (@errors, $message->{message} . '.'); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
0
|
$self->{error} = join (' ', @errors); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
elsif (exists $json_response->{messages}) { |
125
|
0
|
|
|
|
|
0
|
$self->{error} = $json_response->{messages}->[0]->{message}; |
126
|
0
|
|
|
|
|
0
|
$self->{status} = $json_response->{messages}->[0]->{code}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
else { |
130
|
0
|
|
|
|
|
0
|
$self->{error} = $self->{response}->status_line; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
return $self; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub card_token { |
137
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
138
|
0
|
|
0
|
|
|
0
|
return $self->{json_response}->{response}->{card}->{token} || ''; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub json_response { |
142
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
143
|
0
|
|
0
|
|
|
0
|
return $self->{json_response} || {}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub response { |
147
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
148
|
0
|
|
0
|
|
|
0
|
return $self->{response} || ''; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub successful { |
152
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
153
|
0
|
|
0
|
|
|
0
|
return $self->{successful} || undef; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub error { |
157
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
158
|
1
|
|
50
|
|
|
7
|
return $self->{error} || ''; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub id { |
162
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
163
|
0
|
|
0
|
|
|
|
return $self->{id} || ''; # charge or customer token depending on the API |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub status { |
167
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
168
|
0
|
|
0
|
|
|
|
return $self->{status} || ''; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |