Skip to content

Commit

Permalink
REENG-251 - Added encoding spot to location
Browse files Browse the repository at this point in the history
  • Loading branch information
michalblocinski authored and dzmitrybitsiutski committed May 16, 2024
1 parent 4bd3898 commit cf50bff
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 2.7.1
- Added encoding spot to location

## 2.7.0
- Added Spot entity
- Added SpotInfo Entity
Expand Down
44 changes: 44 additions & 0 deletions src/Paysera/WalletApi/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,7 @@ public function encodeLocation(Paysera_WalletApi_Entity_Location $object)
'status' => $object->getStatus(),
'services' => $services,
'public' => $object->getPublic(),
'spots' => $this->encodeSpots($object->getSpots()),
);
}

Expand Down Expand Up @@ -2523,4 +2524,47 @@ public function decodeSpotInfo(array $data)

return $spotInfo;
}

/**
* @var Paysera_WalletApi_Entity_Spot[] $spots
*
* @return array
*/
public function encodeSpots($spots) {
$spotsEncoded = [];
foreach ($spots as $spot) {
$spotsEncoded[] = $this->encodeSpot($spot);
}

return $spotsEncoded;
}

/**
* @var Paysera_WalletApi_Entity_Spot $spot
*
* @return array
*/
public function encodeSpot($spot) {
return [
'id' => $spot->getId(),
'status' => $spot->getStatus(),
'identifier' => $spot->getIdentifier(),
'place_info' => $this->encodeSpotInfo($spot->getSpotInfo())
];
}

/**
* @var Paysera_WalletApi_Entity_SpotInfo $spotInfo
*
* @return array
*/
public function encodeSpotInfo($spotInfo) {
return [
'title' => $spotInfo->getTitle(),
'description' => $spotInfo->getDescription(),
'address' => $spotInfo->getAddress(),
'logo_uri' => $spotInfo->getLogoUri(),
'location_id' => $spotInfo->getLocationId(),
];
}
}
121 changes: 121 additions & 0 deletions tests/Paysera/WalletApi/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use DateTime;
use InvalidArgumentException;
use Paysera_WalletApi_Entity_Location_DayWorkingHours;
use Paysera_WalletApi_Entity_Location_Price;
use Paysera_WalletApi_Entity_Spot;
use Paysera_WalletApi_Entity_Allowance;
use Paysera_WalletApi_Entity_FundsSource;
use Paysera_WalletApi_Entity_Limit;
Expand All @@ -22,6 +25,8 @@
use Paysera_WalletApi_Entity_Restrictions;
use Paysera_WalletApi_Entity_Search_Result;
use Paysera_WalletApi_Entity_MacCredentials;
use Paysera_WalletApi_Entity_SpotInfo;
use Paysera_WalletApi_Entity_Time;
use Paysera_WalletApi_Entity_Transaction;
use Paysera_WalletApi_Entity_User_Identity;
use Paysera_WalletApi_Exception_LogicException;
Expand Down Expand Up @@ -1687,6 +1692,7 @@ public function testDecodeLocation() {
]
];

/** @var Paysera_WalletApi_Entity_Location $location */
$location = $this->mapper->decodeLocation($data);

$this->assertInstanceOf(Paysera_WalletApi_Entity_Location::class, $location);
Expand Down Expand Up @@ -1756,6 +1762,121 @@ public function testDecodeLocation() {
$this->assertEquals(1, $spotInfo->getLocationId());
}

public function testEncodeLocation() {
// Create a location entity
$location = new Paysera_WalletApi_Entity_Location();
$location->setId(1);
$location->setTitle('Test Location');
$location->setDescription('This is a test location');
$location->setAddress('Test Address');
$location->setRadius(100);
$location->setLat(54.6872);
$location->setLng(25.2797);

// Add prices
$price1 = new Paysera_WalletApi_Entity_Location_Price();
$price1->setTitle('a');
$price1->markAsPrice();
$price1->setPrice(new Paysera_WalletApi_Entity_Money(10000, 'EUR'));
$location->addPrice($price1);

$price2 = new Paysera_WalletApi_Entity_Location_Price();
$price2->setTitle('b');
$price2->markAsPrice();
$price2->setPrice(new Paysera_WalletApi_Entity_Money(20000, 'USD'));
$location->addPrice($price2);

// Add working hours
$openingTime = new Paysera_WalletApi_Entity_Time('9', '0');
$closingTime = new Paysera_WalletApi_Entity_Time('17', '0');
$workingHours1 = new Paysera_WalletApi_Entity_Location_DayWorkingHours();
$workingHours1->markAsMonday();
$workingHours1->setOpeningTime($openingTime);
$workingHours1->setClosingTime($closingTime);
$location->addWorkingHours($workingHours1);

$workingHours2 = new Paysera_WalletApi_Entity_Location_DayWorkingHours();
$workingHours2->markAsTuesday();
$workingHours2->setOpeningTime($openingTime);
$workingHours2->setClosingTime($closingTime);
$location->addWorkingHours($workingHours2);

// Set images
$location->setImagePinOpen('http://example.com/pin_open.png');
$location->setImagePinClosed('http://example.com/pin_closed.png');

// Add services
$location->setServices([
'pay',
'cash_in',
'cash_out',
]);

// Set status and public
$location->setStatus('active');
$location->setPublic(true);

// Add a spot
$spot = new Paysera_WalletApi_Entity_Spot();
$spot->setId(1);
$spot->setStatus('active');
$spot->setIdentifier('spot1');

// Set spot info
$spotInfo = new Paysera_WalletApi_Entity_SpotInfo();
$spotInfo->setTitle('Spot 1');
$spotInfo->setDescription('This is spot 1');
$spotInfo->setAddress('Spot 1 Address');
$spotInfo->setLogoUri('http://example.com/spot1.png');
$spotInfo->setLocationId(1);
$spot->setSpotInfo($spotInfo);

$location->setSpots([$spot]);

// Encode the location entity
$encodedLocation = $this->mapper->encodeLocation($location);

$expectedData = [
'id' => 1,
'title' => 'Test Location',
'description' => 'This is a test location',
'address' => 'Test Address',
'radius' => 100,
'lat' => 54.6872,
'lng' => 25.2797,
'prices' => [
['title' => 'a', 'type' => 'price', 'price' => ['amount' => 1000000, 'currency' => 'EUR']],
['title' => 'b', 'type' => 'price', 'price' => ['amount' => 2000000, 'currency' => 'USD']]
],
'working_hours' => [
'monday' => ['opening_time' => '9:0', 'closing_time' => '17:0'],
'tuesday' => ['opening_time' => '9:0', 'closing_time' => '17:0']
],
'services' => [
'pay' => ['available' => true],
'cash_in' => ['available' => true],
'cash_out' => ['available' => true]
],
'status' => 'active',
'public' => true,
'spots' => [
[
'id' => 1,
'status' => 'active',
'identifier' => 'spot1',
'place_info' => [
'title' => 'Spot 1',
'description' => 'This is spot 1',
'address' => 'Spot 1 Address',
'logo_uri' => 'http://example.com/spot1.png',
'location_id' => 1
]
]
]
];
$this->assertEquals($expectedData, $encodedLocation);
}

private function setProperty($object, $property, $value)
{
$reflectionProperty = new ReflectionProperty($object, $property);
Expand Down

0 comments on commit cf50bff

Please sign in to comment.