Search code examples
phpsoapcommission-junction

Commission Junction Daily Publisher Commission Service


I am creating a website with the Commission Junction links,. Now I need to process the commission reports for dividing the commissions. I am planning to use Daily Publisher Commission Service as it provides a provision for including the date in the request. Now I am not able to do a purchase through the CJ link and so I am using a sample query that has given in CJ site itself. I am new to these wbservices and so have some doubts here.

  1. The actual respone will be exactly same as the one given. I mean will it includes the <soapenv:Envelope
    things or it is begin with just the ns1.???

  2. I have assigned the response to a variable $result and give

    $result_xml=simplexml_load_string($result);

but it is showing the error that ns1 is not defined in namespace. Then I have given the <soapenv:Envelope things to the top. Now the error has gone. But the result_xml variable is blank .

Please help me if someone has done it before. or please suggest me some good tutorials so that I can learn and do it. It will be much helpful if someone can give the complete sample response and so I can check the code with it.

Thanks in Advance.


Solution

  • An XML response to a SOAP request will be something like:

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soap:Body>
            <findPublisherCommissionsResponse xmlns="http://api.cj.com">
                <out xmlns="http://api.cj.com">
                    <publisherCommissions xmlns="http://transaction.service.cj.com">
                        <ns1:PublisherCommissionV2 xmlns:ns1="http://transaction.domain.cj.com">
                            <actionStatus xmlns="http://transaction.domain.cj.com">
                                closed
                            </actionStatus>
                            <actionType xmlns="http://transaction.domain.cj.com">
                                sale
                            </actionType>
                            <adId xmlns="http://transaction.domain.cj.com">
                                13123123
                            </adId>
                            <advertiserId xmlns="http://transaction.domain.cj.com">
                                12312312
                            </advertiserId>
                            <advertiserName xmlns="http://transaction.domain.cj.com">
                                Merchant UK ltd
                            </advertiserName>
                            <commissionAmount xmlns="http://transaction.domain.cj.com">
                                25
                            </commissionAmount>
                            <country xmlns="http://transaction.domain.cj.com">
                            </country>
                            <eventDate xmlns="http://transaction.domain.cj.com">
                                2009-08-28T20:30:44-07:00
                            </eventDate>
                            <lockingDate xmlns="http://transaction.domain.cj.com">
                                2009-09-10T00:00:00-07:00
                            </lockingDate>
                            <orderId xmlns="http://transaction.domain.cj.com">
                                1231232
                            </orderId>
                            <original xmlns="http://transaction.domain.cj.com">
                                true
                            </original>
                            <originalActionId xmlns="http://transaction.domain.cj.com">
                                12312321312
                            </originalActionId>
                            <postingDate xmlns="http://transaction.domain.cj.com">
                                2009-08-28T23:30:03-07:00
                            </postingDate>
                            <sId xmlns="http://transaction.domain.cj.com">
                                googlelink
                            </sId>
                            <saleAmount xmlns="http://transaction.domain.cj.com">
                                25
                            </saleAmount>
                            <transactionId xmlns="http://transaction.domain.cj.com">
                                123123123
                            </transactionId>
                            <websiteId xmlns="http://transaction.domain.cj.com">
                                1231231
                            </websiteId>
                        </ns1:PublisherCommissionV2>
                    </publisherCommissions>
                    <sortBy xmlns="http://transaction.service.cj.com">
                    </sortBy>
                    <totalResults xmlns="http://transaction.service.cj.com">
                        1
                    </totalResults>
                </out>
            </findPublisherCommissionsResponse>
        </soap:Body>
    </soap:Envelope>
    

    You maybe having issues parse the xml response into a SimpleXml Object because SimpleXML doesn't like colons (:) in the tag and attribute names SOAP & SimpleXML. Also check here SimpleXML & Namespaces

    Your SOAP request should already be an object so I am uncertain as to why you are trying to parse it using SimpleXML. If you need the response as XML then you could always use a serializer.

    In my own script as an example I use something like this:

    //code here $cj_devkey = "CJ KEY HERE";

            $ini    = ini_set( "soap.wsdl_cache_enabled", "0" );
            $client = new SoapClient( "https://pubcommission.api.cj.com/wsdl/version2/publisherCommissionServiceV2.wsdl", array(
                 'trace' => true,
                'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
                'proxy_host' => "proxy" 
            ) );
    
            $object = $client->findPublisherCommissions( array(
                 "developerKey" => $cj_devkey,
                "date" => '08/28/2009',
                "dateType" => 'event',
                "advertiserIds" => '',
                "websiteIds" => '123456',
                "actionStatus" => '',
                "actionTypes" => 'sale',
                "adIds" => '',
                "countries" => 'all',
                "correctionStatus" => 'all',
                "sortBy" => '',
                "sortOrder" => '' 
            ) );
    

    A sample response using print_r($object) will return :

    stdClass Object
    (
        [out] => stdClass Object
            (
                [publisherCommissions] => stdClass Object
                    (
                        [PublisherCommissionV2] => stdClass Object
                            (
                                [actionStatus] => closed
                                [actionType] => sale
                                [adId] => 123123213
                                [advertiserId] => 2313531
                                [advertiserName] => MERCHANT HERE
                                [commissionAmount] => 25
                                [country] => 
                                [eventDate] => 2009-08-28T20:30:44-07:00
                                [lockingDate] => 2009-09-10T00:00:00-07:00
                                [orderId] => 123123
                                [original] => 1
                                [originalActionId] => 123123
                                [postingDate] => 2009-08-28T23:30:03-07:00
                                [sId] => sports
                                [saleAmount] => 25
                                [transactionId] => 12312312
                                [websiteId] => 123123
                            )
    
                    )
    
                [sortBy] => 
                [totalResults] => 1
            )
    
    )
    

    If you want to traverse the object elements you can use stuff like:

    $num_results = $object->out->totalResults;
    

    or loop through each commission payment with stuff like:

    foreach ( $object->out->publisherCommissions as $commission ) {
                    $user_id        = $commission->{'sId'};
                    $transaction_id = $commission->{'transactionId'};
                    $program_id     = $commission->{'advertiserId'};
                    $post_date      = $commission->{'postingDate'};
                    $action_status  = $commission->{'actionStatus'};
                    $amount         = $commission->{'commissionAmount'};
    }