Skip to content

Commit

Permalink
Merge pull request #34 from Soptareanu/master
Browse files Browse the repository at this point in the history
Update SDK
  • Loading branch information
Soptareanu authored Jan 10, 2023
2 parents eed07bf + 4ae2063 commit 6852f7c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/Sameday/Http/RequestBodyUrlEncoded.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function __construct(array $params)
*/
public function getBody()
{
return http_build_query($this->params, null, '&');
return http_build_query($this->params, '', '&');
}
}
82 changes: 56 additions & 26 deletions src/Sameday/Requests/SamedayPostAwbRequest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,33 @@ class SamedayPostAwbRequest implements SamedayRequestInterface
/**
* @var int|null
*/
protected $lockerId;
protected $lockerFirstMile;

/**
* SamedayPostAwbRequest constructor.
*
* @param int $pickupPointId
* @param int|null $contactPersonId
* @var int|null
*/
protected $lockerLastMile;

/**
* @param $pickupPointId
* @param $contactPersonId
* @param PackageType $packageType
* @param ParcelDimensionsObject[] $parcelsDimensions
* @param int $serviceId
* @param array $parcelsDimensions
* @param $serviceId
* @param AwbPaymentType $awbPayment
* @param AwbRecipientEntityObject $awbRecipient
* @param float $insuredValue
* @param float $cashOnDeliveryAmount
* @param $insuredValue
* @param $cashOnDeliveryAmount
* @param CodCollectorType|null $cashOnDeliveryCollector
* @param ThirdPartyPickupEntityObject|null $thirdPartyPickup
* @param int[] $serviceTaxIds
* @param array $serviceTaxIds
* @param DeliveryIntervalServiceType|null $deliveryIntervalServiceType
* @param string|null $reference
* @param string|null $observation
* @param string|null $priceObservation
* @param string|null $clientObservation
* @param int|null $lockerId
* @param $reference
* @param $observation
* @param $priceObservation
* @param $clientObservation
* @param $lockerFirstMile
* @param $lockerLastMile
*/
public function __construct(
$pickupPointId,
Expand All @@ -149,7 +153,8 @@ public function __construct(
$observation = null,
$priceObservation = null,
$clientObservation = null,
$lockerId = null
$lockerFirstMile = null,
$lockerLastMile = null
) {
$this->pickupPointId = $pickupPointId;
$this->contactPersonId = $contactPersonId;
Expand All @@ -168,7 +173,8 @@ public function __construct(
$this->observation = $observation;
$this->priceObservation = $priceObservation;
$this->clientObservation = $clientObservation;
$this->lockerId = $lockerId;
$this->lockerFirstMile = $lockerFirstMile;
$this->lockerLastMile = $lockerLastMile;
}

/**
Expand All @@ -179,7 +185,7 @@ public function buildRequest()
// Calculate weight for all parcels.
$weight = 0;
array_map(
function (ParcelDimensionsObject $parcelDimensions) use (&$weight) {
static function (ParcelDimensionsObject $parcelDimensions) use (&$weight) {
$weight += $parcelDimensions->getWeight();
},
$this->parcelsDimensions
Expand Down Expand Up @@ -210,7 +216,7 @@ function (ParcelDimensionsObject $parcelDimensions) use (&$weight) {
'awbRecipient' => $this->awbRecipient->getFields(),
'parcels' => array_map(
// Build parcel fields from ParcelDimensionsObject.
function (ParcelDimensionsObject $parcelDimensions) {
static function (ParcelDimensionsObject $parcelDimensions) {
return [
'weight' => $parcelDimensions->getWeight(),
'width' => $parcelDimensions->getWidth(),
Expand All @@ -226,8 +232,12 @@ function (ParcelDimensionsObject $parcelDimensions) {
'clientObservation' => $this->clientObservation,
]);

if ($this->lockerId !== null) {
$body = array_merge($body, ['lockerId' => $this->lockerId]);
if ($this->lockerFirstMile !== null) {
$body = array_merge($body, ['lockerFirstMile' => $this->lockerFirstMile]);
}

if ($this->lockerLastMile !== null) {
$body = array_merge($body, ['lockerLastMile' => $this->lockerLastMile]);
}

return new SamedayRequest(
Expand Down Expand Up @@ -582,19 +592,39 @@ public function setClientObservation($clientObservation)
/**
* @return int|null
*/
public function getLockerId()
public function getLockerFirstMile()
{
return $this->lockerFirstMile;
}

/**
* @param $lockerFirstMile
*
* @return $this
*/
public function setLockerFirstMile($lockerFirstMile)
{
$this->lockerFirstMile = $lockerFirstMile;

return $this;
}

/**
* @return int|null
*/
public function getLockerLastMile()
{
return $this->lockerId;
return $this->lockerLastMile;
}

/**
* @param int|null $lockerId
* @param $lockerLastMile
*
* @return $this
*/
public function setLockerId($lockerId)
public function setLockerLastMile($lockerLastMile)
{
$this->lockerId = $lockerId;
$this->lockerLastMile = $lockerLastMile;

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sameday/Responses/SamedayPostAwbResponse.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(SamedayPostAwbRequest $request, SamedayRawResponse $
$this->cost = $json['awbCost'];

$this->parcels = array_map(
function (array $parcel) {
static function (array $parcel) {
return new ParcelObject($parcel['position'], $parcel['awbNumber']);
},
$json['parcels']
Expand Down
2 changes: 1 addition & 1 deletion src/Sameday/SamedayClient.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function sendRequest(SamedayRequest $request)

$url = $this->host . $request->getEndpoint();
if ($request->getQueryParams()) {
$params = http_build_query($request->getQueryParams(), null, '&');
$params = http_build_query($request->getQueryParams(), '', '&');
if ($params !== '') {
$url .= '?' . $params;
}
Expand Down
13 changes: 9 additions & 4 deletions tests/Requests/SamedayPostAwbRequestTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testConstructor()
'observation',
'priceObservation',
'clientObservation',
null,
10
);

Expand All @@ -65,7 +66,8 @@ public function testConstructor()
$this->assertEquals('observation', $request->getObservation());
$this->assertEquals('priceObservation', $request->getPriceObservation());
$this->assertEquals('clientObservation', $request->getClientObservation());
$this->assertEquals(10, $request->getLockerId());
$this->assertEquals(null, $request->getLockerFirstMile());
$this->assertEquals(10, $request->getLockerLastMile());
}

public function testSetGet()
Expand Down Expand Up @@ -105,7 +107,8 @@ public function testSetGet()
$request->setObservation('observation');
$request->setPriceObservation('priceObservation');
$request->setClientObservation('clientObservation');
$request->setLockerId(10);
$request->setLockerFirstMile(10);
$request->setLockerLastMile(10);

$this->assertEquals(10, $request->getPickupPointId());
$this->assertEquals(20, $request->getContactPersonId());
Expand All @@ -124,7 +127,8 @@ public function testSetGet()
$this->assertEquals('observation', $request->getObservation());
$this->assertEquals('priceObservation', $request->getPriceObservation());
$this->assertEquals('clientObservation', $request->getClientObservation());
$this->assertEquals(10, $request->getLockerId());
$this->assertEquals(10, $request->getLockerFirstMile());
$this->assertEquals(10, $request->getLockerLastMile());
}

public function testBuildRequestWithoutLockerId()
Expand Down Expand Up @@ -197,6 +201,7 @@ public function testBuildRequest()
'observation',
'priceObservation',
'clientObservation',
10,
10
);
$samedayRequest = $request->buildRequest();
Expand All @@ -205,6 +210,6 @@ public function testBuildRequest()
$this->assertTrue($samedayRequest->isNeedAuth());
$this->assertEquals('POST', $samedayRequest->getMethod());
$this->assertEquals('/api/awb', $samedayRequest->getEndpoint());
$this->assertEquals('pickupPoint=1&contactPerson=2&packageType=2&packageNumber=2&packageWeight=2&service=3&awbPayment=1&cashOnDelivery=110&cashOnDeliveryReturns=1&insuredValue=100&thirdPartyPickup=1&thirdParty%5Bname%5D=name&thirdParty%5BphoneNumber%5D=phone&thirdParty%5Baddress%5D=address&thirdParty%5BpersonType%5D=1&thirdParty%5Bcity%5D=1&thirdParty%5Bcounty%5D=2&thirdParty%5BcompanyName%5D=name&thirdParty%5BcompanyCui%5D=cui&thirdParty%5BcompanyOnrcNumber%5D=onrc&thirdParty%5BcompanyIban%5D=iban&thirdParty%5BcompanyBank%5D=bank&serviceTaxes%5B0%5D=11&serviceTaxes%5B1%5D=12&serviceTaxes%5B2%5D=13&deliveryInterval=1000&awbRecipient%5Bname%5D=name&awbRecipient%5BphoneNumber%5D=phone&awbRecipient%5Baddress%5D=address&awbRecipient%5BpersonType%5D=0&awbRecipient%5BcityString%5D=city&awbRecipient%5BcountyString%5D=county&awbRecipient%5BpostalCode%5D=postalCode&awbRecipient%5Bemail%5D=email&parcels%5B0%5D%5Bweight%5D=1&parcels%5B1%5D%5Bweight%5D=1&parcels%5B1%5D%5Bwidth%5D=2&parcels%5B1%5D%5Blength%5D=3&parcels%5B1%5D%5Bheight%5D=4&observation=observation&priceObservation=priceObservation&clientInternalReference=reference&clientObservation=clientObservation&lockerId=10', $samedayRequest->getBody()->getBody());
$this->assertEquals('pickupPoint=1&contactPerson=2&packageType=2&packageNumber=2&packageWeight=2&service=3&awbPayment=1&cashOnDelivery=110&cashOnDeliveryReturns=1&insuredValue=100&thirdPartyPickup=1&thirdParty%5Bname%5D=name&thirdParty%5BphoneNumber%5D=phone&thirdParty%5Baddress%5D=address&thirdParty%5BpersonType%5D=1&thirdParty%5Bcity%5D=1&thirdParty%5Bcounty%5D=2&thirdParty%5BcompanyName%5D=name&thirdParty%5BcompanyCui%5D=cui&thirdParty%5BcompanyOnrcNumber%5D=onrc&thirdParty%5BcompanyIban%5D=iban&thirdParty%5BcompanyBank%5D=bank&serviceTaxes%5B0%5D=11&serviceTaxes%5B1%5D=12&serviceTaxes%5B2%5D=13&deliveryInterval=1000&awbRecipient%5Bname%5D=name&awbRecipient%5BphoneNumber%5D=phone&awbRecipient%5Baddress%5D=address&awbRecipient%5BpersonType%5D=0&awbRecipient%5BcityString%5D=city&awbRecipient%5BcountyString%5D=county&awbRecipient%5BpostalCode%5D=postalCode&awbRecipient%5Bemail%5D=email&parcels%5B0%5D%5Bweight%5D=1&parcels%5B1%5D%5Bweight%5D=1&parcels%5B1%5D%5Bwidth%5D=2&parcels%5B1%5D%5Blength%5D=3&parcels%5B1%5D%5Bheight%5D=4&observation=observation&priceObservation=priceObservation&clientInternalReference=reference&clientObservation=clientObservation&lockerFirstMile=10&lockerLastMile=10', $samedayRequest->getBody()->getBody());
}
}

0 comments on commit 6852f7c

Please sign in to comment.