File Coverage

blib/lib/Business/GoCardless/Mandate.pm
Criterion Covered Total %
statement 26 29 89.6
branch n/a
condition 5 10 50.0
subroutine 20 22 90.9
pod 2 19 10.5
total 53 80 66.2


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