| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Stancer::Role::Payment::Page; |
|
2
|
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
233092
|
use 5.020; |
|
|
14
|
|
|
|
|
62
|
|
|
4
|
14
|
|
|
14
|
|
89
|
use strict; |
|
|
14
|
|
|
|
|
32
|
|
|
|
14
|
|
|
|
|
403
|
|
|
5
|
14
|
|
|
14
|
|
94
|
use warnings; |
|
|
14
|
|
|
|
|
29
|
|
|
|
14
|
|
|
|
|
1293
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Payment page relative role |
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.3'; # VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
14
|
|
|
14
|
|
562
|
use Stancer::Core::Types qw(Maybe Url); |
|
|
14
|
|
|
|
|
39
|
|
|
|
14
|
|
|
|
|
1332
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
14
|
|
|
14
|
|
744
|
use Stancer::Config; |
|
|
14
|
|
|
|
|
36
|
|
|
|
14
|
|
|
|
|
493
|
|
|
13
|
14
|
|
|
14
|
|
7934
|
use Stancer::Exceptions::MissingReturnUrl; |
|
|
14
|
|
|
|
|
109
|
|
|
|
14
|
|
|
|
|
651
|
|
|
14
|
14
|
|
|
14
|
|
7633
|
use Stancer::Exceptions::MissingPaymentId; |
|
|
14
|
|
|
|
|
67
|
|
|
|
14
|
|
|
|
|
633
|
|
|
15
|
14
|
|
|
14
|
|
143
|
use Stancer::Exceptions::MissingApiKey; |
|
|
14
|
|
|
|
|
33
|
|
|
|
14
|
|
|
|
|
465
|
|
|
16
|
14
|
|
|
14
|
|
91
|
use Try::Tiny; |
|
|
14
|
|
|
|
|
31
|
|
|
|
14
|
|
|
|
|
1183
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
14
|
|
|
14
|
|
101
|
use Moo::Role; |
|
|
14
|
|
|
|
|
33
|
|
|
|
14
|
|
|
|
|
121
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
requires qw(_add_modified _attribute_builder id); |
|
21
|
|
|
|
|
|
|
|
|
22
|
14
|
|
|
14
|
|
10331
|
use namespace::clean; |
|
|
14
|
|
|
|
|
44
|
|
|
|
14
|
|
|
|
|
84
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has return_url => ( |
|
26
|
|
|
|
|
|
|
is => 'rw', |
|
27
|
|
|
|
|
|
|
isa => Maybe[Url], |
|
28
|
5
|
|
|
5
|
|
319
|
builder => sub { $_[0]->_attribute_builder('return_url') }, |
|
29
|
|
|
|
|
|
|
lazy => 1, |
|
30
|
|
|
|
|
|
|
predicate => 1, |
|
31
|
|
|
|
|
|
|
trigger => sub { $_[0]->_add_modified('return_url') }, |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub payment_page_url { |
|
36
|
6
|
|
|
6
|
1
|
16610
|
my ($this, @args) = @_; |
|
37
|
6
|
|
|
|
|
18
|
my $data; |
|
38
|
|
|
|
|
|
|
|
|
39
|
6
|
100
|
|
|
|
33
|
if (scalar @args == 1) { |
|
40
|
1
|
|
|
|
|
4
|
$data = $args[0]; |
|
41
|
|
|
|
|
|
|
} else { |
|
42
|
5
|
|
|
|
|
21
|
$data = {@args}; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
6
|
|
|
|
|
88
|
my $config = Stancer::Config->init(); |
|
46
|
|
|
|
|
|
|
|
|
47
|
6
|
100
|
|
|
|
438
|
if (not defined $this->return_url) { |
|
48
|
1
|
|
|
|
|
67
|
my $message = 'You must provide a return URL before going to the payment page.'; |
|
49
|
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
118
|
Stancer::Exceptions::MissingReturnUrl->throw(message => $message); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
5
|
100
|
|
|
|
100
|
if (not defined $this->id) { |
|
54
|
1
|
|
|
|
|
8
|
my $message = 'A payment ID is mandatory to obtain a payment page URL. Maybe you forgot to send the payment.'; |
|
55
|
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
26
|
Stancer::Exceptions::MissingPaymentId->throw(message => $message); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
23
|
my $pattern = 'https://%s/%s/%s'; |
|
60
|
4
|
|
|
|
|
120
|
my $host = $config->host; |
|
61
|
4
|
|
|
|
|
36
|
my $url; |
|
62
|
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
27
|
$host =~ s/api/payment/sm; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
try { |
|
66
|
4
|
|
|
4
|
|
257
|
$url = sprintf $pattern, $host, $config->public_key, $this->id; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
catch { |
|
69
|
1
|
|
|
1
|
|
2728
|
my $message = 'A public API key is needed to obtain a payment page URL.'; |
|
70
|
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
12
|
Stancer::Exceptions::MissingApiKey->throw(message => $message); |
|
72
|
4
|
|
|
|
|
74
|
}; |
|
73
|
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
104
|
my @params = (); |
|
75
|
|
|
|
|
|
|
|
|
76
|
3
|
100
|
|
|
|
23
|
push @params, 'lang=' . $data->{'lang'} if defined $data->{'lang'}; |
|
77
|
|
|
|
|
|
|
|
|
78
|
3
|
100
|
|
|
|
16
|
if (scalar @params) { |
|
79
|
2
|
|
|
|
|
19
|
$url .= q/?/ . join q/&/, @params; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
29
|
return $url; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=pod |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=encoding UTF-8 |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 NAME |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Stancer::Role::Payment::Page - Payment page relative role |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 VERSION |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
version 1.0.3 |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 C<return_url> |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Read/Write string. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
URL used to return to your store when using the payment page. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 METHODS |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 C<< $payment->payment_page_url() >> |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 C<< $payment->payment_page_url( I<%params> ) >> |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 C<< $payment->payment_page_url( I<\%params> ) >> |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
External URL for Stancer payment page. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Maybe used as an iframe or a redirection page if you needed it. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
C<%terms> must be an hash or a reference to an hash (C<\%terms>) with at least one of the following key : |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=over |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item C<lang> |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
To force the language of the page. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The page uses browser language as default language. |
|
130
|
|
|
|
|
|
|
If no language available matches the asked one, the page will be shown in english. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 USAGE |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 Logging |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
We use the L<Log::Any> framework for logging events. |
|
141
|
|
|
|
|
|
|
You may tell where it should log using any available L<Log::Any::Adapter> module. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
For example, to log everything to a file you just have to add a line to your script, like this: |
|
144
|
|
|
|
|
|
|
#! /usr/bin/env perl |
|
145
|
|
|
|
|
|
|
use Log::Any::Adapter (File => '/var/log/payment.log'); |
|
146
|
|
|
|
|
|
|
use Stancer::Role::Payment::Page; |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
You must import C<Log::Any::Adapter> before our libraries, to initialize the logger instance before use. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
You can choose your log level on import directly: |
|
151
|
|
|
|
|
|
|
use Log::Any::Adapter (File => '/var/log/payment.log', log_level => 'info'); |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Read the L<Log::Any> documentation to know what other options you have. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SECURITY |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=over |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Never, never, NEVER register a card or a bank account number in your database. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Always uses HTTPS in card/SEPA in communication. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Our API will never give you a complete card/SEPA number, only the last four digits. |
|
172
|
|
|
|
|
|
|
If you need to keep track, use these last four digit. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 BUGS |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website |
|
181
|
|
|
|
|
|
|
L<https://gitlab.com/wearestancer/library/lib-perl/-/issues> or by email to |
|
182
|
|
|
|
|
|
|
L<bug-stancer@rt.cpan.org|mailto:bug-stancer@rt.cpan.org>. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
|
185
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
|
186
|
|
|
|
|
|
|
feature. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHOR |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Joel Da Silva <jdasilva@cpan.org> |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This software is Copyright (c) 2018-2024 by Stancer / Iliad78. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This is free software, licensed under: |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |