File: TransactionSearcher.pm

package info (click to toggle)
libbusiness-paypal-api-perl 0.77-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 488 kB
  • sloc: perl: 2,503; makefile: 9
file content (76 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package Example::TransactionSearcher;

use Moo;
use MooX::Options;

use feature qw( say );

use Business::PayPal::API::TransactionSearch;
use DateTime;
use Data::Printer;
use String::CamelCase qw( camelize );

# search options
option amount => (
    is       => 'ro',
    format   => 's',
    required => 0,
    doc      => 'payment amount',
);

option end_date => (
    is       => 'ro',
    format   => 's',
    required => 0,
    doc      => 'end date for search. eg 2005-12-22T08:51:28Z',
);

option start_date => (
    is       => 'ro',
    format   => 's',
    required => 0,
    lazy     => 1,
    doc      => 'start date for search. eg 2005-12-22T08:51:28Z',
    default => sub { DateTime->now->truncate( to => 'day' )->datetime . 'Z' },
);

option payer => (
    is       => 'ro',
    format   => 's',
    required => 0,
    doc      => 'payer email address',
);

option transaction_id => (
    is       => 'ro',
    format   => 's',
    required => 0,
    doc      => 'transaction id',
);

with 'Example::Role::Auth';

sub search {
    my $self = shift;

    my @terms = ( 'amount', 'end_date', 'payer', 'start_date', );

    my %search_terms
        = map { camelize($_) => $self->$_ } grep { $self->$_ } @terms;
    $search_terms{TransactionID} = $self->transaction_id
        if $self->transaction_id;

    say 'Search terms: ';
    p %search_terms;

    my @response = $self->_client->TransactionSearch(%search_terms);
    unless ( ref $response[0] ) {
        my %error = @response;
        p %error;
        die;
    }

    return $response[0];
}

1;