PPSR Australia – PHP Example

Having trouble finding a good PHP example to use to start registering your vehicles at http://www.ppsr.gov.au/? Then here you go. A few hours of frustration and looking up other peoples code led me to this basic solution to get started.

Big thanks to https://dwuysan.wordpress.com/ for helping me with getting the TargetEnvironment to work.

If you’re having trouble with ‘Server Error’ responses when doing searches and registrations, check that you have sufficient funds in your PPSR account. You can use the dummy credit cards numbers as provided by PPSR (in an email you would have recieved when you were granted access to the Discovery environment) and make a payment via the PPSR discovery website (WebUI).

From PPSR: “Server error is generated whenever you try to perform a billable transaction, if the account is configured as PAYG or has insufficient funds.”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
include("../config.inc.php"); // contains $username and $password
 
class WsseAuthHeader extends SoapHeader {
 
    private $wss_ns = "";
 
    public function __construct($user, $pass, $ns = null) {
        if ($ns) {
            $this->wss_ns = $ns;
        }
 
        $auth = new stdClass();
        $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
        $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
 
        $username_token = new stdClass();
        $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
 
        $security_sv = new SoapVar(
                        new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
                        SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
 
        parent::__construct($this->wss_ns, 'Security', $security_sv, true);
    }
}
 
class ppsrSoapClient extends SoapClient{
 
    private        $wsdl;
    private        $wss_ns;
    private        $ppsr_ns;
    private        $params;
    private        $environment;
    private        $username;
    private        $password;
 
    public function __construct($environment,$username,$password)
    {
        $this->wsdl            = "schemas.ppsr.gov.au.2011.04.services.wsdl";
        $this->wss_ns        = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
        $this->ppsr_ns        = "http://schemas.ppsr.gov.au/2011/04/services";
        $this->environment    = $environment;
        $this->username        = $username;
        $this->password        = $password;
        $this->params = array(
            'soap_version' => SOAP_1_1,
            'exceptions' => true,
            'trace' => 1,
            'cache_wsdl' => WSDL_CACHE_NONE,
            'targetenvironment' => $this->environment
        ); 
        parent::__construct($this->wsdl, $this->params);
 
        // save us manually calling this each time.
        $this->setSoapHeaders();
    } 
 
    private function setSoapHeaders(){
        $headers = array();
        $headers[1] = new WsseAuthHeader($this->username, $this->password, $this->wss_ns);
        $headers[2] = new SoapHeader($this->ppsr_ns,'TargetEnvironment',$this->environment,true);    
        $this->__setSoapHeaders($headers);
    }
 
    public function getUsername(){
        return $this->username;
    }
}
 
//Put the service parameters here
try{
    $client = new ppsrSoapClient('Discovery',$username,$password);
    try {
        $result = $client->Ping(array("PingRequest"=>array("CustomersRequestMessageId"=>date("Ymdhisu").__LINE__)));
 
        /*
        $vars = array(
            "CustomersRequestMessageId"=>date("Ymdhisu").__LINE__,
            "Username"=>$client->getUsername(),
            "NewPassword"=>"Newpassword1!" // no spaces, 7-15 characters, 1 x uppercase, 1 x number, 1 x special char, different from last 8 passwords
        );
        $result = $client->ChangeB2GPassword(array("ChangeB2GPasswordRequest"=>$vars));        
        */
 
        echo "<pre>";
        print_r($result);
        echo "</pre>";
 
    } catch (Exception $e) {
        echo "<h1>Exception</h1>";
        echo $e->getMessage();
 
        echo "<h1>Debugging Info</h1>";
        echo "<p>REQUEST HEADERS:\n<pre>" .$client->__getLastRequestHeaders() . "</pre>\n</p>";
        echo "<p>REQUEST:\n<pre>" .$client->__getLastRequest(). "</pre>\n</p>";
 
        echo "<p>RESPONSE HEADERS:\n<pre>" .$client->__getLastResponseHeaders() . "</pre>\n</p>"; 
        echo "<p>RESPONSE:\n<pre>" . $client->__getLastResponse() . "</pre>\n</p>";    
    }
} catch (Exception $e) {
    echo $e->getMessage();
}

Please note, I no longer have access to the PPSR development environment, and this example is now quite old code. There have likely been changes to the PPSR system that this code doesn’t cater for.

Please do not ask me to complete/fix your code, I keep my time outside of work hours reserved for self and family.

29 thoughts on “PPSR Australia – PHP Example”

  1. Hi Justin,

    Thanks for this post. I am getting the following message back from ppsr (exception followed by SOAP request). Any ideas ?

    ERROR:

    The message with Action ‘http://schemas.ppsr.gov.au/2011/04/services/RegisterOperationsService/ChangeB2GPassword’ cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

    SOAP REQUEST:

    XXXX-XXX
    XXXX-XXX

    084859

    XXXX-XXX
    XXXX-XXX

  2. I’m assuming it’s because the “CustomersRequestMessageId” needs to be unique for each request, I will update the class posted above to reflect this but I have extended it out to be date(“Ymdhisu”).__LINE__;

  3. Hello Sir,
    First of all many thanks to you for this very helpful Post.
    I am going to develop site for Search Vehicle by VIN Using PPSR Webservices.
    I have made one php page copy your code in it. Set my username and password. when i fire this page on browser it give me ‘Could not connect to host’. i am working on localhost.
    what is the problem for this? how to use ppsr webservices ?

    Thanks in Advance

  4. Hello Sir,

    Thank You For Your Quick Reply and guide me in right Direction.

    The Problem solved and Now I got Response From Web service.
    Can you please suggest me for “SearchBySerialNumber” method In proper way ??
    i have pass all possible parameter for method mention in specification doc but it show me error “Customers Request Message Id must be supplied”. but method can not contain such Parameter to pass as per doc.
    what is solution for this ?

  5. Thanks for post..
    but i got this error message
    SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘schemas.ppsr.gov.au.2011.04.services.wsdl’ : failed to load external entity “schemas.ppsr.gov.au.2011.04.services.wsdl”

    plz help me out

  6. Hello Sir,i am working with ppsr webservices,i am working with discovery environment in localhost,my ip is already whitelisted,i got the proper response from api…

    same code of my local server is not working on live server,i have already pass server ip with bindto parameter,what was problem? please guide me,what i have to change in wsdl kit?

  7. Hello Sir,yes my live server Ip address has been already whitelisted,but as per my debugging,problem in wsdl kit,if i have used wsdl kit(xsd,wsdl files) of my locahost in live server code,then it give me could not connect to host error

    currently production environment is working fine on live server,if i have used live server wsdl kit in live server code for discovery,then it give me atleast one security token is invalid

    please guide me,what i can do,what is the problem?

  8. Hi nim,

    The only thing I can think of is that your WDSL (schemas.ppsr.gov.au.2011.04.services.wsdl) needs to be changed to use the production address eg, change location=”https://b2g-disc.ppsr.gov.au/ should be location=”https://b2g.ppsr.gov.au/ when used in production. I don’t have this set up in a testing environment anymore (changed ISP and no longer white listed) so not able to test further. Hope you are able to solve it soon.

  9. Thanks,for your help,you are right.there is only one change related to the location in schemas.ppsr.gov.au.2011.04.services.wsdl file.now i can go further.
    now i can focus on could not connect to host error,now can you guide me on this error,in which case this type of error occur,i have already passed $options = array(‘socket’ => array(‘bindto’ => ‘my live server ip’));
    $context = stream_context_create($options); in my code…but it is still showing me could not connect to host error

  10. looks like you’re taking quite a different approach to connecting than the example I’ve provided. I imagine, again without being able to test, you are having issues with authentication.

  11. Hello Justin,
    First, many thanks for the example. I’m also trying to achieve same thing for one of my client. Using your example but getting this message

    Could not connect to host

    can you please tell me the reason I may have?

    Thanks

  12. hello justin i tried your code but it gives to me this error
    SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘schemas.ppsr.gov.au.2011.04.services.wsdl’ : failed to load external entity “schemas.ppsr.gov.au.2011.04.services.wsdl”

    can you please help me out for this

  13. I resolve all the issue now i am facing new issue and i don’t know how to resolve the issue

    Exception

    Could not connect to host
    Debugging Info

    REQUEST HEADERS:

    REQUEST:

    egw454Heisfaith4ful!@DiscoveryCustomersRequestMessageId2017100206012676
    RESPONSE HEADERS:

    RESPONSE:

    Please help me out regarding this

  14. Hi Justin,
    Please I need your help. I have used your code as it but change the username and password but yet could not connect to ppsr server. My ip is whitelisted.

    “Forbidden
    You don’t have permission to access / on this server.
    Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request”.

    Thanks for helping me
    Regards,

  15. Sorry all, I don’t have an environment to debug your issues and it is quite likely that a number of things have changed since I first wrote this. Feel free to post any updates you find here so that others don’t have the same battlle to get their PPSR sites up and running.

  16. I have just recently completed work for sites like revscheckaustralia.com.au & vincheckaustralia.com.au which involved implementing an api with both the PPSR and NEVDIS databases. Let me know if you have any issues, I might be able to help.

  17. Hi Jaideep, I’m interested in getting to progress my interface.
    I’m getting the same reply as @shivam singh regarding the parsing error., did you come across this, or indeed @shivam singh how did you resolve it? was it as Justin suggested and a change in the ‘URL’ or is relating to having enough ‘funds’ with the account?

    Can anyone state if the PARSE ERROR is an indication that the account has logged in, or that authentication has failed, or is it basically saying… “sorry, you are in the wrong location” and not even started the authentication process?

    Love to hear from any of you. with your stories or advice.
    Many thanks
    Steve
    stephen.haggarty@donnardconsulting.com

  18. Hi Jaideep,
    We are now able to connect to server but got this error

    SoapFault Object ( [message:protected] => The b2g account customer payment type is PAYG. The b2g account customer payment type must be of Credit or PrePay. [string:Exception:private] => [code:protected] => 0 [file:protected] => /Users/XXX_IP/Documents/ppsrProject_20-10-2017 search/ppsrSoapClient.class.php [line:protected] => 191 [trace:Exception:private] => Array ( [0] => Array ( [file] => /Users/Dr_IP/Documents/ppsrProject_20-10-2017 search/ppsrSoapClient.class.php [line] => 191 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => SearchByRegistrationNumber [1] => Array ( [0] => stdClass Object ( [SearchByRegistrationNumberRequest] => stdClass Object ( [CustomersRequestMessageId] => 201710200415151870078225 [SearchBySerialNumberSearchCriteria] => stdClass Object ( [RegistrationNumber] => XXX234 ) ) ) ) ) ) [1] => Array ( [file] => /Users/Dr_IP/Documents/ppsrProject_20-10-2017 search/index_1.php [line] => 19 [function] => searchByRegno [class] => ppsrSoapClient [type] => -> [args] => Array ( [0] => ZEV252 ) ) ) [previous:Exception:private] => [faultstring] => The b2g account customer payment type is PAYG. The b2g account customer payment type must be of Credit or PrePay. [faultcode] => a:Client [detail] => stdClass Object ( [PpsrSoapFaultDetail] => stdClass Object ( [ErrorNumber] => 50024 [ErrorReferenceId] => 50723511-33d8-4579-bb25-8dd4bf723d23 [RequestProcessedByEnvironment] => Discovery ) ) )

    Please do on make payment? There no payment class in the ppsr document.

    Please reply also to
    auscarip@gmail.com

    Thanks, IP

  19. Hi Justin,

    Please I need your help. I have used your code as it but change the username and password but i am facing new issue and i don’t know how to resolve the issue

    Could not connect to host
    Debugging Info

    REQUEST HEADERS:

    REQUEST:

    *********Discovery2017110403295900000080

    RESPONSE HEADERS:

    RESPONSE:

    Please help me out regarding this issue.

  20. Hello Jaideep,

    I am trying to connect in ppsr for first step as changepassword. but every time i am getting same error “Could not connect to host” as my ip is already whitelisted.

    I am using this as wsdl url “schemas.ppsr.gov.au.2016.05.services” downloaded from here. : https://www.ppsr.gov.au/accessing-b2g-channel

    I am still not connect.. so worry about it can please help some one it will be really help for me.

    If some one can share code or something more help. it will be good.

    Can contact over here : devariyahardik789@gmail.com

  21. Hello Justin,

    Can you please help me regarding ppsr apis.

    I am getting error like could not connect to host even my ip is whitelisted.

    Thanks

  22. Hi Sanjay, Jaideep may be able to help you. I do not have the time. If you come up with a solution, feel free to submit a merge request to the repo I have (or fork it) so others may have an up to date solution

Comments are closed.