webador / sendcloud Goto Github PK
View Code? Open in Web Editor NEWProvides a PHP client to interact with the SendCloud API in an object-oriented way.
License: MIT License
Provides a PHP client to interact with the SendCloud API in an object-oriented way.
License: MIT License
The parameters of the createParcel()
method grew naturally, but I think it would be better to model them (and parameters of other methods) using a value object instead. That way, mandatory parameters are enforced and the dedicated model can be documented and extended better.
Lines 156 to 168 in 7796205
As I stated in my PR #33,
service points endpoints uses a different url : https://servicepoints.sendcloud.sc/api/v2/
.
This can quite a bit confusing to use :
use JouwWeb\Sendcloud\Client;
$client = new Client('your_public_key', 'your_secret_key');
$client->getUser(); // HTTP 200 OK
$client->searchServicePoints('NL'); // HTTP 404 NOT FOUND
$client_2 = new Client('your_public_key', 'your_secret_key', null, 'https://servicepoints.sendcloud.sc/api/v2/');
$client_2->getUser(); // HTTP 404 NOT FOUND
$client_2->searchServicePoints('NL'); // HTTP 200
So I suggest something like this :
Client.php
: Everything related to https://panel.sendcloud.sc/api/v2/
ServicePointsClient.php
: Everything related to https://servicepoints.sendcloud.sc/api/v2/
parseGuzzleException()
to Utility.php
So now :
use JouwWeb\Sendcloud\Client;
use JouwWeb\Sendcloud\ServicePointsClient;
$client = new Client('your_public_key', 'your_secret_key');
$client->getUser(); // HTTP 200 OK
$client->searchServicePoints('NL'); // Method does not exist
$client_2 = new ServicePointsClient('your_public_key', 'your_secret_key');
$client_2->getUser(); // Method does not exist
$client_2->searchServicePoints('NL'); // HTTP 200 OK
Is this a good idea ?
Currently it is not possible to add order_status
, payment_status
& total_order_value
per Parcel right?
Is it possible to built this in?
Hello!
I was wondering if you might be willing to include support for the 'to_post_number' parameter of the parcel creation endpoint (https://docs.sendcloud.sc/api/v2/shipping/#create-a-parcel)? It's needed for creating DHL Parcel Service Point deliveries in Germany (maybe in other places too).
This would have to be handled similarly to the 'to_service_point' parameter.
Thank you!
I'm using this package with Laravel 7 but when I want to upgrade to Laravel 8 the Guzzle version conflicts. Is there a possibility to upgrade to Guzzle ^7.0.1
Thanks
You can't just pass the new (as of v5) full address line 1 here. Even when house number is an empty string, the API will return:
from_house_number: "This field is required."
They are required for return portal on sendcloud to make it easier selecting the right item.
Seems the signature of API function to create a parcel has changed. In my opinion this should not be included in a 3.8 release without a warning.
sendcloud/src/Model/ShippingMethod.php
Line 17 in 81dbffe
Using (int) in the result of ShippingMethod::fromData()
distorts the result of the min_weight
and max_weight
in some cases.
Indeed, the result of (int)(1.001*1000)
is 1000, while we expect to have 1001.
To avoid this, it could be possible to combine intval() and ceil(), like this:
intval(ceil($data['min_weight'] * 1000)),
intval(ceil($data['max_weight'] * 1000)),
Uncaught Error: Class 'JouwWeb\SendCloud\Client' not found in /var/www/html/shipping/sendcloud/index.php:11
We have german "Poststation" addresses and the expected format from sendcloud side is:
Example Address: 21234567 Packstation 123
address: Packstation
address_2: 21234567
house_number: 123
Seems we can not set the Address2 for address and have no influence on the createParcel method.
Why not give an option to add an array with additional data to the Address Model and this will be merged into the data consumed by the createParcel method?
Hi ! How i can download the generated
$pdf
please ?
Hello!
In the function verifyWebhookRequest
of file src/Utility.php
, you are retrieving the header 'SendCloud-Signature' which is correct according to the SendCloud API documentation.
I used your library on inside WordPress, and there the request object enforces certain rules for the header names (https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/). Basically, it stores 'SendCloud-Signature' as 'sendcloud_signature'.
Funny thing is, the call to getHeader
in the verifyWebhookRequest
method works equally well for both 'SendCloud-Signature' and 'sendcloud-signature', but the dash instead of underscore causes the exception to be thrown always.
I was wondering if it would be possible to update the method to look a bit like this:
$signatureHeader = $request->getHeader('SendCloud-Signature');
if (count($signatureHeader) === 0) {
$signatureHeader = $request->getHeader('SendCloud_Signature');
if (count($signatureHeader) === 0) {
throw new SendCloudWebhookException(
'Webhook request does not specify a signature header.',
SendCloudWebhookException::CODE_INVALID_REQUEST
);
}
}
Looking forward to your reply!
Currently the only way of retrieving labels is through the Labels endpoint from what I can tell. I was advised by Sendcloud to use the Parcel Documents endpoint as we rely on ZPL.
Is this something that's currently in the works behind the scenes, or would this be something that I would have to make a PR for?
First of all. Thanks for open-sourcing this.
The package is very helpful.
I am running into the following error when trying to create a parcel using JouwWeb\SendCloud\Client->createParcel()
.
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://panel.sendcloud.sc/api/v2/parcels` resulted in a `400 Bad Request` response: {"error":{"code":400,"request":"api/v2/parcels","message":"weight: \"A valid number is required.\""}}
As seen on https://github.com/JouwWeb/sendcloud/blob/master/src/Client.php#L520 the weight is being cast to a string
. Which is fine according to https://docs.sendcloud.sc/api/v2/shipping/#create-a-parcel. The problem now, for as far as I can see is that for Sendcloud is currently not accepting not rounded weights for parcels in kilograms. For example, the results of different input data for https://github.com/JouwWeb/sendcloud/blob/master/src/Client.php#L192:
name:"Firstname Lastname"
company_name:""
address:"Street"
address_2:""
house_number:"1"
city:"Amsterdam"
postal_code:"1234AB"
country:"NL"
email:"[email protected]"
telephone:"0612345678"
country_state:""
order_number:"1"
weight:"6,525"
Results in an error
name:"Firstname Lastname"
company_name:""
address:"Street"
address_2:""
house_number:"1"
city:"Amsterdam"
postal_code:"1234AB"
country:"NL"
email:"[email protected]"
telephone:"0612345678"
country_state:""
order_number:"1"
weight:"6"
Works perfectly
Changing https://github.com/JouwWeb/sendcloud/blob/master/src/Client.php#L519 fixes it for me.
$parcelData['weight'] = (string)($weight / 1000);
// change to
$parcelData['weight'] = (string) round($weight / 1000);
https://api.sendcloud.dev/docs/sendcloud-public-api/parcels/operations/create-a-parcel#request-body
https://github.com/JouwWeb/sendcloud/blob/master/src/Model/Address.php#L28
As sendcloud has an automatic extraction system in place to get the house number from the address you provide, is not required to sent the house number separately and you can combine it inside the address field.
From #5 (comment):
@bockhauzen: There also seem to be an issue with:
client->createLabelWhen trying to use DE as country code it seems to fail.
Im trying to debug it, probaly my brains are just failing.
When you create a parcel and call the toArray() function on the resulting parcel it fails with the error:
Return value of JouwWeb\SendCloud\Model\Parcel::JouwWeb\SendCloud\Model{closure}() must be of the type string, null returned
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.