File Coverage

blib/lib/WebService/PayPal/PaymentsAdvanced/Mocker/Helper.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition 1 2 50.0
subroutine 16 16 100.0
pod 9 9 100.0
total 61 62 98.3


line stmt bran cond sub pod time code
1             package WebService::PayPal::PaymentsAdvanced::Mocker::Helper;
2              
3 7     7   74 use Moo;
  7         18  
  7         73  
4              
5 7     7   2651 use namespace::autoclean;
  7         28  
  7         56  
6              
7             our $VERSION = '0.000027';
8              
9 7     7   2225 use Data::GUID;
  7         52920  
  7         72  
10 7     7   5316 use DateTime;
  7         1825251  
  7         276  
11 7     7   2652 use DateTime::Format::MySQL;
  7         298620  
  7         238  
12 7     7   162 use DateTime::TimeZone;
  7         19  
  7         134  
13 7     7   115 use Types::Standard qw( InstanceOf );
  7         23  
  7         133  
14              
15             has _time_zone => (
16             is => 'lazy',
17             isa => InstanceOf ['DateTime::TimeZone'],
18             default =>
19             sub { DateTime::TimeZone->new( name => 'America/Los_Angeles' ) },
20             );
21              
22             sub baid {
23 4     4 1 30 my $self = shift;
24 4         126 return 'B-' . $self->unique_id(17);
25             }
26              
27             sub correlationid {
28 26     26 1 193 return lc shift->unique_id(13);
29             }
30              
31             sub pnref {
32 27     27 1 512 return shift->unique_id(12);
33             }
34              
35             sub ppref {
36 26     26 1 427 return shift->unique_id(17);
37             }
38              
39             sub secure_token {
40 17     17 1 1745 return shift->unique_id(25);
41             }
42              
43             sub token {
44 2     2 1 23 return 'EC-' . shift->unique_id(17);
45             }
46              
47             sub transtime {
48 28     28 1 867 return DateTime::Format::MySQL->format_datetime( shift->datetime_now );
49             }
50              
51             sub unique_id {
52 102     102 1 185 my $self = shift;
53 102   50     248 my $length = shift || die 'length param required';
54              
55 102         367 my $id = Data::GUID->new->as_string;
56 102         4794 $id =~ s{-}{}g;
57 102         502 return substr( $id, 0, $length );
58             }
59              
60             sub datetime_now {
61 28     28 1 535 return DateTime->now( time_zone => shift->_time_zone );
62             }
63              
64             1;
65              
66             =pod
67              
68             =encoding UTF-8
69              
70             =head1 NAME
71              
72             WebService::PayPal::PaymentsAdvanced::Mocker::Helper - Helper methods used when mocking PayPal web services
73              
74             =head1 VERSION
75              
76             version 0.000027
77              
78             =head1 SYNOPSIS
79              
80             use WebService::PayPal::PaymentsAdvanced::Mocker::Helper;
81             my $helper = WebService::PayPal::PaymentsAdvanced::Mocker::Helper->new;
82              
83             print $helper->transtime;
84              
85             =head2 baid
86              
87             Returns a new, unique BAID
88              
89             =head2 correlationid
90              
91             Returns a new, unique CORRELATIONID
92              
93             =head2 pnref
94              
95             Returns a new, unique PNREF
96              
97             =head2 ppref
98              
99             Returns a new, unique PPREF
100              
101             =head2 secure_token
102              
103             Returns a new, unique SECURETOKEN
104              
105             =head2 token
106              
107             Returns a new, unique SECURETOKENID
108              
109             =head2 transtime
110              
111             Returns a TRANSTIME based on the current time
112              
113             =head2 unique_id( $length )
114              
115             A generic method for creating unique ids.
116              
117             =head2 datetime_now
118              
119             Returns a new DateTime object with the current time, using the same time zone
120             which the PayPal services use.
121              
122             =head1 DESCRIPTION
123              
124             Helper methods used when mocking PayPal web
125              
126             =head1 SUPPORT
127              
128             Bugs may be submitted through L<https://github.com/maxmind/webservice-paypal-paymentsadvanced/issues>.
129              
130             =head1 AUTHOR
131              
132             Olaf Alders <olaf@wundercounter.com>
133              
134             =head1 COPYRIGHT AND LICENSE
135              
136             This software is copyright (c) 2021 by MaxMind, Inc.
137              
138             This is free software; you can redistribute it and/or modify it under
139             the same terms as the Perl 5 programming language system itself.
140              
141             =cut
142              
143             __END__
144              
145             # ABSTRACT: Helper methods used when mocking PayPal web services
146