File Coverage

blib/lib/Business/GoCardless/PreAuthorization.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 2 100.0
condition n/a
subroutine 10 10 100.0
pod 0 6 0.0
total 38 44 86.3


line stmt bran cond sub pod time code
1             package Business::GoCardless::PreAuthorization;
2              
3             =head1 NAME
4              
5             Business::GoCardless::PreAuthorization
6              
7             =head1 DESCRIPTION
8              
9             A class for a gocardless pre_authorization, extends L
10              
11             =cut
12              
13 19     19   1249 use strict;
  19         56  
  19         563  
14 19     19   99 use warnings;
  19         48  
  19         471  
15              
16 19     19   124 use Moo;
  19         54  
  19         119  
17             extends 'Business::GoCardless::Resource';
18              
19 19     19   7566 use Business::GoCardless::Bill;
  19         48  
  19         7087  
20              
21             =head1 ATTRIBUTES
22              
23             created_at
24             currency
25             description
26             expires_at
27             id
28             interval_length
29             interval_unit
30             max_amount
31             merchant_id
32             name
33             next_interval_start
34             remaining_amount
35             setup_fee
36             status
37             sub_resource_uris
38             uri
39             user_id
40              
41             =cut
42              
43             has [ qw/
44             created_at
45             currency
46             description
47             expires_at
48             id
49             interval_length
50             interval_unit
51             max_amount
52             merchant_id
53             name
54             next_interval_start
55             remaining_amount
56             setup_fee
57             status
58             sub_resource_uris
59             uri
60             user_id
61             / ] => (
62             is => 'rw',
63             );
64              
65             =head1 Operations on a pre_authorization
66              
67             bill
68              
69             my $Bill = $PreAuthorization->bill;
70              
71             Creates a new bill, returning a L object.
72              
73             cancel
74              
75             $PreAuthorization->cancel;
76              
77             Cancels a pre_authorization.
78              
79             =cut
80              
81             sub bill {
82 2     2 0 7062 my ( $self,%params ) = @_;
83              
84 2 100       62 if ( $self->client->api_version > 1 ) {
85              
86             my $post_data = {
87             payments => {
88             %params,
89             links => {
90             # $self here will be a RedirectFlow
91             mandate => $self->links->{mandate},
92             },
93             },
94 1         27 };
95              
96 1         7 my $data = $self->client->api_post( "/payments",$post_data );
97              
98             return Business::GoCardless::Payment->new(
99             client => $self->client,
100 1         12 %{ $data->{payments} },
  1         64  
101             );
102             }
103              
104 1         22 my $data = $self->client->api_post(
105             "/bills",
106             {
107             bill => {
108             pre_authorization_id => $self->id,
109             %params,
110             }
111             }
112             );
113              
114             return Business::GoCardless::Bill->new(
115             client => $self->client,
116 1         7 %{ $data }
  1         28  
117             );
118             }
119              
120 1     1 0 2911 sub cancel { shift->_operation( 'cancel','api_put' ); }
121              
122             =head1 Status checks on a pre_authorization
123              
124             inactive
125             active
126             cancelled
127             expired
128              
129             if ( $PreAuthorization->active ) {
130             ...
131             }
132              
133             =cut
134              
135 2     2 0 4361 sub inactive { return shift->status eq 'inactive' }
136 2     2 0 17 sub active { return shift->status eq 'active' }
137 3     3 0 2871 sub cancelled { return shift->status eq 'cancelled' }
138 2     2 0 18 sub expired { return shift->status eq 'expired' }
139              
140             =head1 AUTHOR
141              
142             Lee Johnson - C
143              
144             This library is free software; you can redistribute it and/or modify it under
145             the same terms as Perl itself. If you would like to contribute documentation,
146             features, bug fixes, or anything else then please raise an issue / pull request:
147              
148             https://github.com/Humanstate/business-gocardless
149              
150             =cut
151              
152             1;
153              
154             # vim: ts=4:sw=4:et