line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::Bitpay; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
30933
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
40
|
use 5.008_001; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
90
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
8
|
|
|
|
|
|
|
eval $VERSION; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1532
|
use HTTP::Request; |
|
2
|
|
|
|
|
103736
|
|
|
2
|
|
|
|
|
78
|
|
11
|
2
|
|
|
2
|
|
22
|
use URI; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
12
|
2
|
|
|
2
|
|
2712
|
use JSON qw(encode_json decode_json); |
|
2
|
|
|
|
|
53477
|
|
|
2
|
|
|
|
|
14
|
|
13
|
2
|
|
|
2
|
|
4279
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
58852
|
|
|
2
|
|
|
|
|
1180
|
|
14
|
|
|
|
|
|
|
require Carp; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
1
|
50
|
|
1
|
1
|
71
|
my ($class, $api_key, @args) = @_ or Carp::croak("api key missed"); |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
10
|
bless { |
20
|
|
|
|
|
|
|
key => $api_key, |
21
|
|
|
|
|
|
|
gateway => 'https://bitpay.com/api/', |
22
|
|
|
|
|
|
|
ua => LWP::UserAgent->new, |
23
|
|
|
|
|
|
|
@args |
24
|
|
|
|
|
|
|
}, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub prepare_request { |
28
|
2
|
|
|
2
|
0
|
11800
|
my ($self, $api, $data) = @_; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
24
|
my $uri = URI->new($self->{gateway}); |
31
|
2
|
|
|
|
|
10983
|
$uri->userinfo($self->{key} . ':'); |
32
|
2
|
|
|
|
|
336
|
$uri->path($uri->path . $api); |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
97
|
my $method = 'GET'; |
35
|
2
|
|
|
|
|
5
|
my @fields; |
36
|
2
|
100
|
|
|
|
9
|
if ($data) { |
37
|
1
|
|
|
|
|
2
|
$method = 'POST'; |
38
|
1
|
|
|
|
|
22
|
$data = encode_json $data; |
39
|
1
|
|
|
|
|
4
|
push @fields, 'Content-Type' => 'application/json'; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
24
|
my $request = HTTP::Request->new( |
43
|
|
|
|
|
|
|
$method => $uri, [ |
44
|
|
|
|
|
|
|
'User-Agent' => 'bitpay api', |
45
|
|
|
|
|
|
|
'X-BitPay-Plugin-Info' => 'perl' . $VERSION, |
46
|
|
|
|
|
|
|
@fields, |
47
|
|
|
|
|
|
|
], |
48
|
|
|
|
|
|
|
$data |
49
|
|
|
|
|
|
|
); |
50
|
2
|
|
|
|
|
429
|
$request; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub request { |
54
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $http_response = $self->{ua}->request($self->prepare_request(@_)); |
57
|
0
|
0
|
|
|
|
|
Carp::croak($http_response->status_line) |
58
|
|
|
|
|
|
|
unless $http_response->is_success; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $response = decode_json($http_response->decoded_content); |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if (my $error = $response->{error}) { |
63
|
0
|
|
|
|
|
|
my $messages = $error->{messages}; |
64
|
0
|
|
|
|
|
|
Carp::croak("$error->{message}: ", |
65
|
0
|
|
|
|
|
|
join(', ', map {"$_ ($messages->{$_})"} keys %$messages)); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$response; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub create_invoice { |
73
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
Carp::croak('price missed') unless exists $args{price}; |
76
|
0
|
0
|
|
|
|
|
Carp::croak('currency missed') unless exists $args{currency}; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->request('invoice', \%args); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub get_invoice { |
82
|
0
|
|
|
0
|
1
|
|
my ($self, $id) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->request("invoice/$id"); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
__END__ |