Business-OnlinePayment-IPayment

 view release on metacpan or  search on metacpan

t/payment.t  view on Meta::CPAN

use 5.010001;
use strict;
use warnings;
use Test::More;
use Data::Dumper;
use File::Spec;
use LWP::UserAgent;
use URI;
use POSIX qw/strftime/;

plan tests => 34;

use Business::OnlinePayment::IPayment;
use Business::OnlinePayment::IPayment::Response;

diag "Create the object and store the fixed values";

# first try with faulty data

my %faulty = ();

my $faultybopi;

eval { $faultybopi =
         Business::OnlinePayment::IPayment->new();
       $faultybopi->session_id;
       };

ok($@, "Error: $@");

my %accdata = (
               accountid => 99999,
               trxuserid => 99999,
               trxpassword => 0,
               adminactionpassword => '5cfgRT34xsdedtFLdfHxj7tfwx24fe',
              );

my %urls = (
            success_url => "http://linuxia.de/ipayment/success",
            failure_url => "http://linuxia.de/ipayment/failure",
           );

$faulty{wsdl_file} = File::Spec->catfile("t", "ipayment.wsdl");

# incrementally add the data to the hash

# please note that we want to die here, as without the credentials is
# not going to work, and should be provided when the object is
# created.
foreach my $k (qw/accountid trxuserid trxpassword/) {
    eval { $faultybopi =
             Business::OnlinePayment::IPayment->new(%faulty, %urls);
           $faultybopi->session_id;
       };
    # test all the bad values
    ok($@, "Error: $@");
    $faulty{$k} = $accdata{$k};
}

# adminactionpassword seems to be optional? But we need only to
# generate the session, nothing more

my $wsdl_file = File::Spec->catfile("t", "ipayment.wsdl");

my $bopi = Business::OnlinePayment::IPayment->new(%accdata, %urls,
                                                  wsdl_file => $wsdl_file);

$accdata{accountId} = delete $accdata{accountid};
$accdata{trxuserId} = delete $accdata{trxuserid};

is_deeply($bopi->accountData, { %accdata } , "Stored values ok");

is scalar(keys %{$bopi->processorUrls}), 3, "Found 3 urls";
is $bopi->processorUrls->{redirectUrl}, $urls{success_url}, "success ok";
is $bopi->processorUrls->{silentErrorUrl}, $urls{failure_url}, "success ok";

eval { $bopi->trx_obj->paymentType("test") };
ok($@, "Can't set payment type to bogus value $@");

eval { $bopi->trx_obj->transactionType("preauth") };
ok($@, "Can't change the transaction to allowed value after its creation");

eval { $bopi->trx_obj->transactionType("test") };
ok($@, "Can't set payment type to bogus value $@");



# ok, no point in testing each of those, we trust Moo to do its job

$bopi->transaction(transactionType => 'preauth',
                   trxAmount => int(rand(1000)) * 100);


my $session_id = $bopi->session_id;

my $ua = LWP::UserAgent->new;
$ua->max_redirect(0);

my $response = $ua->post($bopi->ipayment_cgi_location,,
                         { ipayment_session_id => $session_id,
                           addr_name => "Mario Rossi",
                           silent => 1,
                           cc_number => "371449635398431",
                           return_paymentdata_details => 1,
                           cc_checkcode => "",
                           cc_expdate_month => "02",
                           cc_expdate_year => next_year() });

test_success($response);


diag "Testing secured app";


my %account = (
               accountid => 99999,
               trxuserid => 99998,
               trxpassword => 0,
               adminactionpassword => '5cfgRT34xsdedtFLdfHxj7tfwx24fe',
               app_security_key => 'testtest',
               wsdl_file => $wsdl_file,
               %urls
              );


my $secbopi = Business::OnlinePayment::IPayment->new(%account);

$secbopi->transaction(transactionType => 'preauth',
                      trxAmount       => int(rand(5000)) * 100,
                      shopper_id      => 1234);



( run in 0.688 second using v1.01-cache-2.11-cpan-0b5f733616e )