diff options
author | Mitch Jackson <mitch@freeside.biz> | 2019-04-22 22:09:39 -0400 |
---|---|---|
committer | Mitch Jackson <mitch@freeside.biz> | 2019-04-22 22:09:39 -0400 |
commit | ef8b468214d2917b90f0537130f14c217ea71224 (patch) | |
tree | 97f7f13c47ecf64a01fe21d44d0ac310de51fe3d /t/041-tokenize-card.t | |
parent | 24c86c6b9136ad878a118d57fc9b876eee3672f8 (diff) |
Tokenization processing, refinements, tests
Diffstat (limited to 't/041-tokenize-card.t')
-rwxr-xr-x | t/041-tokenize-card.t | 167 |
1 files changed, 115 insertions, 52 deletions
diff --git a/t/041-tokenize-card.t b/t/041-tokenize-card.t index f8a1292..161030c 100755 --- a/t/041-tokenize-card.t +++ b/t/041-tokenize-card.t @@ -4,79 +4,142 @@ use warnings; use Test::More; use lib 't'; -require 'TestFixtures.pm'; +use TestFixtures; use Business::OnlinePayment; +use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + $Data::Dumper::Indent = 1; my $merchant_id = $ENV{BAMBORA_MERCHANT_ID}; my $api_key = $ENV{BAMBORA_API_KEY}; SKIP: { - skip 'Missing env vars BAMBORA_MERCHANT_ID and BAMBORA_API_KEY', 32 + skip 'Missing env vars BAMBORA_MERCHANT_ID and BAMBORA_API_KEY', 36 unless $merchant_id && $api_key; my %content = ( - login => $merchant_id, - password => $api_key, - action => 'Tokenize', - amount => '9.99', - - owner => 'Freeside Internet', - name => 'Mitch Jackson', - address => '1407 Graymalkin Lane', - city => 'Vancouver', - state => 'BC', - zip => '111 111', - country => 'CA', - - invoice_number => time(), - card_number => '4030000010001234', - cvv2 => '123', - expiration => '1122', - phone => '251-300-1300', - email => 'mitch@freeside.biz', - ); - - my $tr; - ok( $tr = Business::OnlinePayment->new('Bambora'), 'Instantiatiate $tr' ); - ok( $tr->content( %content ), 'Set transaction content onto $tr' ); - { - local $@; - eval { $tr->submit }; - ok( !$@, "Submit request to create Payment Profile (tokenize)" ); - } + common_content(), - my $response; + login => $merchant_id, + password => $api_key, - my %expect = ( - code => 1, - message => 'Operation Successful', - ); - my @expect = qw( - customer_code + action => 'Tokenize', ); - ok( $response = $tr->response_decoded, 'response_decoded' ); + # + # Create a payment profile with Tokenize + # - for my $k ( keys %expect ) { - ok( - $response->{$k} eq $expect{$k}, - sprintf '$tr->%s == %s', $k, $expect{$k} - ); - } + my ( $tr, $response ) = make_api_request( \%content ); - for my $k ( @expect ) { - ok( - defined $response->{$k}, - sprintf '$r->%s (%s)', - $k, $response->{$k} - ); - } + inspect_response( + $response, + { + code => 1, + message => 'Operation Successful', + }, + [qw/ customer_code /], + ); ok( $response->{customer_code} eq $tr->card_token, '$tr->card_token eq $response->{customer_code}' ); + # + # Create a charge against the payment profile + # with the token set as 'card_number' + # + + my %content_ch1 = ( + %content, + action => 'Normal Authorization', + card_number => $tr->card_token, + amount => '2.95', + ); + + my ( $tr_ch1, $response_ch1 ) = make_api_request( \%content_ch1 ); + + # warn Dumper({ + # response_ch1 => $response_ch1, + # }); + + inspect_response( + $response_ch1, + { + amount => $content_ch1{amount}, + approved => 1, + auth_code => 'TEST', + authorizing_merchant_id => $content{login}, + message => 'Approved', + payment_method => 'CC', + type => 'P', + }, + [qw/ + card + created + order_number + /], + ); + + + # + # Create a charge against the payment profile + # with the token set as 'card_token' + # + + my %content_ch2 = ( + login => $content{login}, + password => $content{password}, + action => 'Normal Authorization', + #card_token => '9915559773829941', + card_token => $tr->card_token, + amount => '7.77', + ); + + my ( $tr_ch2, $response_ch2 ) = make_api_request( \%content_ch2 ); + + # warn Dumper({ + # response_chs => $response_ch2 + # }); + + inspect_response( + $response_ch2, + { + amount => $content_ch2{amount}, + approved => 1, + auth_code => 'TEST', + authorizing_merchant_id => $content{login}, + message => 'Approved', + payment_method => 'CC', + type => 'P', + }, + [qw/ + card + created + order_number + /], + ); + + # + # Attempt charge with a normal credit card number as card_token + # Expect fail + # + + my %content_fail = ( + %content_ch2, + card_token => '4242424242424242', + amount => '24.95', + ); + + my ( $tr_fail, $response_fail ) = make_api_request( \%content_fail ); + + inspect_transaction( + $tr_fail, + { is_success => 0 }, + [qw/ error_message /], + ); + } done_testing;
\ No newline at end of file |