Skip to content

Commit

Permalink
Merge pull request #5 from SysPete/master
Browse files Browse the repository at this point in the history
Add useful methods on payment failure.
  • Loading branch information
racke committed Apr 29, 2014
2 parents dac8ac1 + 240085f commit 8542a4f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -15,7 +15,7 @@ WriteMakefile(
PREREQ_PM => {
'Test::More' => 0,
'Business::OnlinePayment' => 3.01,
'Net::Braintree' => 0.017,
'Net::Braintree' => 0.20,
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Business-OnlinePayment-Braintree-*' },
Expand Down
35 changes: 30 additions & 5 deletions lib/Business/OnlinePayment/Braintree.pm
Expand Up @@ -68,7 +68,7 @@ sub submit {
my $self = shift;
my $config = Net::Braintree->configuration;
my %content = $self->content;
my ($action, $result);
my ($action, $result, $transaction, $result_code);

# sandbox vs production
if ($self->test_transaction) {
Expand All @@ -95,14 +95,38 @@ sub submit {
return 0;
}

my %result_codes = (
2000 => 'declined',
2001 => 'nsf',
2002 => 'nsf',
2003 => 'nsf',
2010 => 'declined',
2012 => 'declined',
2013 => 'declined',
2014 => 'declined',
2022 => 'declined',
2038 => 'declined',
2041 => 'declined',
2044 => 'declined',
2046 => 'declined',
2047 => 'pickup',
2053 => 'stolen',
);

$transaction = $result->transaction;
$result_code = $transaction->processor_response_code;

$self->result_code($result_code);
$self->order_number($transaction->id);

if ($result->is_success()) {
$self->is_success(1);
$self->authorization($result->transaction->id);
$self->order_number($result->transaction->id);
$self->authorization($transaction->id);
}
else {
$self->is_success(0);
$self->error_message($result->message);
$self->is_success(0);
$self->error_message($result->message);
$self->failure_status($result_codes{$result_code}) if $result_codes{$result_code};
}
}

Expand All @@ -128,6 +152,7 @@ sub sale {
number => $content{card_number},
expiration_month => substr($content{expiration},0,2),
expiration_year => substr($content{expiration},2,2),
cvv => $content{cvv},
},
billing => {
first_name => $content{first_name},
Expand Down

0 comments on commit 8542a4f

Please sign in to comment.