Hi there,
I'm currently working on a Magento 2 Purolator shipping module. Is there some documentation that is available to make my life simpler for integrating it? I know how Purolator makes their call to their API but I don't know about the different class for Magento 2 to call them, if that makes any sense.
Thanks in advance
Marc,
Hi @Rennes007,
Maybe the official examples can help you: https://github.com/magento/magento2-samples/tree/master/sample-module-shipping-provider
Hi Damian,
That's great, but I was looking for something like, how to I call the (let's assume i'm using Purolator) the Purolator API and make a call via SOAP to get information back to magento?
Purolator has an example, like this:
function createPWSSOAPClient() { /** Purpose : Creates a SOAP Client in Non-WSDL mode with the appropriate authentication and * header information **/ //Set the parameters for the Non-WSDL mode SOAP communication with your Development/Production credentials $client = new SoapClient( "./wsdl/serviceavailabilityservice.wsdl", array ( 'trace' => true, 'location' => "https://webservices.purolator.com/PWS/V1/ServiceAvailability/ServiceAvailabilityService.asmx", 'uri' => "http://purolator.com/pws/datatypes/v1", 'login' => PRODUCTION_KEY, 'password' => PRODUCTION_PASS ) ); //Define the SOAP Envelope Headers $headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1', 'RequestContext', array ( 'Version' => '1.3', 'Language' => 'en', 'GroupID' => 'xxx', 'RequestReference' => 'Rating Example' ) ); //Apply the SOAP Header to your client $client->__setSoapHeaders($headers); return $client; }
It's based on some wsdl files that I have loaded.
Then, to get the result back, I have:
//Create a SOAP Client for Example 02 $client = createPWSSOAPClient(); //Populate the Origin Information $request->Addresses->ShortAddress->City = "Burnaby"; $request->Addresses->ShortAddress->Province = "BC"; $request->Addresses->ShortAddress->Country = "CA"; $request->Addresses->ShortAddress->PostalCode = "V5E4H9"; //Execute the request and capture the response $response = $client->ValidateCityPostalCodeZip($request); /** * SOAP Request Envelope (Request sent to Web Service) * <?xml version="1.0" encoding="UTF-8"?> * <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://purolator.com/pws/datatypes/v1"><SOAP-ENV:Header><ns1:RequestContext><ns1:Version>1.0</ns1:Version><ns1:Language>en</ns1:Language><ns1:GroupID>xxx</ns1:GroupID><ns1:RequestReference>Rating Example</ns1:RequestReference></ns1:RequestContext></SOAP-ENV:Header><SOAP-ENV:Body><ns1:ValidateCityPostalCodeZipRequest><ns1:Addresses><ns1:ShortAddress><ns1:City>Burnaby</ns1:City><ns1:Province>BC</ns1:Province><ns1:Country>CA</ns1:Country><ns1:PostalCode>V5E4H9</ns1:PostalCode></ns1:ShortAddress></ns1:Addresses></ns1:ValidateCityPostalCodeZipRequest></SOAP-ENV:Body></SOAP-ENV:Envelope> **/ /** * SOAP Response Envelope (Request Returned from the Web Service) * <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:ResponseContext xmlns:h="http://purolator.com/pws/datatypes/v1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><h:ResponseReference>Rating Example</h:ResponseReference></h:ResponseContext></s:Header><s:Body><ValidateCityPostalCodeZipResponse xmlns="http://purolator.com/pws/datatypes/v1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ResponseInformation><Errors/><InformationalMessages i:nil="true"/></ResponseInformation><SuggestedAddresses><SuggestedAddress><Address><City>Burnaby</City><Province>BC</Province><Country>CA</Country><PostalCode>V5E4H9</PostalCode></Address><ResponseInformation><Errors/><InformationalMessages i:nil="true"/></ResponseInformation></SuggestedAddress></SuggestedAddresses></ValidateCityPostalCodeZipResponse></s:Body></s:Envelope> **/ //Display the services and associated rules for this shipment print_r($response);
Thanks for helping
I am also trying exactly this. Is there any progress at your end? If yes can you please share how you made it work?
I'm sorry if this answer is not helpful but there is already an extension developed for Purolator: https://meetanshi.com/magento-2-purolator-shipping.html
Doesn't it helpful?
Anyone have success with the extension suggested above in the link?