File Coverage

blib/lib/Business/GoCardless/Payment.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition 1 2 50.0
subroutine 19 19 100.0
pod 0 15 0.0
total 47 63 74.6


line stmt bran cond sub pod time code
1             package Business::GoCardless::Payment;
2              
3             =head1 NAME
4              
5             Business::GoCardless::Payment
6              
7             =head1 DESCRIPTION
8              
9             A class for a gocardless payment, extends L
10              
11             =cut
12              
13 5     5   188696 use strict;
  5         11  
  5         207  
14 5     5   27 use warnings;
  5         8  
  5         278  
15              
16 5     5   28 use Moo;
  5         72  
  5         34  
17              
18             extends 'Business::GoCardless::Resource';
19              
20             =head1 ATTRIBUTES
21              
22             amount
23             amount_refunded
24             charge_date
25             created_at
26             currency
27             description
28             fx
29             id
30             links
31             metadata
32             reference
33             retry_if_possible
34             status
35              
36             =cut
37              
38             has [ qw/
39             amount
40             amount_refunded
41             charge_date
42             created_at
43             currency
44             description
45             fx
46             id
47             links
48             metadata
49             reference
50             retry_if_possible
51             status
52             / ] => (
53             is => 'rw',
54             );
55              
56             =head1 Operations on a payment
57              
58             retry
59             cancel
60             refund
61              
62             $Payment->retry if $Payment->failed;
63              
64             =cut
65              
66 1     1 0 3638 sub retry { shift->_operation( undef,'api_post',undef,'actions/retry' ); }
67 1     1 0 4809 sub cancel { shift->_operation( undef,'api_post',undef,'actions/cancel' ); }
68             sub refund {
69             # apparently this endpoint is restricted by default, so nuts to it for now
70 1     1 0 5 return 0;
71             }
72              
73             =head1 Status checks on a payment
74              
75             pending
76             paid
77             failed
78             chargedback
79             cancelled
80             withdrawn
81             refunded
82             submitted
83             confirmed
84              
85             if ( $Payment->failed ) {
86             ...
87             }
88              
89             =cut
90              
91 1     1 0 2052 sub pending { return shift->status =~ /pending/ }
92 1     1 0 8 sub paid { return shift->status eq 'paid_out' }
93 1     1 0 7 sub failed { return shift->status eq 'failed' }
94 1     1 0 7 sub chargedback { return shift->status eq 'charged_back' }
95 2     2 0 2889 sub cancelled { return shift->status eq 'cancelled' }
96 1     1 0 14 sub withdrawn { return shift->status eq 'customer_appoval_denied' }
97 1     1 0 8 sub refunded { return shift->status eq 'refunded' }
98 1     1 0 6 sub submitted { return shift->status eq 'submitted' }
99 1     1 0 24 sub confirmed { return shift->status eq 'confirmed' }
100              
101             =head1 payout_id
102              
103             =head1 mandate_id
104              
105             =head1 creditor_id
106              
107             Accessors for details found in the C section
108              
109             =cut
110              
111 2     2 0 23 sub payout_id { return shift->_link_content( 'payout' ) }
112 1     1 0 3 sub mandate_id { return shift->_link_content( 'mandate' ) }
113 1     1 0 5 sub creditor_id { return shift->_link_content( 'creditor' ) }
114              
115             sub _link_content {
116 4     4   11 my ( $self,$attr ) = @_;
117 4   50     22 my $links = $self->links || {};
118 4         25 return $links->{$attr};
119             }
120              
121             =head1 AUTHOR
122              
123             Lee Johnson - C
124              
125             This library is free software; you can redistribute it and/or modify it under
126             the same terms as Perl itself. If you would like to contribute documentation,
127             features, bug fixes, or anything else then please raise an issue / pull request:
128              
129             https://github.com/Humanstate/business-gocardless
130              
131             =cut
132              
133             1;
134              
135             # vim: ts=4:sw=4:et