perl-business-paypal-api/t/DirectPayments.t

159 lines
6.3 KiB
Perl
Raw Normal View History

2009-12-02 16:44:18 +00:00
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
if( ! $ENV{WPP_TEST} || ! -f $ENV{WPP_TEST} ) {
plan skip_all => 'No WPP_TEST env var set. Please see README to run tests';
}
else {
plan tests => '7';
2009-12-02 16:44:18 +00:00
}
use Business::PayPal::API qw( DirectPayments CaptureRequest ReauthorizationRequest VoidRequest RefundTransaction );
my @methlist = qw( DirectPayments CaptureRequest ReauthorizationRequest VoidRequest RefundTransaction);
use_ok('Business::PayPal::API', @methlist);
require 't/API.pl';
my %args = do_args();
my ($transale,$tranvoid,$tranbasic,$tranrefund);
my ($ppsale,$ppvoid,$ppbasic,$pprefund,$pprefund1,$ppcap,$ppcap1);
my (%respsale,%resprefund,%resprefund1,%respbasic,%respcap,%respcap1,%respvoid);
#Test Full Refund on Sale
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=1;
$ppsale = new Business::PayPal::API(%args);
%respsale = $ppsale->DoDirectPaymentRequest (
PaymentAction => 'Sale',
OrderTotal => 11.87,
2009-12-02 16:44:18 +00:00
TaxTotal => 0.0,
ItemTotal => 0.0,
CreditCardType => 'Visa',
CreditCardNumber => '4561435600988217',
ExpMonth => '01',
ExpYear => +(localtime)[5]+1901,
CVV2 => '123',
FirstName => 'JP',
LastName => 'Morgan',
Street1 => '1st Street LaCausa',
Street2 => '',
CityName => 'La',
StateOrProvince => 'CA',
2009-12-02 16:44:18 +00:00
PostalCode => '90210',
Country => 'US',
Payer => 'mall@example.org',
CurrencyID => 'USD',
IPAddress => '10.0.0.1',
MerchantSessionID => '10113301',
);
#$Business::PayPal::API::Debug=0;
if(like( $respsale{'Ack'}, qr/Success/, 'Direct Payment Sale')) {
2009-12-02 16:44:18 +00:00
$transale = $respsale{'TransactionID'};
#$Business::PayPal::API::Debug=1;
$pprefund = new Business::PayPal::API(%args);
%resprefund = $pprefund->RefundTransaction (
TransactionID => $transale,
RefundType => 'Full',
Memo => 'Full direct sale refund',
2009-12-02 16:44:18 +00:00
);
#$Business::PayPal::API::Debug=0;
like( $resprefund{'Ack'}, qr/Success/, 'Full Refund For Sale');
2009-12-02 16:44:18 +00:00
}
#Basic Authorization and Capture
%args=do_args();
#$Business::PayPal::API::Debug=0;
$ppbasic = new Business::PayPal::API(%args);
%respbasic = $ppbasic->DoDirectPaymentRequest (
PaymentAction => 'Authorization',
OrderTotal => 13.87,
TaxTotal => 0.0,
ItemTotal => 0.0,
CreditCardType => 'Visa',
CreditCardNumber => '4561435600988217',
ExpMonth => '01',
ExpYear => +(localtime)[5]+1901,
CVV2 => '123',
FirstName => 'JP',
LastName => 'Morgan',
Street1 => '1st Street LaCausa',
Street2 => '',
CityName => 'La',
StateOrProvince => 'CA',
2009-12-02 16:44:18 +00:00
PostalCode => '90210',
Country => 'US',
Payer => 'mall@example.org',
CurrencyID => 'USD',
IPAddress => '10.0.0.1',
MerchantSessionID => '10113301',
);
#$Business::PayPal::API::Debug=0;
if( like( $respbasic{'Ack'}, qr/Success/, 'Direct Payment Basic Authorization') ) {
2009-12-02 16:44:18 +00:00
$tranbasic = $respbasic{'TransactionID'};
#Test Partial Capture
#$Business::PayPal::API::Debug=1;
$ppcap = new Business::PayPal::API(%args);
%respcap = $ppcap->DoCaptureRequest (
AuthorizationID => $tranbasic,
CompleteType => 'NotComplete',
Amount => '3.00',
Note => 'Partial Capture',
);
#$Business::PayPal::API::Debug=0;
like( $respcap{'Ack'}, qr/Success/, 'Partial Capture');
2009-12-02 16:44:18 +00:00
#Test Full Capture
#$Business::PayPal::API::Debug=1;
$ppcap1 = new Business::PayPal::API(%args);
%respcap1 = $ppcap1->DoCaptureRequest (
AuthorizationID => $tranbasic,
CompleteType => 'Complete',
Amount => '6.00',
);
#$Business::PayPal::API::Debug=0;
like( $respcap1{'Ack'}, qr/Success/, 'Full Capture');
2009-12-02 16:44:18 +00:00
}
else { skip( "direct payment auth failed", 2 ) }
2009-12-02 16:44:18 +00:00
#Test Void
$ppbasic = new Business::PayPal::API(%args);
%respbasic = $ppbasic->DoDirectPaymentRequest (
PaymentAction => 'Authorization',
OrderTotal => 17.37,
2009-12-02 16:44:18 +00:00
TaxTotal => 0.0,
ItemTotal => 0.0,
CreditCardType => 'Visa',
CreditCardNumber => '4561435600988217',
ExpMonth => '01',
ExpYear => +(localtime)[5]+1901,
CVV2 => '123',
FirstName => 'JP',
LastName => 'Morgan',
Street1 => '1st Street LaCausa',
Street2 => '',
CityName => 'La',
StateOrProvince => 'CA',
2009-12-02 16:44:18 +00:00
PostalCode => '90210',
Country => 'US',
Payer => 'mall@example.org',
CurrencyID => 'USD',
IPAddress => '10.0.0.1',
MerchantSessionID => '10113301',
);
#$Business::PayPal::API::Debug=1;
$ppvoid = new Business::PayPal::API(%args);
%respvoid = $ppvoid->DoVoidRequest ( AuthorizationID => $respbasic{TransactionID},
Note => 'Authorization Void', );
#$Business::PayPal::API::Debug=0;
like( $respvoid{'Ack'}, qr/Success/, 'Authorization Voided');