Help with some PayPal SOAP code

I am having issues with PayPal’s SOAP API layer. I am using Ruby 1.8.3
in Ubuntu Breezy.

I downloaded soap4r and used the wsdl2ruby.rb to create
‘defaultDriver.rb’ and other files to map to the PayPal SOAP API.

I am connecting to the sandbox test server with a account and password
and have the certificates and keys in the right spots.

I am getting this following error returned from the SOAP request:

10006
Version is not supported

The first error 10006 is a PayPal error basically saying what the
following line says. Version not supported means that I need to set the
version in the Request, but I can’t see where to set that in the files
that wsdl2ruby.rb created. Here is the script I am trying to
run(basically a customer trying to purchase something using the Direct
Payment API method).

The credit card number is fake btw, i am just trying to sucessfully
connect at this point. I have the correct username/passwords, i ommited
them in my example.

I have taken much of my methods from this howto, but the author uses a
different PayPal API method than I do, and when I run his script, I
cannot set the version either.

http://wiki.rubyonrails.org/rails/pages/PayPalWebServices

require ‘http-access2’
require ‘soap/wsdlDriver’
require ‘soap/header/simplehandler’
require ‘defaultDriver.rb’

class RequesterCredentialsHandler < SOAP::Header::SimpleHandler
HeaderName = XSD::QName.new(‘urn:ebay:api:PayPalAPI’,
‘RequesterCredentials’)
CredentialsName =
XSD::QName.new(‘urn:ebay:apis:eBLBaseComponents’, ‘Credentials’)
UsernameName = XSD::QName.new(nil, ‘Username’)
PasswordName = XSD::QName.new(nil, ‘Password’)
SubjectName = XSD::QName.new(nil, ‘Subject’)

def initialize(username, password, subject)
super(HeaderName)
@username, @password, @subject = username, password, subject
end

def on_simple_outbound
{CredentialsName => {UsernameName => @username, PasswordName =>
@password,
SubjectName => @subject}}
end
end

ENDPOINT_URL = “https://api.sandbox.paypal.com/2.0/

soap = PayPalAPIAAInterface.new(ENDPOINT_URL)

load SSL/Key properties

soap.options[‘protocol.http.ssl_config.verify_mode’] =
OpenSSL::SSL::VERIFY_PEER
soap.options[‘protocol.http.ssl_config.ca_file’] = ‘api_cert_chain.crt’
soap.options[‘protocol.http.ssl_config.client_cert’] = ‘cert’
soap.options[‘protocol.http.ssl_config.client_key’] = ‘key’

soap.headerhandler <<
RequesterCredentialsHandler.new(‘username’,‘password’,‘email’)

soap.wiredump_dev = STDERR if $DEBUG

#setup the direct payment request
request = DoDirectPaymentReq.new
dprequest = DoDirectPaymentRequestDetailsType.new

request.DoDirectPaymentRequest = dprequest
#request.DoDirectPaymentRequest.Version = “2.0”

#set the payment action
dppay_action = PaymentActionCodeType::Sale

#lets set a new payer info object
dppayer_info = PayerInfoType.new
dppayer_info.PayerName = PersonNameType.new(‘Wingritch’, ‘Bill’)
dppayer_address = AddressType.new
dppayer_address.Street1 = “123 Sw Street Ave”
dppayer_address.CityName = “Portland”
dppayer_address.StateOrProvince = “OR”
dppayer_address.Country = “US”
dppayer_address.PostalCode = “97045”
dppayer_info.Address = dppayer_address

#lets get the credit card details setup to put in the payment request
dpcredit_card = CreditCardDetailsType.new(“MasterCard”)
dpcredit_card.ExpYear=2010
dpcredit_card.ExpMonth=10
dpcredit_card.CreditCardNumber=“4276445055121314”
dpcredit_card.CardOwner = dppayer_info

#create a payment details
dppayment_details = PaymentDetailsType.new
ns = “urn:ebay:apis:eBLBaseComponents”
otqname = XSD::QName.new(ns, “OrderTotal”)
otele = SOAP::SOAPElement.new(otqname, “50”)
otele.extraattr[“currencyID”] = “USD”
dppayment_details.OrderTotal = otele

ip_address = “70.89.189.52”

#now lets set all the information in the request for sending
dprequest.PaymentAction = dppay_action
dprequest.CreditCard = dpcredit_card
dprequest.PaymentDetails = dppayment_details
dprequest.IPAddress = ip_address
dprequest.MerchantSessionId = “merchant_session_id”

puts “request”
dp_response = soap.doDirectPayment(request)
puts “response”
puts dp_response.errors.severityCode
puts dp_response.errors.errorCode
puts dp_response.errors.longMessage
puts dp_response.errors.shortMessage

On Tuesday 17 January 2006 06:29 am, Jonathan Dodson wrote:

I am having issues with PayPal’s SOAP API layer. I am using Ruby 1.8.3
in Ubuntu Breezy.

Note: You are not using ruby 1.8.3, you are using a cvs version from
06-23-2005. 1.8.2 basically with some patches.

I recommend downloading the latest ruby and installing to a private
directory.
I use stock packages, but sometimes it just doesn’t work well.

Tsume