File Coverage

blib/lib/Stancer/Dispute.pm
Criterion Covered Total %
statement 31 31 100.0
branch n/a
condition n/a
subroutine 13 13 100.0
pod 1 1 100.0
total 45 45 100.0


line stmt bran cond sub pod time code
1             package Stancer::Dispute;
2              
3 13     13   1080332 use 5.020;
  13         55  
4 13     13   89 use strict;
  13         28  
  13         451  
5 13     13   87 use warnings;
  13         30  
  13         1286  
6              
7             # ABSTRACT: Dispute representation
8             our $VERSION = '1.0.3'; # VERSION
9              
10 13     13   2432 use Stancer::Core::Types qw(coerce_instance Maybe OrderId PaymentInstance Varchar);
  13         39  
  13         1739  
11              
12 13     13   6892 use Stancer::Core::Iterator::Dispute;
  13         87  
  13         627  
13 13     13   3223 use Stancer::Payment;
  13         51  
  13         591  
14 13     13   101 use Scalar::Util qw(blessed);
  13         27  
  13         915  
15              
16 13     13   81 use Moo;
  13         28  
  13         75  
17              
18             extends 'Stancer::Core::Object';
19             with qw(
20             Stancer::Role::Amount::Read
21             );
22              
23 13     13   11401 use namespace::clean;
  13         46  
  13         107  
24              
25             has '+endpoint' => (
26             default => 'disputes',
27             );
28              
29              
30             has order_id => (
31             is => 'rwp',
32             isa => Maybe[OrderId],
33 7     7   188 builder => sub { $_[0]->_attribute_builder('order_id') },
34             lazy => 1,
35             predicate => 1,
36             trigger => sub { $_[0]->_add_modified('order_id') },
37             );
38              
39              
40             has payment => (
41             is => 'rwp',
42             isa => Maybe[PaymentInstance],
43 7     7   327 builder => sub { $_[0]->_attribute_builder('payment') },
44             coerce => coerce_instance('Stancer::Payment'),
45             lazy => 1,
46             predicate => 1,
47             trigger => sub { $_[0]->_add_modified('payment') },
48             );
49              
50              
51             has response => (
52             is => 'rwp',
53             isa => Maybe[Varchar[2, 4]],
54 7     7   184 builder => sub { $_[0]->_attribute_builder('response') },
55             lazy => 1,
56             predicate => 1,
57             );
58              
59              
60             sub list {
61 27     27 1 152662 my ($class, @args) = @_;
62              
63 27         272 return Stancer::Core::Iterator::Dispute->search(@args);
64             }
65              
66             1;
67              
68             __END__
69              
70             =pod
71              
72             =encoding UTF-8
73              
74             =head1 NAME
75              
76             Stancer::Dispute - Dispute representation
77              
78             =head1 VERSION
79              
80             version 1.0.3
81              
82             =head1 ATTRIBUTES
83              
84             =head2 C<amount>
85              
86             Read-only integer.
87              
88             Dispute amount.
89              
90             =head2 C<currency>
91              
92             Read-only string.
93              
94             Dispute currency.
95              
96             =head2 C<order_id>
97              
98             Read-only string.
99              
100             External order id.
101              
102             =head2 C<payment>
103              
104             Read-only instance of C<Stancer::Payment>.
105              
106             Related payment object.
107              
108             =head2 C<response>
109              
110             Read-only 2 or 4 characters string.
111              
112             API response code.
113              
114             =head1 METHODS
115              
116             =head2 C<< Stancer::Dispute->new() : I<self> >>
117              
118             =head2 C<< Stancer::Dispute->new(I<$token>) : I<self> >>
119              
120             =head2 C<< Stancer::Dispute->new(I<%args>) : I<self> >>
121              
122             =head2 C<< Stancer::Dispute->new(I<\%args>) : I<self> >>
123              
124             This method accept an optional string, it will be used as an entity ID for API calls.
125              
126             # Get an empty new payment
127             my $new = Stancer::Dispute->new();
128              
129             # Get an existing payment
130             my $exist = Stancer::Dispute->new($token);
131              
132             =head2 C<< Dispute->list(I<%terms>) : I<DisputeIterator> >>
133              
134             =head2 C<< Dispute->list(I<\%terms>) : I<DisputeIterator> >>
135              
136             List all disputes.
137              
138             C<%terms> must be an hash or a reference to an hash (C<\%terms>) with at least one of the following key :
139              
140             =over
141              
142             =item C<created>
143              
144             Must be an unix timestamp, a C<DateTime> or a C<DateTime::Span> object which will filter payments
145             created after this value.
146             If a C<DateTime::Span> is passed, C<created_until> will be ignored and replaced with C<< DateTime::Span->end >>.
147              
148             =item C<created_until>
149              
150             Must be an unix timestamp or a C<DateTime> object which will filter payments created before this value.
151             If a C<DateTime::Span> is passed to C<created>, this value will be ignored.
152              
153             =item C<limit>
154              
155             Must be an integer between 1 and 100 and will limit the number of objects to be returned.
156             API defaults is to return 10 elements.
157              
158             =item C<start>
159              
160             Must be an integer and will be used as a pagination cursor, starts at 0.
161              
162             =back
163              
164             =head1 USAGE
165              
166             =head2 Logging
167              
168              
169              
170             We use the L<Log::Any> framework for logging events.
171             You may tell where it should log using any available L<Log::Any::Adapter> module.
172              
173             For example, to log everything to a file you just have to add a line to your script, like this:
174             #! /usr/bin/env perl
175             use Log::Any::Adapter (File => '/var/log/payment.log');
176             use Stancer::Dispute;
177              
178             You must import C<Log::Any::Adapter> before our libraries, to initialize the logger instance before use.
179              
180             You can choose your log level on import directly:
181             use Log::Any::Adapter (File => '/var/log/payment.log', log_level => 'info');
182              
183             Read the L<Log::Any> documentation to know what other options you have.
184              
185             =cut
186              
187             =head1 SECURITY
188              
189             =over
190              
191             =item *
192              
193             Never, never, NEVER register a card or a bank account number in your database.
194              
195             =item *
196              
197             Always uses HTTPS in card/SEPA in communication.
198              
199             =item *
200              
201             Our API will never give you a complete card/SEPA number, only the last four digits.
202             If you need to keep track, use these last four digit.
203              
204             =back
205              
206             =cut
207              
208             =head1 BUGS
209              
210             Please report any bugs or feature requests on the bugtracker website
211             L<https://gitlab.com/wearestancer/library/lib-perl/-/issues> or by email to
212             L<bug-stancer@rt.cpan.org|mailto:bug-stancer@rt.cpan.org>.
213              
214             When submitting a bug or request, please include a test-file or a
215             patch to an existing test-file that illustrates the bug or desired
216             feature.
217              
218             =head1 AUTHOR
219              
220             Joel Da Silva <jdasilva@cpan.org>
221              
222             =head1 COPYRIGHT AND LICENSE
223              
224             This software is Copyright (c) 2018-2024 by Stancer / Iliad78.
225              
226             This is free software, licensed under:
227              
228             The Artistic License 2.0 (GPL Compatible)
229              
230             =cut