Implement payment profile creation
[Business-OnlinePayment-Bambora.git] / t / 041-tokenize-card.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5
6 use lib 't';
7 require 'TestFixtures.pm';
8 use Business::OnlinePayment;
9
10 my $merchant_id = $ENV{BAMBORA_MERCHANT_ID};
11 my $api_key     = $ENV{BAMBORA_API_KEY};
12
13 SKIP: {
14   skip 'Missing env vars BAMBORA_MERCHANT_ID and BAMBORA_API_KEY', 32
15     unless $merchant_id && $api_key;
16
17   my %content = (
18     login          => $merchant_id,
19     password       => $api_key,
20     action         => 'Tokenize',
21     amount         => '9.99',
22
23     owner          => 'Freeside Internet',
24     name           => 'Mitch Jackson',
25     address        => '1407 Graymalkin Lane',
26     city           => 'Vancouver',
27     state          => 'BC',
28     zip            => '111 111',
29     country        => 'CA',
30
31     invoice_number => time(),
32     card_number    => '4030000010001234',
33     cvv2           => '123',
34     expiration     => '1122',
35     phone          => '251-300-1300',
36     email          => 'mitch@freeside.biz',
37   );
38
39   my $tr;
40   ok( $tr = Business::OnlinePayment->new('Bambora'), 'Instantiatiate $tr' );
41   ok( $tr->content( %content ), 'Set transaction content onto $tr' );
42   {
43     local $@;
44     eval { $tr->submit };
45     ok( !$@, "Submit request to create Payment Profile (tokenize)" );
46   }
47
48   my $response;
49
50   my %expect = (
51     code => 1,
52     message => 'Operation Successful',
53   );
54   my @expect = qw(
55     customer_code
56   );
57
58   ok( $response = $tr->response_decoded, 'response_decoded' );
59
60   for my $k ( keys %expect ) {
61     ok(
62       $response->{$k} eq $expect{$k},
63       sprintf '$tr->%s == %s', $k, $expect{$k}
64     );
65   }
66
67   for my $k ( @expect ) {
68     ok(
69       defined $response->{$k},
70       sprintf '$r->%s (%s)',
71         $k, $response->{$k}
72     );
73   }
74
75   ok(
76     $response->{customer_code} eq $tr->card_token,
77     '$tr->card_token eq $response->{customer_code}'
78   );
79
80 }
81
82 done_testing;