line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::Payment::Processor::Test::Random; |
2
|
2
|
|
|
2
|
|
2016
|
use Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
with 'Business::Payment::Processor'; |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
8805
|
use Business::Payment::Result; |
|
2
|
|
|
|
|
274
|
|
|
2
|
|
|
|
|
251
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
0
|
5
|
sub request { return ( 'OK', 'OK' ); } |
9
|
1
|
|
|
1
|
0
|
3
|
sub prepare_data { return {} }; |
10
|
|
|
|
|
|
|
sub prepare_result { |
11
|
1
|
|
|
1
|
0
|
2
|
my ($self, $page, $response) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
7
|
srand(time); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
6
|
my $success = int(rand(1)); |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
2
|
my $result; |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
3
|
if($success) { |
20
|
0
|
|
|
|
|
0
|
$result = Business::Payment::Result->new( |
21
|
|
|
|
|
|
|
success => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
} else { |
24
|
1
|
|
|
|
|
31
|
$result = Business::Payment::Result->new( |
25
|
|
|
|
|
|
|
success => 0, |
26
|
|
|
|
|
|
|
error_code => -1, |
27
|
|
|
|
|
|
|
error_message => 'Failed on purpose!' |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
4
|
return $result; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
2
|
|
12
|
no Moose; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
35
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Business::Payment::Processor::Test::Random - Test Processor |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use Business::Payment; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $bp = Business::Payment->new( |
46
|
|
|
|
|
|
|
processor => Business::Payment::Processor::Test::Random->new |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $charge = Business::Payment::Charge->new( |
50
|
|
|
|
|
|
|
amount => 10.00 # Something Math::Currency can parse |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $result = $bp->handle($charge); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $result = $bp->handle($charge); |
56
|
|
|
|
|
|
|
if($result->success) { |
57
|
|
|
|
|
|
|
print "Success!\n"; |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
print "Failed: ".$result->error_code.": ".$result->error_message."\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 DESCRIPTION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Business::Payment::Processor::Test::Random is test processor that randomly |
65
|
|
|
|
|
|
|
decides if a charge succeeds or fails. This is useful for testing. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 AUTHOR |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Cory G Watson, C<< <gphat@cpan.org> >> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Copyright 2009 Cold Hard Code, LLC, all rights reserved. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
76
|
|
|
|
|
|
|
under the same terms as Perl itself. |