Post by abdou42 » Sun Aug 05, 2018 11:50 pm

helpppppppppppp!!!!
so i have a SOAP function and i want to integrate it to the checkout process
its a DHL function
how should i proceed ; im really lost
here's the function

<?php

class DhlRetoure
{
private $username = "xxx";
private $password = "xxx";
private $portalId = "xxx";
private $deliveryName = "xxx";
private $end_point = "https://amsel.dpwn.net/abholportal/gw/lp/SoapConnector";

public function getRetourePdf($surname, $familyname, $street, $streetNumber, $zip, $city)
{
$xmlRequest = $this->getRequestXml($surname, $familyname, $street, $streetNumber, $zip, $city);
$response = $this->curlSoapRequest($xmlRequest);
if($response){
$pdf = $this->getPdfFromResponse($response);
}
return $pdf;
}
public function displayPdf($pdf){
header("Content-type: application/pdf");
echo $pdf;
}

private function getRequestXml($surname, $familyname, $street, $streetNumber, $zip, $city)
{
$request =
"<?xml version='1.0' encoding='UTF-8' ?>
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:var='https://amsel.dpwn.net/abholportal/gw/lp/schema/1.0/var3bl'>
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand='1' xmlns:wsse='http://docs.oasis-open.org/…/oasis-200401-wss-wssecurity-se…'>
<wsse:UsernameToken>
<wsse:Username>".$this->username."</wsse:Username>
<wsse:Password Type='http://docs.oasis-open.org/…/oasis-200401-wss-username-toke…'>
".$this->password."
</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<var:BookLabelRequest
portalId='".$this->portalId."'
deliveryName='".$this->deliveryName."'
shipmentReference='Shipment Reference'
customerReference='Customer Reference'
labelFormat='PDF'
senderName1='$surname'
senderName2='$familyname'
senderCareOfName='CareofName'
senderContactPhone=''
senderStreet='$street'
senderStreetNumber='$streetNumber'
senderBoxNumber=''
senderPostalCode='$zip'
senderCity='$city' />
</soapenv:Body>
</soapenv:Envelope>";
return $request;
}

/**
* @param $soap_request
* @return mixed
*/
private function curlSoapRequest($xmlRequest)
{
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Content-length: " . strlen($xmlRequest),
);

$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $this->end_point);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true);
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($soap_do);

if (!$response) {
$err = 'Curl error: ' . curl_error($soap_do);
}
else {
/* var_dump(htmlentities($response));*/
}
curl_close($soap_do);
return $response;
}

/**
* @param $response
* @return string
*/
private function getPdfFromResponse($response)
{
$xml = simplexml_load_string($response);
$ns = $xml->getNamespaces(true);
$soap = $xml->children($ns['env']);
$pdf = $soap->Body->children($ns['var3bl'])->BookLabelResponse->label;
$pdf = base64_decode($pdf);
return $pdf;
}
}

Newbie

Posts

Joined
Wed Jun 27, 2018 7:23 am

Post by straightlight » Mon Aug 06, 2018 11:21 pm

What you are looking for has already been developed with the composer version: https://github.com/tobihille/DHL-API-Sample . To return the PDF, read the issues tab comment here with the getManifest() method: https://github.com/Petschko/dhl-php-sdk/issues/50 . If you don't know how to do it, either create a new service request in the Commercial Support section of the forum or, since this request is about an API, send me a PM to implement this class as a custom job.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 8 guests