skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search