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

179 lines
5.2 KiB
Perl
Raw Normal View History

2009-12-02 16:44:18 +00:00
#!/usr/bin/perl
2009-12-02 16:44:18 +00:00
use strict;
use warnings;
use Test::Most;
2009-12-02 16:44:18 +00:00
2014-03-23 02:31:50 +00:00
if ( !$ENV{WPP_TEST} || !-f $ENV{WPP_TEST} ) {
plan skip_all =>
'No WPP_TEST env var set. Please see README to run tests';
2009-12-02 16:44:18 +00:00
}
else {
plan tests => '7';
2009-12-02 16:44:18 +00:00
}
2014-03-23 02:31:50 +00:00
use Business::PayPal::API
qw( DirectPayments CaptureRequest ReauthorizationRequest VoidRequest RefundTransaction );
2009-12-02 16:44:18 +00:00
2014-03-23 02:31:50 +00:00
my @methlist
= qw( DirectPayments CaptureRequest ReauthorizationRequest VoidRequest RefundTransaction);
use_ok( 'Business::PayPal::API', @methlist );
2009-12-02 16:44:18 +00:00
require 't/API.pl';
my %args = do_args();
2014-03-23 02:31:50 +00:00
my ( $transale, $tranvoid, $tranbasic, $tranrefund );
my ( $ppsale, $ppvoid, $ppbasic, $pprefund, $pprefund1, $ppcap, $ppcap1 );
my (%respsale, %resprefund, %resprefund1, %respbasic,
%respcap, %respcap1, %respvoid
);
2009-12-02 16:44:18 +00:00
#Test Full Refund on Sale
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=1;
2014-03-23 02:31:50 +00:00
$ppsale = new Business::PayPal::API( %args );
%respsale = $ppsale->DoDirectPaymentRequest(
PaymentAction => 'Sale',
OrderTotal => 11.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',
PostalCode => '90210',
Country => 'US',
Payer => 'mall@example.org',
CurrencyID => 'USD',
IPAddress => '10.0.0.1',
MerchantSessionID => '10113301',
);
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=0;
2014-03-23 02:31:50 +00:00
if ( like( $respsale{'Ack'}, qr/Success/, 'Direct Payment Sale' ) ) {
$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',
);
#$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
2014-03-23 02:31:50 +00:00
%args = do_args();
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=0;
2014-03-23 02:31:50 +00:00
$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',
PostalCode => '90210',
Country => 'US',
Payer => 'mall@example.org',
CurrencyID => 'USD',
IPAddress => '10.0.0.1',
MerchantSessionID => '10113301',
);
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=0;
2014-03-23 02:31:50 +00:00
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;
2014-03-23 02:31:50 +00:00
$ppcap = new Business::PayPal::API( %args );
%respcap = $ppcap->DoCaptureRequest(
AuthorizationID => $tranbasic,
CompleteType => 'NotComplete',
Amount => '3.00',
Note => 'Partial Capture',
);
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=0;
2014-03-23 02:31:50 +00:00
like( $respcap{'Ack'}, qr/Success/, 'Partial Capture' );
2009-12-02 16:44:18 +00:00
#Test Full Capture
#$Business::PayPal::API::Debug=1;
2014-03-23 02:31:50 +00:00
$ppcap1 = new Business::PayPal::API( %args );
%respcap1 = $ppcap1->DoCaptureRequest(
AuthorizationID => $tranbasic,
CompleteType => 'Complete',
Amount => '6.00',
);
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=0;
2014-03-23 02:31:50 +00:00
like( $respcap1{'Ack'}, qr/Success/, 'Full Capture' );
2009-12-02 16:44:18 +00:00
}
else { skip( "direct payment auth failed", 2 ) }
#Test Void
2014-03-23 02:31:50 +00:00
$ppbasic = new Business::PayPal::API( %args );
%respbasic = $ppbasic->DoDirectPaymentRequest(
PaymentAction => 'Authorization',
OrderTotal => 17.37,
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',
PostalCode => '90210',
Country => 'US',
Payer => 'mall@example.org',
CurrencyID => 'USD',
IPAddress => '10.0.0.1',
MerchantSessionID => '10113301',
);
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=1;
2014-03-23 02:31:50 +00:00
$ppvoid = new Business::PayPal::API( %args );
%respvoid = $ppvoid->DoVoidRequest(
AuthorizationID => $respbasic{TransactionID},
Note => 'Authorization Void',
);
2009-12-02 16:44:18 +00:00
#$Business::PayPal::API::Debug=0;
2014-03-23 02:31:50 +00:00
like( $respvoid{'Ack'}, qr/Success/, 'Authorization Voided' );