File: API.pl

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 (55 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download | duplicates (4)
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

=pod

The tester must supply their own PayPal sandbox seller authentication
(either using certificates or 3-token auth), as well as the buyer
sandbox account (email address).

Should we set env variables, prompt for them, or have them in a conf
file? Prompt for them, but we should allow for an input file as an env
variable:

  WPP_TEST=auth.txt prove -lvr t

=cut

sub do_args {
    unless ( $ENV{WPP_TEST} && -f $ENV{WPP_TEST} ) {
        die
            "See the TESTING section in `perldoc Business::PayPal::API documentation`\n";
        exit;
    }

    my %args = ();
    open FILE, "<", $ENV{WPP_TEST}
        or die "Could not open $ENV{WPP_TEST}: $!\n";

    my @variables = qw( Username Password Signature Subject timeout
        CertFile KeyFile PKCS12File PKCS12Password
        BuyerEmail SellerEmail
    );

    my %patterns = ();
    @patterns{ map { qr/^$_\b/i } @variables } = @variables;

    while (<FILE>) {
        chomp;

    MATCH: for my $pat ( keys %patterns ) {
            next unless $_ =~ $pat;
            ( my $value = $_ ) =~ s/$pat\s*=\s*(.+)/$1/;
            $args{ $patterns{$pat} } = $value;
            delete $patterns{$pat};
            last MATCH;
        }
    }

    close FILE;

    ## leave this!
    $args{sandbox} = 1;

    return %args;
}

1;