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