Skip to content

Commit

Permalink
Merge branch 'release/0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael DELSOL committed Mar 12, 2016
2 parents 05585f5 + dc6791a commit cff4e83
Show file tree
Hide file tree
Showing 63 changed files with 10,053 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wsdltophp.phar
vendor
composer.lock
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CHANGELOG

## 0.0.1
- Initial version
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2015 WsdlToPhp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/WsdlToPhp/PackageColissimoPostage/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/WsdlToPhp/PackageColissimoPostage/?branch=develop)
[![Latest Stable Version](https://poser.pugx.org/wsdltophp/package-colissimo-postage/v/stable)](https://packagist.org/packages/wsdltophp/package-colissimo-postage)
[![Dependency Status](https://www.versioneye.com/user/projects/56e426e4df573d003a5f5e9f/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56e426e4df573d003a5f5e9f)
[![StyleCI](https://styleci.io/repos/53735115/shield)](https://styleci.io/repos/53735115)
[![Total Downloads](https://poser.pugx.org/wsdltophp/package-colissimo-postage/downloads)](https://packagist.org/packages/wsdltophp/package-colissimo-postage)

# PackageColissimoPostage
This package has been generated from the [Colissimo Postage Web Services](https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl) WSDL using the [PackageGenerator](https://github.com/WsdlToPhp/PackageGenerator) project.

# Summary
- [Generating again the package](#generating-again-the-package)
- [How to use the generated package?](#how-to-use-the-generated-package)
- [Install the project](#install-the-project)
- [Learn from the tutorial](#learn-from-the-tutorial)
- [Start from the samples](#start-from-the-samples)
- [GetServerTimeZones](samples/GetServerTimeZones.php)
- [Need support or having a question?](#need-support-or-having-a-question)

# Generating again the package
You can generate again the package's sources using the [generate.sh](generate.sh) script:
```bash
$ git clone https://github.com/WsdlToPhp/PackageColissimoPostage.git package-colissimo-postage
$ cd package-colissimo-postage
$ ./generate.sh
```
After generating the package, don't forget to edit the generated [composer.json](composer.json) file in order to update the psr-4 autoloading:
```json
"psr-4": {
"ColissimoPostage\\": "./src/",
"SoapClient\\": "./SoapClient/"
}
```
Then run:
```bash
$ composer update
```
To learn how to customize the generated package, please read the PackageGenerator's [README](https://github.com/WsdlToPhp/PackageGenerator/blob/master/README.md).

# How to use the generated package?

## Install the project
```bash
$ git clone https://github.com/WsdlToPhp/PackageColissimoPostage.git package-colissimo-postage
$ cd package-colissimo-postage
$ composer update
```

## Learn from the tutorial
Start looking into the auto-generated [tutorial.php](tutorial.php) file. This file contains the starting code to use this package. In addition it contains all the operations provided by the Exchange Web Services and the way to call them.

## Start from the samples
Sample scripts are available under the [samples](samples) folder:

- [GenerateLabel](samples/GenerateLabel.php)
- [GetProductInter](samples/GetProductInter.php)

# Need support or having a question?
We can help you understand how to use it and how to customize it. Feel free to contact us at contact@wsdltophp.com.
48 changes: 48 additions & 0 deletions SoapClient/SoapClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace SoapClient;

/**
* This class can be overridden at your will.
* Its only purpose is to show you how you can use your own SoapClient client.
*/
class SoapClient extends \SoapClient
{
/**
* Final XML request
* @var string
*/
public $lastRequest;

/**
* @see SoapClient::__doRequest()
*/
public function __doRequest($request, $location, $action, $version, $oneWay = null)
{
/**
* Colissimo does not support type definition
*/
$request = str_replace(' xsi:type="ns1:outputFormat"', '', $request);
$request = str_replace(' xsi:type="ns1:letter"', '', $request);
$request = str_replace(' xsi:type="ns1:address"', '', $request);
$request = str_replace(' xsi:type="ns1:sender"', '', $request);
/**
* Colissimo returns headers and boundary parts
*/
$response = parent::__doRequest($this->lastRequest = $request, $location, $action, $version, $oneWay);
/**
* So we only keep the XML envelope
*/
$response = substr($response, strpos($response, '<soap:Envelope '), strrpos($response, '</soap:Envelope>') - strpos($response, '<soap:Envelope ') + strlen('</soap:Envelope>'));
return '<?xml version="1.0" encoding="UTF-8"?>' . trim($response);
}
/**
* Override it in order to return the final XML Request
* @see SoapClient::__getLastRequest()
* @return string
*/
public function __getLastRequest()
{
return $this->lastRequest;
}
}
29 changes: 29 additions & 0 deletions SoapClient/SoapClientBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace SoapClient;

use WsdlToPhp\PackageBase\AbstractSoapClientBase;

/**
* This class can be overridden at your will.
* Its only purpose is to show you how you can use your own SoapClient client.
* As you can see, you must at least override the getSoapClientClassName in order to return
* your own SoapClient class name to be used.
*
* Full information can be found at PackageBase project homepage: https://github.com/WsdlToPhp/PackageBase.
*/
class SoapClientBase extends AbstractSoapClientBase
{
/**
* @var string
*/
const DEFAULT_SOAP_CLIENT_CLASS = '\SoapClient\SoapClient';
/**
* @see \WsdlToPhp\PackageBase\AbstractSoapClientBase::getSoapClientClassName()
* @return string
*/
public function getSoapClientClassName($soapClientClassName = null)
{
return parent::getSoapClientClassName(static::DEFAULT_SOAP_CLIENT_CLASS);
}
}
15 changes: 15 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "wsdltophp/package-colissimo-postage",
"description": "Package generated from https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl using wsdltophp/packagegenerator",
"require": {
"php": ">=5.3.3",
"ext-soap": "*",
"wsdltophp/packagebase": "dev-master"
},
"autoload": {
"psr-4": {
"ColissimoPostage\\": "./src/",
"SoapClient\\": "./SoapClient/"
}
}
}
33 changes: 33 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# get the latest wsdltophp.phar
if [ ! -f wsdltophp.phar ]; then
echo "Download wsdltophp.phar once";
wget https://phar.wsdltophp.com/wsdltophp.phar;
fi

# get current folder
DEST=`pwd`;

# clean current folder
rm -rf $DEST/src/ \
$DEST/tutorial.php \
$DEST/composer.json \
$DEST/composer.lock;

# package informations
php wsdltophp.phar generate:package \
--urlorpath="https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl" \
--destination=$DEST \
--composer-name="wsdltophp/package-colissimo-postage" \
--addcomments="author:WsdlToPhp <contact@wsdltophp.com>" \
--soapclient="\SoapClient\SoapClientBase" \
--namespace="ColissimoPostage";

# generate package
php wsdltophp.phar generate:package \
--urlorpath="https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl" \
--destination=$DEST \
--composer-name="wsdltophp/package-colissimo-postage" \
--addcomments="author:WsdlToPhp <contact@wsdltophp.com>" \
--soapclient="\SoapClient\SoapClientBase" \
--namespace="ColissimoPostage" \
--force;
98 changes: 98 additions & 0 deletions samples/GenerateLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/**
* Composer autoload
*/
require_once __DIR__ . '/../vendor/autoload.php';
/**
* Used classes
*/
use WsdlToPhp\PackageBase\AbstractSoapClientBase;
use ColissimoPostage\ClassMap;
use ColissimoPostage\ServiceType\Generate;
use ColissimoPostage\StructType\GenerateLabelRequest;
use ColissimoPostage\StructType\OutputFormat;
use ColissimoPostage\StructType\Letter;
use ColissimoPostage\StructType\Fields;
use ColissimoPostage\StructType\GenerateLabel;
use ColissimoPostage\StructType\Service;
use ColissimoPostage\StructType\Parcel;
use ColissimoPostage\StructType\CustomsDeclarations;
use ColissimoPostage\StructType\Contents;
use ColissimoPostage\StructType\Article;
use ColissimoPostage\StructType\Category;
use ColissimoPostage\StructType\Sender;
use ColissimoPostage\StructType\Address;
use ColissimoPostage\StructType\Addressee;
/**
* Your Colissimo credentials
*/
define('COLISSIMO_WS_CONTRACT_NUMBER', '******');
/**
* Your Office 365 passowrd
*/
define('COLISSIMO_WS_PASSWORD', '************');
/**
* Minimal options
*/
$options = array(
AbstractSoapClientBase::WSDL_URL => 'https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl',
AbstractSoapClientBase::WSDL_CLASSMAP => ClassMap::get()
);
/**
* Samples for Generate ServiceType
*/
$generate = new Generate($options);
/**
* Send the request
*/
$result = $generate->generateLabel(
new GenerateLabel(
new GenerateLabelRequest(
COLISSIMO_WS_CONTRACT_NUMBER,
COLISSIMO_WS_PASSWORD,
new OutputFormat(0, 0, 'PDF_A4_300dpi', true, ''),
new Letter(
new Service('A2P', date('Y-m-d', strtotime('next monday')), false, null, null, null, null, 1040, 1222, '123465', 'MONSITE.COM', 2),
new Parcel(null, null, 15000, null, '1', false, null, null, null, 'Remettre au gardien', '005727', null),
new CustomsDeclarations(
1,
new Contents(array(
new Article('Produit neuf', 1, 1, 1500, '0102', 'FR')
),
new Category(2)
)
),
new Sender(
'refsenderXXX',
new Address('sender company', 'Jean', 'Dupont', 'etag 00', 'entrée', 'ligne principale', 'lieu dit', 'FR', 'PARIS', '75001', '0102030405', '0708090102', '0054', '88FF', 'foo@bar.com', 'FFFF', 'FR')
),
new Addressee(
'123456',
false,
'service info',
null,
new Address('sender company', 'Jean', 'Dupont', 'etag 00', 'entrée', 'ligne principale', 'lieu dit', 'FR', 'PARIS', '75001', '0102030405', '0708090102', '0054', '88FF', 'foo@bar.com', 'FFFF', 'FR')
)
)
)
)
);
/**
* Debug informations provided by the utility methods
*/
if (true) {
echo 'XML Request: ' . $generate->getLastRequest() . "\r\n";
echo 'Headers Request: ' . $generate->getLastRequestHeaders() . "\r\n";
echo 'XML Response: ' . $generate->getLastResponse() . "\r\n";
echo 'Headers Response: ' . $generate->getLastResponseHeaders() . "\r\n";
}
/**
* Sample call for getProductInter operation/method
*/
if ($generate->getLastResponse(true) instanceof \DOMDocument) {
echo PHP_EOL . 'PDF url: ' . $generate->getLastResponse(true)
->getElementsByTagName('pdfUrl')
->item(0)->nodeValue . PHP_EOL;
} else {
echo PHP_EOL . 'An error occurred: ' . $generate->getLastErrorForMethod('ColissimoPostage\ServiceType\Generate::generateLabel')->getMessage() . PHP_EOL;
}
56 changes: 56 additions & 0 deletions samples/GetProductInter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Composer autoload
*/
require_once __DIR__ . '/../vendor/autoload.php';
/**
* Used classes
*/
use WsdlToPhp\PackageBase\AbstractSoapClientBase;
use ColissimoPostage\ClassMap;
use ColissimoPostage\ServiceType\Get;
use ColissimoPostage\StructType\GetProductInter;
use ColissimoPostage\StructType\GetProductInterRequest;
/**
* Your Colissimo credentials
*/
define('COLISSIMO_WS_CONTRACT_NUMBER', '******');
/**
* Your Office 365 passowrd
*/
define('COLISSIMO_WS_PASSWORD', '************');
/**
* Minimal options
*/
$options = array(
AbstractSoapClientBase::WSDL_URL => 'https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl',
AbstractSoapClientBase::WSDL_CLASSMAP => ClassMap::get()
);
/**
* Samples for Get ServiceType
*/
$get = new Get($options);
/**
* Send the request
*/
$result = $get->getProductInter(new GetProductInter(new GetProductInterRequest(COLISSIMO_WS_CONTRACT_NUMBER, COLISSIMO_WS_PASSWORD, 'COLI', 0, 0, 1, 'DZ', '2000')));
/**
* Debug informations provided by the utility methods
*/
if (false) {
echo 'XML Request: ' . $get->getLastRequest() . "\r\n";
echo 'Headers Request: ' . $get->getLastRequestHeaders() . "\r\n";
echo 'XML Response: ' . $get->getLastResponse() . "\r\n";
echo 'Headers Response: ' . $get->getLastResponseHeaders() . "\r\n";
}
/**
* Sample call for getProductInter operation/method
*/
if ($result !== false) {
echo sprintf('Product: %s', implode(',', $result->getReturn()->getProduct())) . PHP_EOL;
echo sprintf('PartnerType: %s', $result->getReturn()->getPartnerType()) . PHP_EOL;
echo sprintf('ReturnTypeChoice: %s', implode(', ', $result->getReturn()->getReturnTypeChoice())) . PHP_EOL;
echo sprintf('Message: %s', array_shift($result->getReturn()->getMessages())->getMessageContent()) . PHP_EOL;
} else {
print_r($get->getLastError());
}
Loading

0 comments on commit cff4e83

Please sign in to comment.