Jump to content

Using SoapVar with PEAR SOAP (Again)


nymets1104

Recommended Posts

I have been using PEAR SOAP with an API that supports SOAP for several years. One a new call I am trying to implement, the request is required to be in this format:

                       <CartItems>
                           <CartItem>
                              <Quantity>1</Quantity>
                              <Item xsi:type="Service">
                                 <ID>000123</ID>
                              </Item>
                           </CartItem>
                        </CartItems>
                        <Payments>
                           <PaymentInfo xsi:type="CreditCardInfo">
                              <CreditCardNumber>{CreditCardNumber}</CreditCardNumber>
                              <Amount>5</Amount>
                              <BillingAddress>123 Happy Ln</BillingAddress>
                              <BillingCity>San Luis Obispo</BillingCity>
                              <BillingState>CA</BillingState>
                              <BillingPostalCode>93405</BillingPostalCode>
                              <ExpYear>2014</ExpYear>
                              <ExpMonth>7</ExpMonth>
                              <BillingName>Bob Joe</BillingName>
                           </PaymentInfo>
                        </Payments> 

The main issues are with:

     <Item xsi:type="Service">

AND

     <PaymentInfo xsi:type="CreditCardInfo">

 

 

With traditional PHP SOAP I Would use the following code for the request:

$checkoutShoppingCartRequest = $mb->CheckoutShoppingCart(array(
    'Test'=>'true',
    'ClientID'=>1234,
    'CartItems'=>array(
        'CartItem'=>array(
            'Quantity'=>1,
            'Item' => new SoapVar(
                array('ID'=>'1357'), 
                SOAP_ENC_ARRAY, 
                'Service', 
                'http://clients.mindbodyonline.com/api/0_5'
            ),
            'DiscountAmount' => 0
        )
    ),
    'Payments' => array(
        'PaymentInfo' => new SoapVar(
            array(
                'CreditCardNumber'=>'4111111111111111', 
                'ExpYear'=>'2015', 
                'ExpMonth'=>'06', 
                'Amount'=>'130', 
                'BillingAddress'=>'123 Happy Ln', 
                'BillingPostalCode'=>'93405'
            ), 
            SOAP_ENC_ARRAY, 
            'CreditCardInfo', 
            'http://clients.mindbodyonline.com/api/0_5'
        )
    )
)); 

This does not seem to work with PEAR SOAP, in fact anything involving the SoapVar kills the request and nothing is sent. Any statements or even an echo "HELLO" below the SoapVar are not touched when I load the page. I have found very limited documention on this. Does anyone know the proper way to form this request with PEAR SOAP?

Link to comment
Share on other sites

Once I enabled Error Reporting I am getting these Errors:

 

Notice: Undefined property: stdClass::$PaymentInfo in /hermes/waloraweb019/b71/moo.studiosevacom/saleOYC.php on line 35

 

Fatal error: Class 'SoapVar' not found in /hermes/waloraweb019/b71/moo.studiosevacom/saleOYC.php on line 35

 

I am running PEAR SOAP on Fatcow with PHP 5.3

Edited by nymets1104
Link to comment
Share on other sites

Not many people are familiar with SOAP.

 

Are you sure SOAP is installed at all? And why are you using PEAR for it? And why are you still on PHP 5.3?

 

Unfortunately Fatcow's shared hosting is very limited as far as PHP: http://www.fatcow.com/knowledgebase/beta/article.bml?ArticleID=2124

 

SOAP is installed as I can make calls to this API that do not contain the XSI:TYPE tag (<Item xsi:type="Service">)

Fatcow does not support PHP SOAP only PEAR SOAP which seems to be a huge hurdle.

Link to comment
Share on other sites

PHP 5.3 has been entirely unsupported for almost a year now. Even 5.4 is only receiving security fixes. Their inability to keep up with changing times is worrisome.

 

PEAR's SOAP is not the same as the bundled version. For one, it doesn't have the SoapVar class which is why you're getting that fatal error. There is a SOAP_Value which sounds equivalent, but it's not identical. Maybe

'Item' => new SOAP_Value(
	'Item', // name
	'Service', // type
	array('ID'=>'1357') // value
),
Link to comment
Share on other sites

PHP 5.3 has been entirely unsupported for almost a year now. Even 5.4 is only receiving security fixes. Their inability to keep up with changing times is worrisome.

 

PEAR's SOAP is not the same as the bundled version. For one, it doesn't have the SoapVar class which is why you're getting that fatal error. There is a SOAP_Value which sounds equivalent, but it's not identical. Maybe

'Item' => new SOAP_Value(
	'Item', // name
	'Service', // type
	array('ID'=>'1357') // value
),

Thank You very much for your input. I believe that these limitations from PEAR will ultimately make it impossible to accomplish this call successfully. I did try the Soap_Value suggestion and while it did fix the Fatal Errors, the End Point doesnt seem to recognize it as a valid request.

    [CartItems] => Array
        (
            [0] => Array
                (
                    [Quantity] => 1
                    [Item] => SOAP_Value Object
                        (
                            [value] => Array
                                (
                                    [ID] => 1357
                                )

                            [nqn] => QName Object
                                (
                                    [name] => Item
                                    [prefix] => 
                                    [namespace] => 
                                )

                            [name] => Item
                            [namespace] => 
                            [tqn] => QName Object
                                (
                                    [name] => Service
                                    [prefix] => 
                                    [namespace] => 
                                )

                            [type] => Service
                            [type_namespace] => 
                            [arrayType] => 
                            [attributes] => Array
                                (
                                )

                            [options] => Array
                                (
                                )

                        )

                )

        )

    [Payments] => Array
        (
            [0] => Array
                (
                    [PaymentInfo] => SOAP_Value Object
                        (
                            [value] => Array
                                (
                                    [CreditCardNumber] => 4111111111111111
                                    [ExpYear] => 2015
                                    [ExpMonth] => 06
                                    [Amount] => 130
                                    [BillingAddress] => 123 Happy Ln
                                    [BillingPostalCode] => 93405
                                )

                            [nqn] => QName Object
                                (
                                    [name] => PaymentInfo
                                    [prefix] => 
                                    [namespace] => 
                                )

                            [name] => PaymentInfo
                            [namespace] => 
                            [tqn] => QName Object
                                (
                                    [name] => CreditCardInfo
                                    [prefix] => 
                                    [namespace] => 
                                )

                            [type] => CreditCardInfo
                            [type_namespace] => 
                            [arrayType] => 
                            [attributes] => Array
                                (
                                )

                            [options] => Array
                                (
                                )

                        )

                )

        )

)
object(stdClass)#13 (7) {
  ["Status"]=>
  string(17) "InvalidParameters"
  ["ErrorCode"]=>
  string(4) "9999"
  ["Message"]=>
  string(55) "The cart must have at least one payment method defined."
  ["XMLDetail"]=>
  string(4) "Full"
  ["ResultCount"]=>
  string(1) "0"
  ["CurrentPageIndex"]=>
  string(1) "0"
  ["TotalPageCount"]=>
  string(1) "0"
}

I can start another thread for this, but rather than relocating my website to a Server that supports a more recent and robust PHP Library, would it be possible for me to utililize an external server for these requests while allowing me to keep my site with Fatcow?

Link to comment
Share on other sites

So I tried capturing the XML Packets with Wireshark on this SOAP Request and even on other succesful Requests. I had no luck, but then it dawned on me. The XML is being sent from the Server (Fatcow) to the Web Service Endpoint (MindBody). So would it even be possible to capture this packet with wireshark or an alternate way?

Link to comment
Share on other sites

To get a valid WSDL from that location you need to append ?wsdl to the url:

 

https://api.mindbodyonline.com/0_5/SaleService.asmx?wsdl

 

 

That URL you gave is not to a WSDL. Go to it yourself and see.

Good Call, now I get:

 

Request : 

 

No operation __getLastRequest for port Sale_x0020_ServiceSoap in WSDL.

 

The Code I am using to call this is:

 

sale_proxy.php:

<?php class WebService_Sale_x0020_Service_Sale_x0020_ServiceSoap extends SOAP_Client
{
    function WebService_Sale_x0020_Service_Sale_x0020_ServiceSoap($path = 'https://api.mindbodyonline.com/0_5/SaleService.asmx?wsdl')
    {
        
		$option=array('trace'=>1); 

        $this->SOAP_Client($path,$option);
    }
   
    function &CheckoutShoppingCart($Request)
    {
        $CheckoutShoppingCart = new SOAP_Value('{http://clients.mindbodyonline.com/api/0_5}CheckoutShoppingCart', false, $v = array('Request' => $Request));
        $result = $this->call('CheckoutShoppingCart',
                              $v = array('CheckoutShoppingCart' => $CheckoutShoppingCart),
                              array('namespace' => 'http://clients.mindbodyonline.com/api/0_5',
                                    'soapaction' => 'http://clients.mindbodyonline.com/api/0_5/CheckoutShoppingCart',
                                    'style' => 'document',
                                    'use' => 'literal'));
        return $result;
    }

sale.php:



require_once 'SOAP/Client.php'; 
require_once 'sale_proxy.php';

$proxySales= new  WebService_Sale_x0020_Service_Sale_x0020_ServiceSoap();



$ret=$proxySales->CheckoutShoppingCart($Request);
 
  // <xmp> tag displays xml output in html 
   echo 'Request : <br/><xmp>', 
  $proxySales->__getLastRequest(), 
  '</xmp><br/><br/> Error Message : <br/>';
Link to comment
Share on other sites

Okay...

 

You could try outputting the entire object, like

print_r($proxySales);
to see if there's something useful in there.

 

Otherwise all I can suggest is to look through the SOAP examples to see how their code is supposed to be used.

 

I appreciate your help with this. Unfortunately it seems with the limitations imposed by Fatcow Hosting, I am not bale to form the request in the way that the Server handling it can interpret correctly. I briefly attempted to use Java script to run interact with the Web Service, but this caused even more problems with cross domain issues and so forth. I will continue to work through this and will post any updates here.

Again, thanks for sticking with me on this frustrating situation

Link to comment
Share on other sites

  • 1 month later...

UPDATE!

 

 

After migrating my entire site to a new Host with a robust support of PHP and SOAP I have successfully made calls to the API

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://clients.mindbodyonline.com/api/0_5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:CheckoutShoppingCart>
  <ns1:Request>
    <ns1:SourceCredentials>
      <ns1:SourceName>YogaStudio</ns1:SourceName>
      <ns1:Password>***********************</ns1:Password>
      <ns1:SiteIDs>
       <ns1:int>99999</ns1:int>
      </ns1:SiteIDs>
     </ns1:SourceCredentials>
  <ns1:UserCredentials>
    <ns1:Username>username</ns1:Username>
    <ns1:Password>password</ns1:Password>
    <ns1:SiteIDs>
     <ns1:int>99999</ns1:int>
    </ns1:SiteIDs>
   </ns1:UserCredentials>
<ns1:XMLDetail xsi:nil="true"/>
<ns1:PageSize xsi:nil="true"/>
<ns1:CurrentPageIndex xsi:nil="true"/>
<ns1:ClientID>999</ns1:ClientID>
<ns1:Test>true</ns1:Test>
<ns1:CartItems>
   <ns1:CartItem>
    <ns1:Item xsi:type="ns1:Service">
     <ns1:ID>77</ns1:ID>
    </ns1:Item>
   <ns1:DiscountAmount>0</ns1:DiscountAmount>
    <ns1:Quantity>1</ns1:Quantity>
<  /ns1:CartItem>
</ns1:CartItems>
<ns1:InStore xsi:nil="true"/>
  <ns1:Payments>
   <ns1:PaymentInfo xsi:type="ns1:CreditCardInfo">
    <ns1:CreditCardNumber>9999999999999999</ns1:CreditCardNumber>
    <ns1:Amount>15</ns1:Amount>
    <ns1:ExpMonth>06</ns1:ExpMonth>
    <ns1:ExpYear>2015</ns1:ExpYear>
    <ns1:BillingAddress>123 Happy Ln</ns1:BillingAddress>
    <ns1:BillingPostalCode>93405</ns1:BillingPostalCode>
   </ns1:PaymentInfo>
 </ns1:Payments>
  <ns1:SendEmail xsi:nil="true"/>
  <ns1:LocationID xsi:nil="true"/>
  </ns1:Request>
 </ns1:CheckoutShoppingCart>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
 

I used this PHP to make the call:

<?php
ini_set('display_errors', 1);
error_reporting(-1);
	include_once('MINDBODY_API_v0.5.php');
	$mb = new MINDBODY_API();

	$checkoutShoppingCartRequest = $mb->CheckoutShoppingCart(array(
    'Test'=>'true',
    'ClientID'=>999,
    'CartItems'=>array(
        'CartItem'=>array(
            'Quantity'=>1,
            'Item' => new SoapVar(
                array('ID'=>'999'), 
                SOAP_ENC_ARRAY, 
                'Service', 
                'http://clients.mindbodyonline.com/api/0_5'
            ),
            'DiscountAmount' => 0
        )
    ),
    'Payments' => array(
        'PaymentInfo' => new SoapVar(
            array(
                'CreditCardNumber'=>'9999999999999999', 
                'ExpYear'=>'2015', 
                'ExpMonth'=>'06', 
                'Amount'=>'0', 
                'BillingAddress'=>'123 Happy Ln', 
                'BillingPostalCode'=>'93405'
            ), 
            SOAP_ENC_ARRAY, 
            'CreditCardInfo', 
            'http://clients.mindbodyonline.com/api/0_5'
        )
    )
)); 


?>
<textarea><?= $mb->getXMLRequest(); ?></textarea>
<textarea><?= $mb->getXMLResponse(); ?></textarea>	

Thanks for all who commeted as it was all very helpful!

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.