Merge branch 'correct-options-output'
Conflicts: .gitignore
This commit is contained in:
commit
4a0e47a78a
4 changed files with 146 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@ blib
|
||||||
perltidy.LOG
|
perltidy.LOG
|
||||||
pm_to_blib
|
pm_to_blib
|
||||||
subscription-payment.html
|
subscription-payment.html
|
||||||
|
options-payment.html
|
||||||
|
|
2
Changes
2
Changes
|
@ -9,6 +9,8 @@ Revision history for Perl module Business::PayPal::API
|
||||||
- Extract out more payer details from XML.
|
- Extract out more payer details from XML.
|
||||||
(PayerName, NameSuffix, PayerCountry).
|
(PayerName, NameSuffix, PayerCountry).
|
||||||
- Fix https://rt.cpan.org/Public/Bug/Display.html?id=67386
|
- Fix https://rt.cpan.org/Public/Bug/Display.html?id=67386
|
||||||
|
- Options fields of GetTransactionDetails are now returned as a hash,
|
||||||
|
containing the actual options data, rather than array of empty strings.
|
||||||
|
|
||||||
|
|
||||||
0.70 2012-11-13
|
0.70 2012-11-13
|
||||||
|
|
|
@ -127,12 +127,43 @@ sub GetTransactionDetails {
|
||||||
Number => 'Number',
|
Number => 'Number',
|
||||||
Quantity => 'Quantity',
|
Quantity => 'Quantity',
|
||||||
Amount => 'Amount',
|
Amount => 'Amount',
|
||||||
Options => 'Options',
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( scalar( @$paymentitems ) > 0 ) {
|
if ( scalar( @$paymentitems ) > 0 ) {
|
||||||
|
# Options data must be extracted differently. Specifically, the
|
||||||
|
# "interesting" parts of the Options data is not in the values inside
|
||||||
|
# the $som structure (which means $som->valueof(), which
|
||||||
|
# $self->getFieldsList() above calls underneath, won't extract the
|
||||||
|
# useful data, because the values are empty.
|
||||||
|
|
||||||
|
# The convoluted loop below finds any Options values and matches them
|
||||||
|
# up properly with the correct PaymentItem. Note that the loop is
|
||||||
|
# written this way to account for the fact that there may be multiple
|
||||||
|
# PaymentItems.
|
||||||
|
|
||||||
|
# Finally, I contemplated placing this loop below in getFieldsList()
|
||||||
|
# with a special-case for Options, but I am not sure it belongs
|
||||||
|
# there. Ultimately, I think this is unique to the
|
||||||
|
# GetTransactionsDetails call in the API, and thus it's more
|
||||||
|
# appropriately placed here.
|
||||||
|
my $ii = 0;
|
||||||
|
my @fulloptions;
|
||||||
|
foreach my $rec ( $som->dataof($path . '/PaymentItemInfo/PaymentItem' ) ) {
|
||||||
|
my %options;
|
||||||
|
foreach my $subrec ($rec->value()) {
|
||||||
|
foreach my $fieldrec ($$subrec->value()) {
|
||||||
|
$options{$fieldrec->attr()->{name}} = $fieldrec->attr()->{value}
|
||||||
|
if ($fieldrec->name() eq "Options");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$paymentitems->[$ii]{Options} = \%options;
|
||||||
|
push(@fulloptions, \%options);
|
||||||
|
}
|
||||||
|
# Now, we can save the payment items properly
|
||||||
$response{PaymentItems} = $paymentitems;
|
$response{PaymentItems} = $paymentitems;
|
||||||
|
# And set the PII_Options properly too.
|
||||||
|
$response{PII_Options} = \@fulloptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
return %response;
|
return %response;
|
||||||
|
@ -260,6 +291,7 @@ records:
|
||||||
Number => '...',
|
Number => '...',
|
||||||
Quantity => '...',
|
Quantity => '...',
|
||||||
Amount => '...',
|
Amount => '...',
|
||||||
|
Options => { 'key' => 'value', ... },
|
||||||
},
|
},
|
||||||
{ SalesTax => ..., etc.
|
{ SalesTax => ..., etc.
|
||||||
} ]
|
} ]
|
||||||
|
@ -272,6 +304,9 @@ Example:
|
||||||
for my $item ( @{ $resp{PaymentItems} } ) {
|
for my $item ( @{ $resp{PaymentItems} } ) {
|
||||||
print "Name: " . $item->{Name} . "\n";
|
print "Name: " . $item->{Name} . "\n";
|
||||||
print "Amt: " . $item->{Amount} . "\n";
|
print "Amt: " . $item->{Amount} . "\n";
|
||||||
|
for my $optionname (keys %$item->{Options}) {
|
||||||
|
print "Option: $optionname is " . $item->{Options}{$optionname} . "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
=head2 ERROR HANDLING
|
=head2 ERROR HANDLING
|
||||||
|
@ -290,10 +325,12 @@ L<https://developer.paypal.com/en_US/pdf/PP_APIReference.pdf>
|
||||||
=head1 AUTHOR
|
=head1 AUTHOR
|
||||||
|
|
||||||
Scot Wiersdorf E<lt>scott@perlcode.orgE<gt>
|
Scot Wiersdorf E<lt>scott@perlcode.orgE<gt>
|
||||||
|
Bradley M. Kuhn E<lt>bkuhn@ebb.orgE<gt>
|
||||||
|
|
||||||
=head1 COPYRIGHT AND LICENSE
|
=head1 COPYRIGHT AND LICENSE
|
||||||
|
|
||||||
Copyright (C) 2006 by Scott Wiersdorf
|
Copyright (C) 2006 by Scott Wiersdorf
|
||||||
|
Copyright (C) 2014, 2015 by Bradley M. Kuhn
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or modify
|
This library is free software; you can redistribute it and/or modify
|
||||||
it under the same terms as Perl itself, either Perl version 5.8.5 or,
|
it under the same terms as Perl itself, either Perl version 5.8.5 or,
|
||||||
|
@ -301,3 +338,13 @@ at your option, any later version of Perl 5 you may have available.
|
||||||
|
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# Mode: CPerl
|
||||||
|
# indent-tabs-mode: nil
|
||||||
|
# cperl-indent-level: 4
|
||||||
|
# cperl-brace-offset: 0
|
||||||
|
# cperl-continued-brace-offset: 0
|
||||||
|
# cperl-label-offset: -4
|
||||||
|
# cperl-continued-statement-offset: 4
|
||||||
|
# End:
|
||||||
|
|
95
t/OptionFields.t
Normal file
95
t/OptionFields.t
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
# This file is part of Business:PayPal:API Module. License: Same as Perl. See its README for details.
|
||||||
|
# -*- mode: cperl -*-
|
||||||
|
use Test::More;
|
||||||
|
use strict;
|
||||||
|
use autodie qw(:all);
|
||||||
|
use Cwd;
|
||||||
|
|
||||||
|
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 => 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
use_ok( 'Business::PayPal::API::TransactionSearch' );
|
||||||
|
use_ok( 'Business::PayPal::API::GetTransactionDetails' );
|
||||||
|
|
||||||
|
#########################
|
||||||
|
|
||||||
|
require 't/API.pl';
|
||||||
|
|
||||||
|
my %args = do_args();
|
||||||
|
|
||||||
|
=pod
|
||||||
|
|
||||||
|
These tests verify the options work.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
open(OPTIONS_PAY_HTML, ">", "options-payment.html");
|
||||||
|
print OPTIONS_PAY_HTML <<_OPTIONS_PAYMENT_DATA_
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
|
||||||
|
<input type="hidden" name="cmd" value="_xclick" />
|
||||||
|
<input type="hidden" name="business" value="$args{SellerEmail}" />
|
||||||
|
<input type="hidden" name="item_name" value="Field Options Tester" />
|
||||||
|
<input id="no_shipping" type="hidden" name="no_shipping" value="0" />
|
||||||
|
<input id="amount" type="text" name="amount" size="7" minimum="120" value="120" />
|
||||||
|
<input type="hidden" name="on1" value="firstOption" />
|
||||||
|
<input type="hidden" name="os1" value="Yes" />
|
||||||
|
<input type="hidden" name="on2" value="size"/>
|
||||||
|
<input name="os2" id="os2" value="Large"/>
|
||||||
|
<input type="image" border="0" name="submit" alt="Submit Field Tester with $120 payment">
|
||||||
|
</form></body></html>
|
||||||
|
_OPTIONS_PAYMENT_DATA_
|
||||||
|
;
|
||||||
|
close(OPTIONS_PAY_HTML);
|
||||||
|
|
||||||
|
my $cwd = getcwd;
|
||||||
|
|
||||||
|
print STDERR <<"_OPTIONS_LINK_";
|
||||||
|
Please note the next series of tests will not succeeed unless there is at
|
||||||
|
least one transaction that is part of a subscription payments in your business
|
||||||
|
account.
|
||||||
|
|
||||||
|
if you haven't made one yet, you can visit:
|
||||||
|
file://$cwd/options-payment.html
|
||||||
|
|
||||||
|
and use the sandbox buyer account to make the payment.
|
||||||
|
_OPTIONS_LINK_
|
||||||
|
|
||||||
|
my $startdate = '1998-01-01T01:45:10.00Z';
|
||||||
|
|
||||||
|
my $ts = new Business::PayPal::API::TransactionSearch( %args );
|
||||||
|
my $td = new Business::PayPal::API::GetTransactionDetails( %args );
|
||||||
|
|
||||||
|
my $resp = $ts->TransactionSearch(StartDate => $startdate);
|
||||||
|
my %detail;
|
||||||
|
foreach my $record (@{$resp}) {
|
||||||
|
%detail = $td->GetTransactionDetails(TransactionID => $record->{TransactionID});
|
||||||
|
last if $detail{PII_Name} =~ /Field\s+Options/i;
|
||||||
|
}
|
||||||
|
like($detail{PaymentItems}[0]{Name}, qr/Field\s+Options/i, 'Found field options test transaction');
|
||||||
|
like($detail{PII_Name}, qr/Field\s+Options/i, 'Found field options test transaction');
|
||||||
|
|
||||||
|
foreach my $options ($detail{PaymentItems}[0]{Options}, $detail{PII_Options}[0]) {
|
||||||
|
ok(scalar(keys %$options) == 2, "The PaymentItems Options has 2 elements");
|
||||||
|
ok(defined $options->{firstOption}, "'firstOption' is present");
|
||||||
|
ok($options->{firstOption} eq 'Yes', "'firstOption' is selected as 'Yes'");
|
||||||
|
ok(defined $options->{size}, "'size' option is present");
|
||||||
|
ok($options->{size} eq "Large", "'size' option is selected as 'Large'");
|
||||||
|
}
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# Mode: CPerl
|
||||||
|
# indent-tabs-mode: nil
|
||||||
|
# cperl-indent-level: 4
|
||||||
|
# cperl-brace-offset: 0
|
||||||
|
# cperl-continued-brace-offset: 0
|
||||||
|
# cperl-label-offset: -4
|
||||||
|
# cperl-continued-statement-offset: 4
|
||||||
|
# End:
|
||||||
|
|
Loading…
Reference in a new issue