tags:

views:

140

answers:

2

I need to generate the following XML with SOAP:

                    ...
                <InternationalShippingServiceOption>
                        <ShippingService>StandardInternational</ShippingService>
                        <ShippingServiceCost currencyID="USD">39.99</ShippingServiceCost>
                        <ShippingServicePriority>1</ShippingServicePriority>
                        <ShipToLocation>CA</ShipToLocation>
                    </InternationalShippingServiceOption>
                    ...

So I have the following SOAP array in PHP to do this:

$params =   array(
         'InternationalShippingServiceOption' => array(
            'ShippingService'=>'StandardInternational',
            'ShippingServiceCost'=>39.99,
            'ShippingServicePriority'=>1,
            'ShipToLocation'=>'CA',
        )
    )
$client = new eBaySOAP($session); //eBaySOAP extends SoapClient
$results = $client->AddItem($params);

Everything works great, except I am not generating the currencyID="USD" attribute in the ShippingServiceCost tag in the XML. How do I do this?

A: 

Why, I am glad you asked. I just solved this today.

$shippingsvccostwithid = new SoapVar(array('currencyID' => $whatever),SOAP_ENC_OBJECT, 'ShippingServiceCost', 'https://your.namespace.here.com/');
$params = array("InternationalShippingServiceOption" => array(
    "ShippingService" => "StandardInternational",
    "ShippingServiceCost" => $shippingsvccostwithid,
    "ShippingServicePriority" => 1,
    "ShipToLocation" => "CA"
);

And then continue as normal.

Please let me know if you need any more help.

benjy
A: 

You don't need to use SoapVar. This works (for me at least):

$params =   array(
         'InternationalShippingServiceOption' => array(
            'ShippingService'=>'StandardInternational',
            'ShippingServiceCost' => array('_' => 39.99, 'currencyID' => 'USD')
            'ShippingServicePriority'=>1,
            'ShipToLocation'=>'CA',
        )
    )

I'm using this technique with the PayPal SOAP API.

richb
I have a question about PayPal SOAP api if you don't mind. How do you set the 'Version'? When I set it, the tag becomes 'xsd:string' instead of 'Version'. More info here http://stackoverflow.com/questions/3105577/simple-php-soapclient-example-for-paypal-neededThanks!
Jonah