summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorjeff <jeff>2007-11-20 03:03:08 +0000
committerjeff <jeff>2007-11-20 03:03:08 +0000
commit511331906b11bc8f104f49b164a0a4b262099b0d (patch)
tree813b37c784438b6d99e2f854f702e1006fa09cce /t
parent63544739784abac4d9740323b609e554d58584e6 (diff)
add ARB (recurring authorizations/subscriptions) support
Diffstat (limited to 't')
-rw-r--r--t/00load.t5
-rw-r--r--t/card_arb.t65
-rw-r--r--t/lib/Business/FraudDetect/_Fake.pm23
-rw-r--r--t/lib/test_account.pl5
-rw-r--r--t/mixed_operation.t98
-rw-r--r--t/test_account_arb2
6 files changed, 198 insertions, 0 deletions
diff --git a/t/00load.t b/t/00load.t
new file mode 100644
index 0000000..2e4c366
--- /dev/null
+++ b/t/00load.t
@@ -0,0 +1,5 @@
+#!/usr/bin/perl -w
+
+use Test::More tests => 1;
+
+use_ok 'Business::OnlinePayment::AuthorizeNet';
diff --git a/t/card_arb.t b/t/card_arb.t
new file mode 100644
index 0000000..e560339
--- /dev/null
+++ b/t/card_arb.t
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -w
+
+use Test::More;
+require "t/lib/test_account.pl";
+
+my($login, $password) = test_account_or_skip('arb');
+plan tests => 5;
+
+use_ok 'Business::OnlinePayment';
+
+my $tx = Business::OnlinePayment->new("AuthorizeNet");
+$tx->content(
+ type => 'VISA',
+ login => $login,
+ password => $password,
+ action => 'Recurring Authorization',
+ description => 'Business::OnlinePayment::ARB visa test',
+ amount => '49.95',
+ invoice_number => '100100',
+ customer_id => 'jsk',
+ first_name => 'Tofu',
+ last_name => 'Beast',
+ address => '123 Anystreet',
+ city => 'Anywhere',
+ state => 'UT',
+ zip => '84058',
+ card_number => '4007000000027',
+ expiration => expiration_date(),
+ interval => '1 month',
+ start => '2007-12-01',
+ periods => '3',
+);
+$tx->test_transaction(1); # test, dont really charge
+$tx->submit();
+
+ok($tx->is_success()) or diag $tx->error_message;
+
+my $subscription = $tx->order_number();
+like($subscription, qr/^[0-9]{1,13}$/, "Get order number");
+
+SKIP: {
+
+ skip "No order number", 2 unless $subscription;
+
+ $tx->content(
+ login => $login,
+ password => $password,
+ action => 'Modify Recurring Authorization',
+ subscription => $subscription,
+ amount => '19.95',
+ );
+ $tx->test_transaction(1);
+ $tx->submit();
+ ok($tx->is_success()) or diag $tx->error_message;
+
+ $tx->content(
+ login => $login,
+ password => $password,
+ action => 'Cancel Recurring Authorization',
+ subscription => $subscription,
+ );
+ $tx->test_transaction(1);
+ $tx->submit();
+ ok($tx->is_success()) or diag $tx->error_message;
+}
diff --git a/t/lib/Business/FraudDetect/_Fake.pm b/t/lib/Business/FraudDetect/_Fake.pm
new file mode 100644
index 0000000..d09faa7
--- /dev/null
+++ b/t/lib/Business/FraudDetect/_Fake.pm
@@ -0,0 +1,23 @@
+package Business::FraudDetect::_Fake;
+
+use vars qw( @ISA $result $fraud_score );
+
+@ISA = qw ( Business::OnlinePayment );
+
+sub _glean_parameters_from_parent {
+ my ($self, $parent) = @_;
+ $result = $parent->fraud_detect_faked_result;
+ $fraud_score = $parent->fraud_detect_faked_score;
+}
+
+sub fraud_score {
+ $fraud_score;
+}
+
+sub submit {
+ my $self = shift;
+ $result ? $self->error_message('') : $self->error_message('Planned failure.');
+ $self->is_success($result);
+}
+
+1;
diff --git a/t/lib/test_account.pl b/t/lib/test_account.pl
index 38b282b..0b06973 100644
--- a/t/lib/test_account.pl
+++ b/t/lib/test_account.pl
@@ -28,4 +28,9 @@ sub expiration_date {
return sprintf("%02d/%02d", $month, $year);
}
+sub tomorrow {
+ my($day, $month, $year) = (localtime(time+86400))[3..5];
+ return sprintf("%04d-%02d-%02d", $year+1900, ++$month, $day);
+}
+
1;
diff --git a/t/mixed_operation.t b/t/mixed_operation.t
new file mode 100644
index 0000000..b248245
--- /dev/null
+++ b/t/mixed_operation.t
@@ -0,0 +1,98 @@
+#!/usr/bin/perl -w
+
+BEGIN { push @INC, "t/lib" };
+
+use Test::More;
+
+require "t/lib/test_account.pl";
+
+
+my($arblogin, $arbpassword) = test_account_or_skip('arb');
+my($aimlogin, $aimpassword) = test_account_or_skip();
+plan tests => 9;
+
+use_ok 'Business::OnlinePayment';
+my $tx = Business::OnlinePayment->new("AuthorizeNet",
+ fraud_detect => '_Fake',
+ fraud_detect_faked_result => '0',
+ fraud_detect_faked_score => '2',
+ maximum_fraud_score => '1',
+ );
+$tx->content(
+ type => 'VISA',
+ login => $arblogin,
+ password => $arbpassword,
+ action => 'Recurring Authorization',
+ description => 'Business::OnlinePayment::ARB mixed test',
+ amount => '1.05',
+ first_name => 'Tofu',
+ last_name => 'Beast',
+ card_number => '4007000000027',
+ expiration => expiration_date(),
+ interval => '1 month',
+ start => tomorrow(),
+ periods => '6',
+);
+$tx->test_transaction(1); # test, dont really charge
+$tx->submit();
+
+ok(!$tx->is_success()) or diag "ARB Fraud detection unexpectedly did not fail.";
+
+$tx->fraud_detect_faked_result(1);
+$tx->submit();
+
+ok(!$tx->is_success()) or diag "ARB Fraud detection unexpectedly did not deny.";
+
+$tx->fraud_detect_faked_score(0);
+$tx->submit();
+
+ok($tx->is_success()) or diag $tx->error_message();
+
+my $subscription = $tx->order_number();
+like($subscription, qr/^[0-9]{1,13}$/, "Get order number");
+
+SKIP: {
+
+ skip "No order number", 1 unless $subscription;
+
+ $tx->content(
+ login => $arblogin,
+ password => $arbpassword,
+ action => 'Cancel Recurring Authorization',
+ subscription => $subscription,
+ );
+ $tx->test_transaction(1);
+ $tx->submit();
+ ok($tx->is_success()) or diag $tx->error_message;
+}
+
+$tx->server('test.authorize.net');
+$tx->path('/gateway/transact.dll');
+$tx->content(
+ type => 'VISA',
+ login => $aimlogin,
+ password => $aimpassword,
+ action => 'Normal Authorization',
+ description => 'Business::OnlinePayment::AIM mixed test',
+ amount => '1.06',
+ first_name => 'Tofu',
+ last_name => 'Beast',
+ card_number => '4007000000027',
+ expiration => expiration_date(),
+);
+$tx->test_transaction(1); #test, don't really charge
+$tx->fraud_detect_faked_result(0);
+$tx->fraud_detect_faked_score(2);
+$tx->submit();
+
+ok(!$tx->is_success()) or diag "AIM Fraud detection unexpectedly did not fail.";
+
+$tx->submit();
+$tx->fraud_detect_faked_result(1);
+
+ok(!$tx->is_success()) or diag "AIM Fraud detection unexpectedly did not deny.";
+
+$tx->fraud_detect_faked_score(0);
+$tx->submit();
+ok($tx->is_success()) or diag $tx->error_message;
+
diff --git a/t/test_account_arb b/t/test_account_arb
new file mode 100644
index 0000000..bd0ffa6
--- /dev/null
+++ b/t/test_account_arb
@@ -0,0 +1,2 @@
+7d9P9X9vT2
+773dV9999Pyz9GdW