我在使用Savon发送SOAP请求时遇到问题。
我收到以下错误:
{:fault=> {:faultcode=>"soap:Client", :faultstring=>
"Unmarshalling Error: unexpected element (uri:\"\", local:\"api\"). Expected elements are <{}Eft>,<{}Customer>,<{}Safekey>,<{}Fraud>,<{}Customfield>,<{}BankTransfer>,<{}Creditcard>,<{}Basket>,<{}TransactionType>,<{}Ebucks>,<{}Loyalty>,<{}Soulstace>,<{}TransactionRecord>,<{}AdditionalInformation>,<{}Api>,<{}Autopay>,<{}Stage>,<{}Globalpay> "}}
我的.rb文件如下所示:
require 'savon'
require 'pp'
require 'rubygems'
client = Savon.client({
:wsdl => "https://staging.payu.co.za/service/PayUAPI?wsdl",
:pretty_print_xml => true,
:log_level => :debug,
:wsse_auth => ["Staging Integration Store 2", "XSWYgMUA"],
})
request_msg = {
:Api => "ONE_ZERO",
:Safekey => "{826BD3C4-9663-48B0-804B-044BAA6A57F1}",
:TransactionType => "PAYMENT",
:AdditionalInformation => {
:merchantReference => "mercRef_1350046243",
:cancelUrl => "http://example.com/cancel-page/",
:returnUrl => "http://example.com/return/",
:supportedPaymentMethods => "CREDITCARD"
},
:Customer => {
:email => "john@doe.com",
:firstName => "John",
:lastName => "Doe",
:merchantUserId => 1350046243
},
:Basket => {
:amountInCents => 100,
:currencyCode => "ZAR",
:description => "Basket description comes here"
}
}
begin
set_transaction = client.call(:set_transaction) do
message(request_msg)
end
rescue Savon::SOAPFault => error
pp error.to_hash
end
这是我想用以上代码发送的工作SOAP请求XML(在SoapUI中测试):
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soap.api.controller.web.payjar.com/" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<SOAP-ENV:Header>
<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-9" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>Staging Integration Store 1</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">78cXrW1W</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:setTransaction>
<Api>ONE_ZERO</Api>
<Safekey>{45D5C765-16D2-45A4-8C41-8D6F84042F8C}</Safekey>
<TransactionType>PAYMENT</TransactionType>
<AdditionalInformation>
<merchantReference>mercRef_1350046243</merchantReference>
<cancelUrl>http://example.com/cancel-page/</cancelUrl>
<returnUrl>http://example.com/return/</returnUrl>
<supportedPaymentMethods>CREDITCARD</supportedPaymentMethods>
</AdditionalInformation>
<Customer>
<email>john@doe.com</email>
<firstName>John</firstName>
<lastName>Doe</lastName>
<merchantUserId>1350046243</merchantUserId>
</Customer>
<Basket>
<amountInCents>100</amountInCents>
<currencyCode>ZAR</currencyCode>
<description>Basket description comes here</description>
</Basket>
</ns1:setTransaction>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>