Business-OnlinePayment-IPayment

 view release on metacpan or  search on metacpan

t/auth-refund.t  view on Meta::CPAN

use 5.010001;
use strict;
use warnings;
use Test::More;
use Data::Dumper;
use File::Spec;
use LWP::UserAgent;
# to prevent the following error on older Perls
# Can't locate object method "new" via package "LWP::Protocol::https::Socket"
use IO::Socket::SSL;

use URI;
use POSIX qw/strftime/;

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

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

my %account = (
               accountid => 99999,
               trxuserid => 99998,
               trxpassword => 0,
               adminactionpassword => '5cfgRT34xsdedtFLdfHxj7tfwx24fe',
               app_security_key => 'testtest',
               wsdl_file => File::Spec->catfile("t", "ipayment.wsdl"),
               success_url => "http://linuxia.de/ipayment/success",
               failure_url => "http://linuxia.de/ipayment/failure",
              );
my $secbopi = Business::OnlinePayment::IPayment->new(%account);

my $amount = int(rand(5000)) * 100 + 2000;

my $shopper_id = int(rand(5000));

$secbopi->transaction(transactionType => 'auth',
                      trxAmount       => "$amount",
                      shopper_id      => $shopper_id);

my $response = $ua->post($secbopi->ipayment_cgi_location,
                      { ipayment_session_id => $secbopi->session_id,
                        addr_name => "Mario Pegula",
                        silent => 1,
                        cc_number => "4111111111111111",
                        cc_checkcode => "",
                        cc_expdate_month => "02",
                        trx_securityhash => $secbopi->trx_securityhash,
                        cc_expdate_year => next_year() });

ok($response->code == 302, 'Check HTTP response code for POST action')
    || diag('HTTP response: ' . $response->as_string);

my $ipayres = $secbopi->get_response_obj($response->header('location'));

ok($ipayres->is_valid);
ok($ipayres->is_success);

print $ipayres->ret_trx_number, " ", $ipayres->trx_amount, " ", $ipayres->trx_currency, "\n";

my $refund = $secbopi->refund($ipayres->ret_trx_number, 2000, "EUR",
                              { shopperId => $shopper_id });

like($secbopi->debug->request->content,
     qr{<shopperId>\Q$shopper_id\E</shopperId}, "Shopper id passed");

ok($refund->is_success);
# print Dumper($secbopi->debug);
print Dumper($secbopi->raw_response_hash);



( run in 2.560 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )