]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/payment_test.pl
Patch from Joe Atzberger and Lebbeous Fogle-Weekley:
[Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / payment_test.pl
1 #!/usr/bin/perl
2
3 #----------------------------------------------------------------
4 # Simple example
5 #----------------------------------------------------------------
6
7 require '../oils_header.pl';
8 use strict; use warnings;
9
10 use Getopt::Long;
11
12 sub usage {
13     return <<END_OF_USAGE;
14 $0 [-h] --login=UserName --password==MyPass [OPTIONS] [Transaction data]
15
16 Required Arguments:
17     -l --login      Assigned by your processor API (specified in -t)
18     -p --password   Assigned by your processor API (specified in -t)
19
20 Options:
21     -t --target       Payment processor (default PayPal)
22     -s --signature    A "long password" required by PayPal in leiu of certificates
23     -r --server       Use a specific server with a processor (AuthorizeNet)
24     -c --config_file  opensrf_core.xml file (default /openils/conf/opensrf_core.xml)
25
26 Transaction data:
27     -a --amount    Monetary value, no dollar sign, default a random value under 25.00
28     -i --id        Patron ID#, default 5 (for no reason)
29     -n --number    Credit card number to be charged
30     -x --expires   Date (MM-YYYY) of card expiration, default 12-2014
31
32 Example:
33
34 $0  --login=seller_1254418209_biz_api1.esilibrary.com \\
35     --password=1254618222 \\
36     --signature=AiPC9xjkCyDFQXbSkoZcgqH3hpacAVPVw5GcZgNKVA9SGKcbrqLuhLks \\
37     --amount=32.75 \\
38     --id=13042
39
40 END_OF_USAGE
41 }
42
43 ### DEFAULTS
44 my $config    = '/openils/conf/opensrf_core.xml';
45 my $processor = 'PayPal';
46 my $number    = '4123000011112228';
47 my $expires   = '12-2014';
48 my $id        = 5;
49
50 ### Empties
51 my ($login, $password, $signature, $help, $amount, $server);
52
53 GetOptions(
54     'config_file=s' => \$config,
55     'target=s'      => \$processor,
56     'login=s'       => \$login,
57     'password=s'    => \$password,
58     's|signature=s' => \$signature,
59     'amount=f'      => \$amount,
60     'id=i'          => \$id,
61     'number=s'      => \$number,
62     'x|expires=s'   => \$expires,
63     'r|server=s'    => \$server,
64     'help|?'        => \$help,
65 );
66
67 $help and print usage and exit;
68
69 unless ($login and $processor and $password) {
70     print usage;
71     exit;
72 }
73 osrf_connect($config);
74
75 $amount or $amount = int(rand(25)) . '.' . sprintf("%02d", int(rand(99)));
76
77 print <<END_OF_DUMP;
78 Attempting transaction:
79 \{
80     processor => $processor,
81         login => $login,
82      password => $password,
83     signature => $signature,
84        amount => $amount,
85            cc => $number,
86    expiration => $expires,
87        server => $server,
88      testmode => 1,
89     patron_id => $id,
90       country => US,
91   description => test transaction processid $$
92 \}
93
94 END_OF_DUMP
95
96 my( $user, $evt ) = simplereq('open-ils.credit', 'open-ils.credit.process', 
97 {
98     processor => $processor,
99         login => $login,
100      password => $password,
101     signature => $signature,
102        amount => $amount,
103            cc => $number,
104    expiration => $expires,
105        server => $server,
106      testmode => 1,
107     patron_id => $id,
108       country => "US",
109   description => "test transaction processid $$"
110 }
111 );
112 oils_event_die($evt); # this user was not found / not all methods return events..
113 print debug($user);
114