File Coverage

blib/lib/Business/GoCardless/Mandate.pm
Criterion Covered Total %
statement 18 21 85.7
branch n/a
condition n/a
subroutine 12 14 85.7
pod 2 11 18.1
total 32 46 69.5


line stmt bran cond sub pod time code
1             package Business::GoCardless::Mandate;
2              
3             =head1 NAME
4              
5             Business::GoCardless::Mandate
6              
7             =head1 DESCRIPTION
8              
9             A class for a gocardless mandate, extends L
10              
11             =cut
12              
13 19     19   130 use strict;
  19         43  
  19         588  
14 19     19   299 use warnings;
  19         292  
  19         578  
15              
16 19     19   127 use Moo;
  19         43  
  19         115  
17             extends 'Business::GoCardless::Resource';
18              
19             =head1 ATTRIBUTES
20              
21             created_at
22             consent_parameters
23             funds_settlement
24             id
25             links
26             metadata
27             next_possible_charge_date
28             payments_require_approval
29             reference
30             scheme
31             status
32             verified_at
33            
34             =cut
35              
36             has [ qw/
37             created_at
38             consent_parameters
39             funds_settlement
40             id
41             links
42             metadata
43             next_possible_charge_date
44             payments_require_approval
45             reference
46             scheme
47             status
48             verified_at
49             / ] => (
50             is => 'rw',
51             );
52              
53              
54             =head1 Operations on a mandate
55              
56             =head2 cancel
57              
58             $Mandate->cancel;
59              
60             =head2 update
61              
62             $Mandate->update( %params );
63              
64             note that you can only update the metadata on a mandate, so you must pass the params
65             hash as something that looks like:
66              
67             %params = ( metadata => { ... } );
68              
69             =cut
70              
71 0     0 1 0 sub cancel { shift->_operation( undef,'api_post',undef,'actions/cancel' ); }
72              
73             sub update {
74 0     0 1 0 my ( $self,%params ) = @_;
75              
76 0         0 return $self->client->api_put(
77             sprintf( $self->endpoint,$self->id ),
78             { mandates => { %params } },
79             );
80             }
81              
82             =head1 Status checks on a mandate
83              
84             pending_customer_approval
85             pending_submission
86             submitted
87             active
88             failed
89             cancelled
90             expired
91              
92             if ( $Mandate->failed ) {
93             ...
94             }
95              
96             =cut
97              
98 1     1 0 2030 sub pending_customer_approval { return shift->status eq 'pending_customer_approval' }
99 1     1 0 9 sub pending_submission { return shift->status eq 'pending_submission' }
100 1     1 0 9 sub submitted { return shift->status eq 'submitted' }
101 1     1 0 12 sub active { return shift->status eq 'active' }
102 1     1 0 17 sub failed { return shift->status eq 'failed' }
103 1     1 0 9 sub cancelled { return shift->status eq 'cancelled' }
104 1     1 0 8 sub expired { return shift->status eq 'expired' }
105              
106             =head1 Funds settlement checks on a mandate
107              
108             is_managed
109             is_direct
110              
111             =cut
112              
113 1     1 0 8 sub is_managed { return shift->funds_settlement eq 'managed' }
114 1     1 0 11 sub is_direct { return shift->funds_settlement eq 'direct' }
115              
116             =head1 AUTHOR
117              
118             Lee Johnson - C
119              
120             This library is free software; you can redistribute it and/or modify it under
121             the same terms as Perl itself. If you would like to contribute documentation,
122             features, bug fixes, or anything else then please raise an issue / pull request:
123              
124             https://github.com/Humanstate/business-gocardless
125              
126             =cut
127              
128             1;
129              
130             # vim: ts=4:sw=4:et