diff --git a/lib/Business/PayPal/API.pm b/lib/Business/PayPal/API.pm index 9466d82..9e1647f 100644 --- a/lib/Business/PayPal/API.pm +++ b/lib/Business/PayPal/API.pm @@ -181,10 +181,13 @@ sub getFieldsList { @response{keys %$fields} = @{$rec}{keys %$fields}; ## avoid duplicates - if( defined $response{TransactionID}){ - $trans_id{$response{TransactionID}}? next : - $trans_id{$response{TransactionID}} = 1; - } + if( defined $response{TransactionID}) { + if( $trans_id{$response{TransactionID}}) { + next; + } else { + $trans_id{$response{TransactionID}} = 1; + } + } push @records, \%response; } diff --git a/t/DirectPayments.t b/t/DirectPayments.t index bce2d7a..9af2022 100644 --- a/t/DirectPayments.t +++ b/t/DirectPayments.t @@ -7,7 +7,7 @@ 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 => '9'; + plan tests => '7'; } use Business::PayPal::API qw( DirectPayments CaptureRequest ReauthorizationRequest VoidRequest RefundTransaction ); @@ -23,55 +23,13 @@ my ($transale,$tranvoid,$tranbasic,$tranrefund); my ($ppsale,$ppvoid,$ppbasic,$pprefund,$pprefund1,$ppcap,$ppcap1); my (%respsale,%resprefund,%resprefund1,%respbasic,%respcap,%respcap1,%respvoid); -#Test Partial Refund on Sale - -#$Business::PayPal::API::Debug=1; -$ppsale = new Business::PayPal::API(%args); -%respsale = $ppsale->DoDirectPaymentRequest ( - PaymentAction => 'Sale', - 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', - ); -#$Business::PayPal::API::Debug=0; -if(is( $respsale{'Ack'}, 'Success', 'Direct Payment Sale')) { - $transale = $respsale{'TransactionID'}; -#$Business::PayPal::API::Debug=1; - $pprefund = new Business::PayPal::API(%args); - %resprefund = $pprefund->RefundTransaction ( - TransactionID => $transale, - RefundType => 'Partial', - Amount => '3.00', - Memo => 'Partial three dollar refund', - ); -#$Business::PayPal::API::Debug=0; - is( $resprefund{'Ack'}, 'Success', 'Partial Refund for sale'); - } - #Test Full Refund on Sale #$Business::PayPal::API::Debug=1; $ppsale = new Business::PayPal::API(%args); %respsale = $ppsale->DoDirectPaymentRequest ( PaymentAction => 'Sale', - OrderTotal => 13.87, + OrderTotal => 11.87, TaxTotal => 0.0, ItemTotal => 0.0, CreditCardType => 'Visa', @@ -84,7 +42,7 @@ $ppsale = new Business::PayPal::API(%args); Street1 => '1st Street LaCausa', Street2 => '', CityName => 'La', - StateOrProvince => 'Ca', + StateOrProvince => 'CA', PostalCode => '90210', Country => 'US', Payer => 'mall@example.org', @@ -93,17 +51,17 @@ $ppsale = new Business::PayPal::API(%args); MerchantSessionID => '10113301', ); #$Business::PayPal::API::Debug=0; -if(is( $respsale{'Ack'}, 'Success', 'Direct Payment Sale')) { +if(like( $respsale{'Ack'}, qr/Success/, 'Direct Payment Sale')) { $transale = $respsale{'TransactionID'}; #$Business::PayPal::API::Debug=1; - $pprefund1 = new Business::PayPal::API(%args); - %resprefund1 = $pprefund1->RefundTransaction ( + $pprefund = new Business::PayPal::API(%args); + %resprefund = $pprefund->RefundTransaction ( TransactionID => $transale, RefundType => 'Full', - Memo => 'Full refund', + Memo => 'Full direct sale refund', ); #$Business::PayPal::API::Debug=0; - is( $resprefund1{'Ack'}, 'Success', 'Full Refund for sale'); + like( $resprefund{'Ack'}, qr/Success/, 'Full Refund For Sale'); } #Basic Authorization and Capture @@ -126,7 +84,7 @@ $ppbasic = new Business::PayPal::API(%args); Street1 => '1st Street LaCausa', Street2 => '', CityName => 'La', - StateOrProvince => 'Ca', + StateOrProvince => 'CA', PostalCode => '90210', Country => 'US', Payer => 'mall@example.org', @@ -136,7 +94,7 @@ $ppbasic = new Business::PayPal::API(%args); ); #$Business::PayPal::API::Debug=0; -if( is( $respbasic{'Ack'}, 'Success', 'Direct Payment Basic Authorization') ) { +if( like( $respbasic{'Ack'}, qr/Success/, 'Direct Payment Basic Authorization') ) { $tranbasic = $respbasic{'TransactionID'}; #Test Partial Capture @@ -150,7 +108,7 @@ if( is( $respbasic{'Ack'}, 'Success', 'Direct Payment Basic Authorization') ) { Note => 'Partial Capture', ); #$Business::PayPal::API::Debug=0; - is( $respcap{'Ack'}, 'Success', 'Partial Capture'); + like( $respcap{'Ack'}, qr/Success/, 'Partial Capture'); #Test Full Capture #$Business::PayPal::API::Debug=1; @@ -161,15 +119,16 @@ if( is( $respbasic{'Ack'}, 'Success', 'Direct Payment Basic Authorization') ) { Amount => '6.00', ); #$Business::PayPal::API::Debug=0; - is( $respcap1{'Ack'}, 'Success', 'Full Capture'); + like( $respcap1{'Ack'}, qr/Success/, 'Full Capture'); } else { skip( "direct payment auth failed", 2 ) } + #Test Void $ppbasic = new Business::PayPal::API(%args); %respbasic = $ppbasic->DoDirectPaymentRequest ( PaymentAction => 'Authorization', - OrderTotal => 18.37, + OrderTotal => 17.37, TaxTotal => 0.0, ItemTotal => 0.0, CreditCardType => 'Visa', @@ -182,7 +141,7 @@ $ppbasic = new Business::PayPal::API(%args); Street1 => '1st Street LaCausa', Street2 => '', CityName => 'La', - StateOrProvince => 'Ca', + StateOrProvince => 'CA', PostalCode => '90210', Country => 'US', Payer => 'mall@example.org', @@ -196,4 +155,4 @@ $ppvoid = new Business::PayPal::API(%args); %respvoid = $ppvoid->DoVoidRequest ( AuthorizationID => $respbasic{TransactionID}, Note => 'Authorization Void', ); #$Business::PayPal::API::Debug=0; -is( $respvoid{'Ack'}, 'Success', 'Authorization Voided'); +like( $respvoid{'Ack'}, qr/Success/, 'Authorization Voided'); diff --git a/t/ExpressCheckout.t b/t/ExpressCheckout.t index 3b6354f..5ca18f5 100644 --- a/t/ExpressCheckout.t +++ b/t/ExpressCheckout.t @@ -87,6 +87,6 @@ my %payment = ( Token => $details{Token}, ## my %payinfo = $pp->DoExpressCheckoutPayment(%payment); -is( $payinfo{Ack}, 'Success', "successful payment" ); +like( $payinfo{Ack}, qr/Success/ , "successful payment" ); is( $payinfo{Token}, $token, "payment ok" ); is( $payinfo{GrossAmount}, 55.43, "amount correct" ); diff --git a/t/ExpressOrder.t b/t/ExpressOrder.t index d8a7cb9..6d6d9e2 100644 --- a/t/ExpressOrder.t +++ b/t/ExpressOrder.t @@ -92,7 +92,7 @@ my %payinfo = $pp->DoExpressCheckoutPayment(%payment); #$Business::PayPal::API::Debug = 0; #If Order is successful then authorize it, then void it. -if(is( $payinfo{Ack}, 'Success', "successful payment" )) { +if(like( $payinfo{Ack}, qr/Success/ , "successful payment" )) { my $transid= $payinfo{TransactionID}; my $amount= '25.43'; use_ok('Business::PayPal::API::AuthorizationRequest'); @@ -101,12 +101,12 @@ if(is( $payinfo{Ack}, 'Success', "successful payment" )) { $ppauth = new Business::PayPal::API::AuthorizationRequest(%args); my %resp = $ppauth->DoAuthorizationRequest( TransactionID => $transid, Amount => $amount); - is( $resp{Ack}, 'Success', 'Successful order authorization' ); + like( $resp{Ack}, qr/Succes/ , 'Successful order authorization' ); use_ok( 'Business::PayPal::API::VoidRequest' ); %args = do_args(); my $ppvoid= new Business::PayPal::API::VoidRequest( %args ); %resp1= $ppvoid->DoVoidRequest( AuthorizationID => $transid, Note => 'Voided' ); - is( $resp1{Ack}, 'Success', 'Successful order void' ); + like( $resp1{Ack}, qr/Success/, 'Successful order void' ); } diff --git a/t/GetTransactionDetails.t b/t/GetTransactionDetails.t index a8a8fdf..20547ff 100644 --- a/t/GetTransactionDetails.t +++ b/t/GetTransactionDetails.t @@ -41,4 +41,4 @@ die "Need a transaction id.\n" unless $transid; #$Business::PayPal::API::Debug = 1; my %resp = $pp->GetTransactionDetails( TransactionID => $transid ); -is( $resp{Ack}, 'Success', "transaction received" ); +like( $resp{Ack}, qr/Success/ , "transaction received" ); diff --git a/t/MassPay.t b/t/MassPay.t index 6217c7d..5e9a78c 100644 --- a/t/MassPay.t +++ b/t/MassPay.t @@ -22,7 +22,7 @@ my %resp = $pp->MassPay( EmailSubject => "This is the subject; nice eh?", UniqueID => "123456", Note => "Enjoy the money. Don't spend it all in one place." } ] ); -is( $resp{Ack}, 'Success', "successful payment" ); +like( $resp{Ack}, qr/Success/ , "successful payment" ); %resp = $pp->MassPay( EmailSubject => "This is the subject; nice eh?", MassPayItems => [ { ReceiverEmail => 'bob@test.tld', @@ -34,4 +34,4 @@ is( $resp{Ack}, 'Success', "successful payment" ); UniqueID => "123458", Note => "Enjoy the money. Don't spend it all in one place." } ] ); -is( $resp{Ack}, 'Success', "successful payments" ); +like( $resp{Ack}, qr/Success/ , "successful payments" ); diff --git a/t/RecurringPayments.t b/t/RecurringPayments.t index da9bc0e..44840cb 100644 --- a/t/RecurringPayments.t +++ b/t/RecurringPayments.t @@ -30,7 +30,7 @@ $Business::PayPal::API::Debug = 0; my $token = $response{Token}; ok( $token, "Got token" ); -is( $response{Ack}, 'Success', "SetCustomerBillingAgreement successful" ); +like( $response{Ack}, qr/Success/ , "SetCustomerBillingAgreement successful" ); exit; @@ -119,5 +119,5 @@ $Business::PayPal::API::Debug = 0; my %details = $pp->GetBillingAgreementCustomerDetails($token); $Business::PayPal::API::Debug = 0; -is( $details{Ack}, "Success", "details ok" ); +like( $details{Ack}, qr/Success/ , "details ok" ); diff --git a/t/RefundTransaction.t b/t/RefundTransaction.t index fa13f87..ff62bbe 100644 --- a/t/RefundTransaction.t +++ b/t/RefundTransaction.t @@ -43,7 +43,7 @@ my %resp = $pp->RefundTransaction( TransactionID => $transid, RefundType => 'Full', Memo => 'Fancy refund time.' ); -is( $resp{Ack}, 'Success', "Successful refund." ); +like( $resp{Ack}, qr/Success/ , "Successful refund." ); if( $resp{Ack} ) { print STDERR <<"_REFUND_"; diff --git a/t/TransactionSearch.t b/t/TransactionSearch.t index 1ce70aa..30bd38e 100644 --- a/t/TransactionSearch.t +++ b/t/TransactionSearch.t @@ -12,7 +12,7 @@ use_ok( 'Business::PayPal::API::TransactionSearch' ); require 't/API.pl'; my %args = do_args(); - +my $resp =''; my $pp = new Business::PayPal::API::TransactionSearch( %args ); print STDERR <<"_TRANSID_";