Tokenization processing, refinements, tests
[Business-OnlinePayment-Bambora.git] / t / 031-payments-card-normal_authorization.t
index f4eb89b..2bb260a 100755 (executable)
@@ -4,7 +4,7 @@ use warnings;
 use Test::More;
 
 use lib 't';
-require 'TestFixtures.pm';
+use TestFixtures;
 use Business::OnlinePayment;
 
 my $merchant_id = $ENV{BAMBORA_MERCHANT_ID};
@@ -15,24 +15,12 @@ SKIP: {
     unless $merchant_id && $api_key;
 
   my %content = (
-    login       => $merchant_id,
-    password    => $api_key,
-    action      => 'Normal Authorization',
-    amount      => '9.99',
-
-    owner       => 'Freeside Internet Services',
-    name        => 'Mitch Jackson',
-    address     => '1407 Graymalkin Lane',
-    city        => 'Vancouver',
-    state       => 'BC',
-    zip         => '111 111',
-    country     => 'CA',
-
-    card_number => '4242424242424242',
-    cvv2        => '111',
-    expiration  => '1122',
-    phone       => '251-300-1300',
-    email       => 'mitch@freeside.biz',
+    common_content(),
+
+    login => $merchant_id,
+    password => $api_key,
+
+    action => 'Normal Authorization',
   );
 
   # Test approved card numbers,
@@ -50,31 +38,42 @@ SKIP: {
     $content{card_number} = $approved_cards{$name}->{card};
     $content{cvv2} = $approved_cards{$name}->{cvv2};
 
-    my $tr;
-    ok( $tr = Business::OnlinePayment->new('Bambora'), 'Instantiatiate $tr' );
-    ok( $tr->content( %content ), 'Set transaction content onto $tr' );
-    {
-      local $@;
-      eval { $tr->submit };
-      ok( !$@, "$name Process transaction (expect approve)" );
-    }
-
-    for my $attr (qw/
-      is_success
-      message_id
-      authorization
-      order_number
-      txn_date
-      avs_code
-    /) {
-      ok(
-        defined $tr->$attr(),
-        sprintf '%s $tr->%s() = %s',
-          $name,
-          $attr,
-          $tr->$attr()
-      );
-    }
+    my ( $tr, $response ) = make_api_request( \%content );
+
+    inspect_response(
+      $response,
+      {
+        amount => '9.99',
+        approved => 1,
+        auth_code => 'TEST',
+        message => 'Approved',
+        message_id => 1,
+        payment_method => 'CC',
+        type => 'P',
+      },
+      [qw/
+        card
+        created
+        order_number
+        risk_score
+        id
+      /],
+    );
+
+    inspect_transaction(
+      $tr,
+      {
+        is_success => 1,
+        authorization => 'TEST',
+      },
+      [qw/
+        message_id
+        order_number
+        txn_date
+        avs_code
+      /],
+    );
+
   }
 
   # Test declined card numbers,
@@ -89,18 +88,18 @@ SKIP: {
     $content{card_number} = $decline_cards{$name}->{card};
     $content{cvv2} = $decline_cards{$name}->{cvv2};
 
-    my $tr;
-    ok( $tr = Business::OnlinePayment->new('Bambora'), 'Instantiate $tr' );
-    ok( $tr->content( %content ), 'Set transaction content onto $tr' );
-    {
-      local $@;
-      eval { $tr->submit };
-      ok( !$@, "$name: Process transaction (expect decline)" );
-    }
+    my ( $tr, $response ) = make_api_request( \%content );
 
-    ok( $tr->is_success == 0, '$tr->is_success == 0' );
+    inspect_transaction(
+      $tr,
+      {
+        is_success => 0,
+      },
+      [qw/
+        error_message
+      /],
+    );
     ok( $tr->result_code != 1, '$tr->result_code != 1' );
-    ok( $tr->error_message, '$tr->error_message: '.$tr->error_message );
   }
 }