-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
299 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace ShoppinPal\Vend\Api\V2; | ||
|
||
use ShoppinPal\Vend\DataObject\Entity\V2\CollectionResult; | ||
use ShoppinPal\Vend\DataObject\Entity\V2\Sale; | ||
use YapepBase\Communication\CurlHttpRequest; | ||
|
||
/** | ||
* Implements the V2 Sales API | ||
*/ | ||
class Sales extends V2ApiAbstract | ||
{ | ||
|
||
/** | ||
* Returns a collection of sales. | ||
* | ||
* @param int $pageSize The number of items to return per page. | ||
* @param null $before The version to succeed the last returned version. | ||
* @param null $after The version to precede the first returned version | ||
* @param bool $includeDeleted If TRUE, deleted items will be returned as well. (required to synchronise deletions) | ||
* | ||
* @return CollectionResult | ||
*/ | ||
public function getCollection( | ||
$pageSize = 50, | ||
$before = null, | ||
$after = null, | ||
$includeDeleted = false | ||
) | ||
{ | ||
$params = [ | ||
'page_size' => $pageSize, | ||
]; | ||
|
||
if (!empty($before)) { | ||
$params['before'] = $before; | ||
} | ||
|
||
if (!empty($after)) { | ||
$params['after'] = $after; | ||
} | ||
|
||
if ($includeDeleted) { | ||
$params['deleted'] = 1; | ||
} | ||
|
||
$request = $this->getAuthenticatedRequestForUri('api/2.0/sales', $params); | ||
$request->setMethod(CurlHttpRequest::METHOD_GET); | ||
|
||
$result = $this->sendRequest($request, 'sale get collection'); | ||
|
||
$sales = []; | ||
|
||
foreach ($result['data'] as $sale) { | ||
$sales[] = new Sale($sale, Sale::UNKNOWN_PROPERTY_IGNORE); | ||
} | ||
|
||
return new CollectionResult( | ||
$result['version']['min'], $result['version']['max'], $sales | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace ShoppinPal\Vend\DataObject\Entity\V2; | ||
|
||
use ShoppinPal\Vend\DataObject\Entity\EntityDoAbstract; | ||
|
||
class Sale extends EntityDoAbstract | ||
{ | ||
|
||
const STATUS_OPEN = 'OPEN'; | ||
const STATUS_SAVED = 'SAVED'; | ||
const STATUS_CLOSED = 'CLOSED'; | ||
const STATUS_LAYBY = 'LAYBY'; | ||
const STATUS_LAYBY_CLOSED = 'LAYBY_CLOSED'; | ||
const STATUS_ONACCOUNT = 'ONACCOUNT'; | ||
const STATUS_ONACCOUNT_CLOSED = 'ONACCOUNT_CLOSED'; | ||
const STATUS_VOIDED = 'VOIDED'; | ||
|
||
protected $subEntities = [ | ||
'lineItems' => [ | ||
self::SUB_ENTITY_KEY_TYPE => self::SUB_ENTITY_TYPE_COLLECTION, | ||
self::SUB_ENTITY_KEY_CLASS => SaleLineItem::class, | ||
], | ||
'payments' => [ | ||
self::SUB_ENTITY_KEY_TYPE => self::SUB_ENTITY_TYPE_COLLECTION, | ||
self::SUB_ENTITY_KEY_CLASS => SalePayment::class, | ||
], | ||
'taxes' => [ | ||
self::SUB_ENTITY_KEY_TYPE => self::SUB_ENTITY_TYPE_COLLECTION, | ||
self::SUB_ENTITY_KEY_CLASS => SaleTax::class, | ||
], | ||
]; | ||
|
||
public $id; | ||
|
||
public $outletId; | ||
|
||
public $registerId; | ||
|
||
public $userId; | ||
|
||
public $customerId; | ||
|
||
public $invoiceNumber; | ||
|
||
public $status; | ||
|
||
public $note; | ||
|
||
public $shortCode; | ||
|
||
public $returnFor; | ||
|
||
public $totalPrice; | ||
|
||
public $totalTax; | ||
|
||
public $totalLoyalty; | ||
|
||
public $createdAt; | ||
|
||
public $updatedAt; | ||
|
||
public $saleDate; | ||
|
||
public $deletedAt; | ||
|
||
/** @var SaleLineItem[] */ | ||
public $lineItems = []; | ||
|
||
/** @var SalePayment[] */ | ||
public $payments = []; | ||
|
||
public $version; | ||
|
||
public $receiptNumber; | ||
|
||
/** @var SaleTax */ | ||
public $taxes = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace ShoppinPal\Vend\DataObject\Entity\V2; | ||
|
||
use ShoppinPal\Vend\DataObject\Entity\EntityDoAbstract; | ||
|
||
class SaleLineItem extends EntityDoAbstract | ||
{ | ||
|
||
protected $subEntities = [ | ||
'taxComponents' => [ | ||
self::SUB_ENTITY_KEY_TYPE => self::SUB_ENTITY_TYPE_COLLECTION, | ||
self::SUB_ENTITY_KEY_CLASS => SaleLineItemTaxComponent::class, | ||
], | ||
]; | ||
|
||
public $id; | ||
|
||
public $productId; | ||
|
||
public $taxId; | ||
|
||
public $discountTotal; | ||
|
||
public $discount; | ||
|
||
public $priceTotal; | ||
|
||
public $price; | ||
|
||
public $costTotal; | ||
|
||
public $cost; | ||
|
||
public $taxTotal; | ||
|
||
public $tax; | ||
|
||
public $quantity; | ||
|
||
public $loyaltyValue; | ||
|
||
public $note; | ||
|
||
public $priceSet; | ||
|
||
public $status; | ||
|
||
public $sequence; | ||
|
||
/** @var SaleLineItemTaxComponent[] */ | ||
public $taxComponents = []; | ||
|
||
public $unitCost; | ||
|
||
public $unitDiscount; | ||
|
||
public $unitLoyaltyValue; | ||
|
||
public $unitPrice; | ||
|
||
public $unitTax; | ||
|
||
public $totalCost; | ||
|
||
public $totalDiscount; | ||
|
||
public $totalLoyaltyValue; | ||
|
||
public $totalPrice; | ||
|
||
public $totalTax; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/ShoppinPal/Vend/DataObject/Entity/V2/SaleLineItemTaxComponent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace ShoppinPal\Vend\DataObject\Entity\V2; | ||
|
||
use ShoppinPal\Vend\DataObject\Entity\EntityDoAbstract; | ||
|
||
class SaleLineItemTaxComponent extends EntityDoAbstract | ||
{ | ||
|
||
public $rateId; | ||
|
||
public $totalTax; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace ShoppinPal\Vend\DataObject\Entity\V2; | ||
|
||
use ShoppinPal\Vend\DataObject\Entity\EntityDoAbstract; | ||
|
||
class SalePayment extends EntityDoAbstract | ||
{ | ||
|
||
public $id; | ||
|
||
public $registerId; | ||
|
||
public $outletId; | ||
|
||
public $retailerPaymentTypeId; | ||
|
||
/** @var int {@uses PaymentType::PAYMENT_TYPE_*} */ | ||
public $paymentTypeId; | ||
|
||
public $name; | ||
|
||
public $amount; | ||
|
||
public $paymentDate; | ||
|
||
public $deletedAt; | ||
|
||
// TODO readd this later | ||
// public $externalAttributes = []; | ||
|
||
public $sourceId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace ShoppinPal\Vend\DataObject\Entity\V2; | ||
|
||
use ShoppinPal\Vend\DataObject\Entity\EntityDoAbstract; | ||
|
||
class SaleTax extends EntityDoAbstract | ||
{ | ||
|
||
public $amount; | ||
|
||
public $id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters