File Coverage

blib/lib/Stancer/Role/Payment/Methods.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod n/a
total 35 35 100.0


line stmt bran cond sub pod time code
1             package Stancer::Role::Payment::Methods;
2              
3 14     14   280146 use 5.020;
  14         85  
4 14     14   87 use strict;
  14         30  
  14         386  
5 14     14   90 use warnings;
  14         33  
  14         1282  
6              
7             # ABSTRACT: Payment's methods relative role
8             our $VERSION = '1.0.3'; # VERSION
9              
10 14     14   706 use Stancer::Core::Types qw(coerce_instance ArrayRef CardInstance Enum Maybe SepaInstance Str);
  14         32  
  14         1671  
11 14     14   140 use List::MoreUtils qw(any);
  14         29  
  14         219  
12              
13 14     14   12288 use Moo::Role;
  14         40  
  14         116  
14              
15             requires qw(_add_modified _attribute_builder _set_method);
16              
17 14     14   10025 use namespace::clean;
  14         43  
  14         121  
18              
19              
20             has card => (
21             is => 'rw',
22             isa => Maybe[CardInstance],
23 24     24   1656 builder => sub { $_[0]->_attribute_builder('card') },
24             coerce => coerce_instance('Stancer::Card'),
25             lazy => 1,
26             predicate => 1,
27             trigger => sub { $_[0]->_add_modified('card')->_set_method('card') },
28             );
29              
30              
31             has method => (
32             is => 'rwp',
33             isa => Maybe[Str],
34 11     11   460 builder => sub { $_[0]->_attribute_builder('method') },
35             lazy => 1,
36             predicate => 1,
37             );
38              
39              
40             has methods_allowed => (
41             is => 'rw',
42             isa => Maybe[ArrayRef[Enum['card', 'sepa']]],
43 30     30   722 builder => sub { $_[0]->_attribute_builder('methods_allowed') },
44             lazy => 1,
45             predicate => 1,
46             trigger => sub { $_[0]->_add_modified('methods_allowed') },
47             );
48              
49             around methods_allowed => sub {
50             my ($orig, $class, $args) = @_;
51              
52             return $class->$orig unless defined $args;
53              
54             $args = [$args] if ref $args eq q//;
55              
56             if (
57             (not $class->_process_hydratation)
58             && defined $class->currency
59             && $class->currency ne 'eur'
60             && any { $_ eq 'sepa' } @{$args}
61             ) {
62             my $message = sprintf 'You can not ask for "%s" with "%s" currency.', (
63             'sepa',
64             uc $class->currency,
65             );
66              
67             Stancer::Exceptions::InvalidMethod->throw(message => $message);
68             }
69              
70             return $class->$orig($args);
71             };
72              
73              
74             has sepa => (
75             is => 'rw',
76             isa => Maybe[SepaInstance],
77 26     26   1181 builder => sub { $_[0]->_attribute_builder('sepa') },
78             coerce => coerce_instance('Stancer::Sepa'),
79             lazy => 1,
80             predicate => 1,
81             trigger => sub { $_[0]->_add_modified('sepa')->_set_method('sepa') },
82             );
83              
84             1;
85              
86             __END__
87              
88             =pod
89              
90             =encoding UTF-8
91              
92             =head1 NAME
93              
94             Stancer::Role::Payment::Methods - Payment's methods relative role
95              
96             =head1 VERSION
97              
98             version 1.0.3
99              
100             =head1 ATTRIBUTES
101              
102             =head2 C<card>
103              
104             Read/Write instance of C<Stancer::Card>.
105              
106             Target card for the payment.
107              
108             =head2 C<method>
109              
110             Read-only string, should be "card" or "sepa".
111              
112             Payment method used.
113              
114             =head2 C<methods_allowed>
115              
116             Read/Write arrayref of string.
117              
118             List of methods allowed to be used on payment page.
119              
120             You can pass a C<string> or an C<arrayref> of C<string>, we will always return an C<arrayref> of C<string>.
121              
122             =head2 C<sepa>
123              
124             Read/Write instance of C<Stancer::Sepa>.
125              
126             Target sepa account for the payment.
127              
128             =head1 USAGE
129              
130             =head2 Logging
131              
132              
133              
134             We use the L<Log::Any> framework for logging events.
135             You may tell where it should log using any available L<Log::Any::Adapter> module.
136              
137             For example, to log everything to a file you just have to add a line to your script, like this:
138             #! /usr/bin/env perl
139             use Log::Any::Adapter (File => '/var/log/payment.log');
140             use Stancer::Role::Payment::Methods;
141              
142             You must import C<Log::Any::Adapter> before our libraries, to initialize the logger instance before use.
143              
144             You can choose your log level on import directly:
145             use Log::Any::Adapter (File => '/var/log/payment.log', log_level => 'info');
146              
147             Read the L<Log::Any> documentation to know what other options you have.
148              
149             =cut
150              
151             =head1 SECURITY
152              
153             =over
154              
155             =item *
156              
157             Never, never, NEVER register a card or a bank account number in your database.
158              
159             =item *
160              
161             Always uses HTTPS in card/SEPA in communication.
162              
163             =item *
164              
165             Our API will never give you a complete card/SEPA number, only the last four digits.
166             If you need to keep track, use these last four digit.
167              
168             =back
169              
170             =cut
171              
172             =head1 BUGS
173              
174             Please report any bugs or feature requests on the bugtracker website
175             L<https://gitlab.com/wearestancer/library/lib-perl/-/issues> or by email to
176             L<bug-stancer@rt.cpan.org|mailto:bug-stancer@rt.cpan.org>.
177              
178             When submitting a bug or request, please include a test-file or a
179             patch to an existing test-file that illustrates the bug or desired
180             feature.
181              
182             =head1 AUTHOR
183              
184             Joel Da Silva <jdasilva@cpan.org>
185              
186             =head1 COPYRIGHT AND LICENSE
187              
188             This software is Copyright (c) 2018-2024 by Stancer / Iliad78.
189              
190             This is free software, licensed under:
191              
192             The Artistic License 2.0 (GPL Compatible)
193              
194             =cut