Package Data | |
---|---|
Maintainer Username: | alexpechkarev |
Maintainer Contact: | alexpechkarev@gmail.com (Alexander Pechkarev) |
Package Create Date: | 2014-07-22 |
Package Last Update: | 2014-08-14 |
Home Page: | "https://github.com/alexpechkarev/parcelforce |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:18:13 |
Package Statistics | |
---|---|
Total Downloads: | 23 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Parcelforce exrpessTransferAPI for Laravel to generate pre-advice electronic file that required by solution.
Must be Parcelforce customer
PHP >= 5.3
MySQL
Laravel >= 4.1 if used as Laravel package
composer require alexpechkarev/parcelforce dev-master
Once installed, register Laravel service provider, in app/config/app.php
:
'providers' => array(
...
'Parcelforce\ExpressTransfer\ParcelforceServiceProvider',
)
Publish configuration file:
php artisan config:publish parcelforce/expresstransfer --path vendor/alexpechkarev/parcelforce/src/config/
All generated file will be stored in app/config/packages/parcelforce/expresstransfer/files
folder by default.
Ensure this folder writable by the web server:
chmod o+w app/config/packages/parcelforce/expresstransfer/files
Name and location of this folder can be specified in the configuration file by editing filePath
value,
if changed ensure it's writable by we server.
/**
* Location consignment files
*/
'filePath' => __DIR__.'/files/',
In the configuration file app/config/packages/parcelforce/expresstransfer/config.php
please ensure that following parameters are set.
For more details on configuration options and required values please contact Parcelforce.
By default these parameters preset with dummy values.
'header_customer_account'
'header_generic_contract'
'senderName'
'senderAddress1'
'senderPostTown'
'senderPostcode'
'dr_consignment_number'
'fileName'
'ftpUser'
'ftpPass'
'ftpUploadPath'
'ftpLocationPath'
Simply pass you data as array to Parcelforce::process()
method. Electronic file will be generated for given data,
stored at filePath
location and submitted to Parcelforce.
$senderData = array(
array(
"deliveryDetails"=>array(
'receiverName' =>"MR CUSTOMER",
'receiverAddress1' =>'100 CUSTOMER SOLUTIONS STREET',
'receiverPostTown' =>'MILTON KEYNES',
'receiverPostcode' =>'MK9 9AB'
)
)
);
Parcelforce::process($senderData);
// generate file locally without submitting to Parcelforce
Parcelforce::process($senderData, FALSE);
Multiply consignment data can be submitted in single request.
$senderData = array(
array(
"deliveryDetails"=>array(
'receiverName' =>"MR CUSTOMER",
'receiverAddress1' =>'100 CUSTOMER SOLUTIONS STREET',
'receiverPostTown' =>'MILTON KEYNES',
'receiverPostcode' =>'MK9 9AB'
)
),
array(
"deliveryDetails"=>array(
'receiverName' =>"MR CUSTOMER",
'receiverAddress1' =>'202 CUSTOMER SOLUTIONS STREET',
'receiverPostTown' =>'MILTON KEYNES',
'receiverPostcode' =>'MK9 9AB'
)
)
);
Parcelforce::process($senderData);
By default collection date is set for tomorrow's date and can be amended in the configuration file, see collectionDate
.
This value can also be specified at runtime using Parcelforce::setDate()
method.
Parcelforce::setDate("next Monday");
Parcelforce::process($senderData);
Dates handled by:
Following formats accepted by setDate()
method:
Location: 'Parcelforce\ExpressTransfer\PHP'
Standalone class have same methods as Laravel package and accepts consignment data in the same way.
Before use please ensure that required parameters are set in configuration file 'Parcelforce/ExpressTransfer/PHP/config.php' and
Parcelforce/ExpressTransfer/PHP/files
folder is writable by web server.
$pf = new \Parcelforce\ExpressTransfer\PHP\Parcelforce();
$pf->process($senderData));
// generate file locally without submitting to Parcelforce
$pf->process($senderData));
setDate()
method is also available in standalone version.
...
$pf->setDate("next Monday");
$pf->process($senderData);
For testing and configuration purposes file can be generated without being submitted to Parcelforce.
To generate file locally simply pass FALSE
as second parameter to process()
method.
// In Laravel package
Parcelforce::process($senderData, FALSE);
// In PHP standalone class
$pf->process($senderData, FALSE);
Once testing and configuration completed file and consignment numbers have to be reset to initial values.
To initiate process call reset()
method.
Please note: reset()
will reload database tables and all the data will be lost.
See config.php
for table details.
// In Laravel package
Parcelforce::reset();
// In PHP standalone class
$pf->reset();
PHPUnit testing require Mockery flexible PHP mock object framework. Run following command to install Mockery:
composer require mockery/mockery:dev-master@dev
In Laravel package test file needs copying from package folder into app/tests/
folder, use following to do so:
cp vendor/alexpechkarev/parcelforce/tests/ParcelforceLaravelTest.txt app/tests/ParcelforceTest.php
And then run test:
phpunit app/tests/ParcelforceTest.php
To test PHP standalone file ensure database credentials are set in the config file.
phpunit vendor/alexpechkarev/parcelforce/tests/ParcelforcePHPTest.php
/**
* @param array $data - array of data
* @return string File content
*/
public function process($data, $upload = TRUE)
/**
* Drop database tables
*/
public function reset()
/**
* Get file content
* @return string
*/
public function getFileContent()
/**
* Get current instance config file
* @return array
*/
public function getConfig()
Please open an issue on GitHub
Parcelforce expressTransfer API for Laravel 4 is released under the MIT License. See the bundled LICENSE file for details.