File Coverage

blib/lib/WWW/PayPal/API/Payments.pm
Criterion Covered Total %
statement 15 32 46.8
branch 0 12 0.0
condition n/a
subroutine 5 9 55.5
pod 3 3 100.0
total 23 56 41.0


line stmt bran cond sub pod time code
1             package WWW::PayPal::API::Payments;
2              
3             # ABSTRACT: PayPal Payments v2 API (captures, refunds, authorizations)
4              
5 2     2   16 use Moo;
  2         6  
  2         15  
6 2     2   882 use Carp qw(croak);
  2         5  
  2         146  
7 2     2   1210 use WWW::PayPal::Capture;
  2         8  
  2         88  
8 2     2   1163 use WWW::PayPal::Refund;
  2         9  
  2         98  
9 2     2   44 use namespace::clean;
  2         9  
  2         11  
10              
11             our $VERSION = '0.002';
12              
13              
14             has client => (
15             is => 'ro',
16             required => 1,
17             weak_ref => 1,
18             );
19              
20             has openapi_operations => (
21             is => 'lazy',
22             builder => sub {
23             # Pre-computed from paypal-rest-api-specifications
24             # (openapi/payments_payment_v2.json).
25             return {
26 0     0     'captures.get' => { method => 'GET', path => '/v2/payments/captures/{capture_id}' },
27             'captures.refund' => { method => 'POST', path => '/v2/payments/captures/{capture_id}/refund' },
28             'refunds.get' => { method => 'GET', path => '/v2/payments/refunds/{refund_id}' },
29             'authorizations.get' => { method => 'GET', path => '/v2/payments/authorizations/{authorization_id}' },
30             'authorizations.capture' => { method => 'POST', path => '/v2/payments/authorizations/{authorization_id}/capture' },
31             'authorizations.void' => { method => 'POST', path => '/v2/payments/authorizations/{authorization_id}/void' },
32             };
33             },
34             );
35              
36             with 'WWW::PayPal::Role::OpenAPI';
37              
38             sub get_capture {
39 0     0 1   my ($self, $id) = @_;
40 0 0         croak 'capture_id required' unless $id;
41 0           my $data = $self->call_operation('captures.get', path => { capture_id => $id });
42 0           return WWW::PayPal::Capture->new(client => $self->client, data => $data);
43             }
44              
45              
46             sub refund {
47 0     0 1   my ($self, $capture_id, %args) = @_;
48 0 0         croak 'capture_id required' unless $capture_id;
49              
50 0           my $body = {};
51 0 0         $body->{amount} = $args{amount} if $args{amount};
52 0 0         $body->{invoice_id} = $args{invoice_id} if $args{invoice_id};
53 0 0         $body->{note_to_payer} = $args{note_to_payer} if $args{note_to_payer};
54              
55 0           my $data = $self->call_operation('captures.refund',
56             path => { capture_id => $capture_id },
57             body => $body,
58             );
59 0           return WWW::PayPal::Refund->new(client => $self->client, data => $data);
60             }
61              
62              
63             sub get_refund {
64 0     0 1   my ($self, $id) = @_;
65 0 0         croak 'refund_id required' unless $id;
66 0           my $data = $self->call_operation('refunds.get', path => { refund_id => $id });
67 0           return WWW::PayPal::Refund->new(client => $self->client, data => $data);
68             }
69              
70              
71             1;
72              
73             __END__