| 1 | package Business::OnlinePayment::Mock; | ||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 4 | ▶ | use Business::OnlinePayment; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 4 | ▶ | use Business::OnlinePayment::HTTPS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 4 | ▶ | use parent qw(Business::OnlinePayment::HTTPS); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 4 | our $me = 'Business::OnlinePayment::Mock'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 4 | our $VERSION = '0.008'; # VERSION | |||||||||||||||||||
| 13 | # PODNAME: Business::OnlinePayment::Mock | ||||||||||||||||||||
| 14 | # ABSTRACT: A backend for mocking fake results for test cards | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 4 | our $mock_responses; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | our $default_mock = { | ||||||||||||||||||||
| 19 | error_message => 'Declined', | ||||||||||||||||||||
| 20 | is_success => 0, | ||||||||||||||||||||
| 21 | error_code => 100, | ||||||||||||||||||||
| 22 | 1 | ▶ | order_number => sub { time }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 4 | }; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | our $default_approved_mock = { | ||||||||||||||||||||
| 26 | error_message => 'Approved', | ||||||||||||||||||||
| 27 | is_success => 1, | ||||||||||||||||||||
| 28 | error_code => 0, | ||||||||||||||||||||
| 29 | 0 | ▶ | order_number => sub { time }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 30 | 4 | }; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 4 | ▶ | sub _info { | ||||||||||||||||||
|
Subroutine
_info: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | return { | ||||||||||||||||||||
| 34 | 4 | info_compat => '0.01', | |||||||||||||||||||
| 35 | gateway_name => 'Mock', | ||||||||||||||||||||
| 36 | gateway_url => 'http://www.example.com', | ||||||||||||||||||||
| 37 | module_version => $VERSION, | ||||||||||||||||||||
| 38 | supported_types => ['CC'], | ||||||||||||||||||||
| 39 | supported_actions => { | ||||||||||||||||||||
| 40 | CC => [ | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | # 'Tokenize', # TODO | ||||||||||||||||||||
| 43 | 'Normal Authorization', | ||||||||||||||||||||
| 44 | 'Post Authorization', | ||||||||||||||||||||
| 45 | 'Authorization Only', | ||||||||||||||||||||
| 46 | 'Credit', | ||||||||||||||||||||
| 47 | 'Void', | ||||||||||||||||||||
| 48 | 'Auth Reversal', | ||||||||||||||||||||
| 49 | 'PreAuth', | ||||||||||||||||||||
| 50 | 'Mark Token Used', # very few bop modules use this | ||||||||||||||||||||
| 51 | ], | ||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 1 | ▶ | sub set_default_mock { | ||||||||||||||||||
|
Subroutine
set_default_mock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 58 | 1 | my ($self, $default) = @_; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 1 | $default_mock = $default; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 3 | ▶ | sub set_mock_response { | ||||||||||||||||||
|
Subroutine
set_mock_response: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 65 | 3 | my ($self, $response, $set_as_default) = @_; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 3 | $mock_responses->{ delete $response->{'action'} }->{ delete $response->{'card_number'} } = $response; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 3 | ▶ | $self->set_as_default($response) if $set_as_default; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | ▶ | sub test_transaction { | ||||||||||||||||||
|
Subroutine
test_transaction: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | $self->{'test_transaction'} = 1; | |||||||||||||||||||
| 77 | 0 | $self->server('example.com'); | |||||||||||||||||||
| 78 | 0 | $self->port(443); | |||||||||||||||||||
| 79 | 0 | $self->path('/example.html'); | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | return $self->{'test_transaction'}; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 5 | ▶ | sub submit { | ||||||||||||||||||
|
Subroutine
submit: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||
| 86 | 5 | my $self = shift; | |||||||||||||||||||
| 87 | 5 | my %content = $self->content(); | |||||||||||||||||||
| 88 | 5 | ▶ | die 'Missing action' unless $content{'action'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 4 | my $action; | |||||||||||||||||||
| 91 | 4 | foreach my $a (@{ $self->_info()->{'supported_actions'}->{'CC'} }) { | |||||||||||||||||||
| 92 | 23 | ▶ | if (lc $a eq lc $content{'action'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 3 | $action = $a; | |||||||||||||||||||
| 94 | 3 | last; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | 4 | ▶ | die 'Unsupported action' unless $action; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 3 | ▶ | local $default_mock = $default_approved_mock if $action eq 'Mark Token Used'; # these always approve | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 3 | ▶ | my $result = { %{ $mock_responses->{$action}->{ $content{'card_number'} } || $default_mock } }; # cheap clone | ||||||||||||||||||
|
Condition66%2/3
$Business::OnlinePayment::Mock::mock_responses->{$action}{$content{'card_number'}} || $Business::OnlinePayment::Mock::default_mock
MC/DC0%0/2
$Business::OnlinePayment::Mock::mock_responses->{$action}{$content{'card_number'}} || $Business::OnlinePayment::Mock::default_mock
$Business::OnlinePayment::Mock::mock_responses->{$action}{$content{'card_number'}}
$Business::OnlinePayment::Mock::default_mock
Truth table66%2/3
A || B
A= $Business::OnlinePayment::Mock::mock_responses->{$action}{$content{'card_number'}}B= $Business::OnlinePayment::Mock::default_mock
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 3 | foreach my $k (keys %{$result}) { | |||||||||||||||||||
| 103 | 12 | my $val = $result->{$k}; | |||||||||||||||||||
| 104 | 12 | ▶ | $result->{$k} = ref $val eq 'CODE' ? $val->(\%content) : $val; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | 12 | ▶ | $self->$k($result->{$k}) if $self->can($k); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 3 | return $result; | |||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 4 | 1; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||