Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SOAP:Lite - I'm having a nightmare 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello,

Everything was going well with my development, until I found that I cannot use PayPAl PDT, because my webohst won't support Crypt::SSLeay and so I cannot do HTTPS requests with LWP::UserAgent.

They now tell me they have support for SOAP::Lite and have sent me to a url on paypal for info, I was kinda hoping someone would help me with writing the code as the code below looks like a module to me using methods and stuff I don't fully understand yet in PERL so all help is very much appreciated.

Code:
Perl
 Perl, the Pathologically Eclectic Rubbish Lister, has been a mainstay of Web programming since the earliest days of Web site automation. Perl's support for regular expressions, database access, and network programming makes it an easy choice for Web programmers.

These Perl examples use SOAP::Lite. They were tested with version 0.60a.[12] 

Some things to remember when trying out these examples for yourself:

Change the first line of the Perl script to match the location of the Perl interpreter you want to use.

Turn on debugging by changing the line "use SOAP::Lite;" to "use SOAP::Lite +trace;".

Each of the example files needs to refer to this module: PayPalAPIInterfaceService.pm. This file was auto-generated from the WSDL file; the process is discussed in the SOAP::Lite documentation.

package PayPalAPIInterfaceService;

# -- generated by SOAP::Lite (v0.60) for Perl -- soaplite.com -- Copyright (C) 2000-2001 Paul Kulchenko --
# -- generated from file:PayPalSvc.wsdl [Tue May 25 18:16:17 2004]

my %methods = (
  TransactionSearch => {
    endpoint => '[URL unfurl="true"]https://api.sandbox.paypal.com/2.0/',[/URL]
    soapaction => '',
    uri => '',
    parameters => [
      SOAP::Data->new(name => 'TransactionSearchRequest', type => '', attr => {}),
    ],
  },
  GetTransactionDetails => {
    endpoint => '[URL unfurl="true"]https://api.sandbox.paypal.com/2.0/',[/URL]
    soapaction => '',
    uri => '',
    parameters => [
      SOAP::Data->new(name => 'GetTransactionDetailsRequest', type => '', attr => {}),
    ],
  },
  RefundTransaction => {
    endpoint => '[URL unfurl="true"]https://api.sandbox.paypal.com/2.0/',[/URL]
    soapaction => '',
    uri => '',
    parameters => [
      SOAP::Data->new(name => 'RefundTransactionRequest', type => '', attr => {}),
    ],
  },
  BillUser => {
    endpoint => '[URL unfurl="true"]https://api.sandbox.paypal.com/2.0/',[/URL]
    soapaction => '',
    uri => '',
    parameters => [
      SOAP::Data->new(name => 'BillUserRequest', type => '', attr => {}),
    ],
  },
);

use SOAP::Lite;
use Exporter;
use Carp ();

use vars qw(@ISA $AUTOLOAD @EXPORT_OK %EXPORT_TAGS);
@ISA = qw(Exporter SOAP::Lite);
@EXPORT_OK = (keys %methods);
%EXPORT_TAGS = ('all' => [@EXPORT_OK]);

no strict 'refs';
for my $method (@EXPORT_OK) {
  my %method = %{$methods{$method}};
  *$method = sub {
    my $self = UNIVERSAL::isa($_[0] => __PACKAGE__) 
      ? ref $_[0] ? shift # OBJECT
                  # CLASS, either get self or create new and assign to self
                  : (shift->self || __PACKAGE__->self(__PACKAGE__->new))
      # function call, either get self or create new and assign to self
      : (__PACKAGE__->self || __PACKAGE__->self(__PACKAGE__->new));
    $self->proxy($method{endpoint} || Carp::croak "No server address (proxy) specified") unless $self->proxy;
    my @templates = @{$method{parameters}};
    my $som = $self
      -> endpoint($method{endpoint})
      -> uri($method{uri})
      -> on_action(sub{qq!"$method{soapaction}"!})
      -> call($method => map {@templates ? shift(@templates)->value($_) : $_} @_); 
    UNIVERSAL::isa($som => 'SOAP::SOM') ? wantarray ? $som->paramsall : $som->result 
                                        : $som;
  }
}

sub AUTOLOAD {
  my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::') + 2);
  return if $method eq 'DESTROY';

  die "Unrecognized method '$method'. List of available method(s): @EXPORT_OK\n";
}

1;
Regards,
1DMF


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
oh and there is this code too
Code:
#!/home/ppadmin0/work/burchell/perldist/perl58/bin/perl
# getdetails.pl
# Use the PayPal API to pull up the details of a transaction

# Contact PayPal Developer Technical Support if you have any questions
# [URL unfurl="true"]http://developer.paypal.com[/URL]
# This code requires SOAP::Lite ([URL unfurl="true"]www.soaplite.com).[/URL]

# Add +trace to enable debugging.
#use SOAP::Lite +trace;
use SOAP::Lite;
use lib "..";
use PayPalAPIInterfaceService;

if ($#ARGV != 2) {
   warn "Bad argument count.  Usage:\n";
   warn "   $0 [API username] [API password] [transaction ID]\n";
   warn "example:\n";
   warn "   $0 paypaltech_api1.ersatz.biz CRz7pawd 46H21514LS196684N\n";
   warn "   $0 dave_seller_api1.ersatz.biz chumphauler 2H21140808310442T\n";
   exit(1);
}

$ENV{HTTPS_CERT_FILE} = "../../example_cert/cert_key.pem";
$ENV{HTTPS_KEY_FILE}  = "../../example_cert/cert_key.pem";

# Set the version
my $version = "1.0";

# Retrieve the username, password, and transaction ID from the command line
my $api_username = $ARGV[0];
my $api_password = $ARGV[1];
my $transactionId = $ARGV[2];

# The base namespace
my $xmlns = 'urn:ebay:api:PayPalAPI';

# Create the SOAP call.
# [URL unfurl="true"]https://api.sandbox.paypal.com/wsdl/PayPalSvc.wsdl[/URL]
my $service = SOAP::Lite
    ->proxy('[URL unfurl="true"]https://api.sandbox.paypal.com/2.0/')[/URL]
    ->readable(1)
    ->outputxml(1)
    ->uri('urn:ebay:api:PayPalAPI')
    ->on_action(sub{ sprintf "%s%s", @_ });

my $request = SOAP::Data->name("GetTransactionDetailsRequest" => 
            \SOAP::Data->value(
                 SOAP::Data->name("Version" =>
                 $version)->type("string")->attr({xmlns=>"urn:ebay:apis:eBLBaseComponents"}),
                             SOAP::Data->name("TransactionID" => $transactionId)->type("ebl:TransactionId")
                 ))->type("ns:GetTransactionDetailsRequestType");
                 
# Create the Security Header
my $header = SOAP::Header->name("RequesterCredentials" => 
                                \SOAP::Header->value(
                                        SOAP::Data->name("Credentials" =>
                                                \SOAP::Data->value(
                                                        SOAP::Data->name("Username" => $api_username)->type(""),
                                                        SOAP::Data->name("Password" => $api_password)->type(""),
                                                        SOAP::Data->name("Subject")->type("")
                                                )
                                        )
                                        ->attr({xmlns=>"urn:ebay:apis:eBLBaseComponents"})
                                )
                        )
                        ->attr({xmlns=>$xmlns})->mustUnderstand("1");

# Create the Method
my $method = SOAP::Data
  ->name('GetTransactionDetailsReq')
    ->attr({xmlns=>$xmlns});

# Execute the call
my $response = $service->call($header, $method => $request);

print $response;
exit;

# eBay Language has a new data type that SOAP::Lite doesn't support - token - so we need to add
# a method for it here.
sub SOAP::XMLSchema2001::Deserializer::as_token {
  *as_token = \&SOAP::XMLSchema1999::Deserializer::as_string;
}
I need help big time, i take now i've got to also use a damn XML parser before I can get to simple value/pairs and what does this line mean
Code:
$ENV{HTTPS_CERT_FILE} = "../../example_cert/cert_key.pem";
$ENV{HTTPS_KEY_FILE}  = "../../example_cert/cert_key.pem";
am I meant to point this to some real file somewhere?, where do i get pem files? and what are they?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I think I've grasped the way this works, The first code is a module, i've put that up no problem, I've made the required changes to the GetTransactionDetails.cgi.

I still don't understand what these .pem files are or where I get them, any ideas?

Thanks,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hi,

I believe that the pem file is one of a number of key & certificate files that you need to generate.

There is quite a bit of info about this process on the paypal web site. You might also like to look at this forum :


Have a look at the 'Keys and Certificates' section of this doc :
HTH.

Nigel Bowden
 
thanks - i'll check it out and see if I can get my head round it :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top