File Coverage

blib/lib/Stancer/Core/Types/ApiKeys.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1             package Stancer::Core::Types::ApiKeys;
2              
3 61     61   440400 use 5.020;
  61         234  
4 61     61   399 use strict;
  61         238  
  61         1916  
5 61     61   315 use warnings;
  61         142  
  61         8157  
6              
7             # ABSTRACT: Internal ApiKeys types
8             our $VERSION = '1.0.3'; # VERSION
9              
10             our @EXPORT_OK = ();
11             our %EXPORT_TAGS = ('all' => \@EXPORT_OK);
12              
13 61     61   34100 use Stancer::Core::Types::Helper qw(error_message);
  61         249  
  61         4906  
14              
15 61     61   497 use namespace::clean;
  61         139  
  61         321  
16              
17 61     61   14277 use Exporter qw(import);
  61         153  
  61         35379  
18              
19             my @defs = ();
20              
21             push @defs, {
22             name => 'ApiKey',
23             test => sub {
24             my $value = shift;
25              
26             return if not defined $value;
27             return if length $value != 30;
28              
29             ## no critic (RegularExpressions::RequireExtendedFormatting)
30             $value =~ m/[sp](?:test|prod)_\w+/sm;
31             ## use critic
32             },
33             message => error_message('%s is not a valid API key.'),
34             };
35              
36             push @defs, {
37             name => 'PublicLiveApiKey',
38             subtype_of => 'ApiKey',
39             from => __PACKAGE__,
40             test => sub { $_[0] =~ m/^pprod_\w+/sm },
41             message => error_message('%s is not a valid public API key for live mode.'),
42             };
43              
44             push @defs, {
45             name => 'PublicTestApiKey',
46             subtype_of => 'ApiKey',
47             from => __PACKAGE__,
48             test => sub { $_[0] =~ m/^ptest_\w+/sm },
49             message => error_message('%s is not a valid public API key for test mode.'),
50             };
51              
52             push @defs, {
53             name => 'SecretLiveApiKey',
54             subtype_of => 'ApiKey',
55             from => __PACKAGE__,
56             test => sub { $_[0] =~ m/^sprod_\w+/sm },
57             message => error_message('%s is not a valid secret API key for live mode.'),
58             };
59              
60             push @defs, {
61             name => 'SecretTestApiKey',
62             subtype_of => 'ApiKey',
63             from => __PACKAGE__,
64             test => sub { $_[0] =~ m/^stest_\w+/sm },
65             message => error_message('%s is not a valid secret API key for test mode.'),
66             };
67              
68             Stancer::Core::Types::Helper::register_types(\@defs, __PACKAGE__);
69              
70             1;
71              
72             __END__
73              
74             =pod
75              
76             =encoding UTF-8
77              
78             =head1 NAME
79              
80             Stancer::Core::Types::ApiKeys - Internal ApiKeys types
81              
82             =head1 VERSION
83              
84             version 1.0.3
85              
86             =head1 USAGE
87              
88             =head2 Logging
89              
90              
91              
92             We use the L<Log::Any> framework for logging events.
93             You may tell where it should log using any available L<Log::Any::Adapter> module.
94              
95             For example, to log everything to a file you just have to add a line to your script, like this:
96             #! /usr/bin/env perl
97             use Log::Any::Adapter (File => '/var/log/payment.log');
98             use Stancer::Core::Types::ApiKeys;
99              
100             You must import C<Log::Any::Adapter> before our libraries, to initialize the logger instance before use.
101              
102             You can choose your log level on import directly:
103             use Log::Any::Adapter (File => '/var/log/payment.log', log_level => 'info');
104              
105             Read the L<Log::Any> documentation to know what other options you have.
106              
107             =cut
108              
109             =head1 SECURITY
110              
111             =over
112              
113             =item *
114              
115             Never, never, NEVER register a card or a bank account number in your database.
116              
117             =item *
118              
119             Always uses HTTPS in card/SEPA in communication.
120              
121             =item *
122              
123             Our API will never give you a complete card/SEPA number, only the last four digits.
124             If you need to keep track, use these last four digit.
125              
126             =back
127              
128             =cut
129              
130             =head1 BUGS
131              
132             Please report any bugs or feature requests on the bugtracker website
133             L<https://gitlab.com/wearestancer/library/lib-perl/-/issues> or by email to
134             L<bug-stancer@rt.cpan.org|mailto:bug-stancer@rt.cpan.org>.
135              
136             When submitting a bug or request, please include a test-file or a
137             patch to an existing test-file that illustrates the bug or desired
138             feature.
139              
140             =head1 AUTHOR
141              
142             Joel Da Silva <jdasilva@cpan.org>
143              
144             =head1 COPYRIGHT AND LICENSE
145              
146             This software is Copyright (c) 2018-2024 by Stancer / Iliad78.
147              
148             This is free software, licensed under:
149              
150             The Artistic License 2.0 (GPL Compatible)
151              
152             =cut