-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from alma/release/v2.5.0
Release v2.5.0
- Loading branch information
Showing
12 changed files
with
798 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
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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
src/Entities/DTO/MerchantBusinessEvent/AbstractBusinessEvent.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,22 @@ | ||
<?php | ||
|
||
namespace Alma\API\Entities\DTO\MerchantBusinessEvent; | ||
|
||
abstract class AbstractBusinessEvent | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $eventType; | ||
|
||
/** | ||
* Get Event Type for merchant business event | ||
* | ||
* @return string | ||
*/ | ||
public function getEventType() | ||
{ | ||
return $this->eventType; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/Entities/DTO/MerchantBusinessEvent/CartInitiatedBusinessEvent.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,36 @@ | ||
<?php | ||
|
||
namespace Alma\API\Entities\DTO\MerchantBusinessEvent; | ||
|
||
use Alma\API\Exceptions\ParametersException; | ||
|
||
class CartInitiatedBusinessEvent extends AbstractBusinessEvent | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $cartId; | ||
|
||
/** | ||
* @param string $cartId | ||
* @throws ParametersException | ||
*/ | ||
public function __construct($cartId) | ||
{ | ||
$this->eventType = 'cart_initiated'; | ||
if(empty($cartId) || !is_string($cartId)) { | ||
throw new ParametersException('CartId must be a string'); | ||
} | ||
$this->cartId = $cartId; | ||
} | ||
|
||
/** | ||
* Get Cart Id | ||
* | ||
* @return string | ||
*/ | ||
public function getCartId() | ||
{ | ||
return $this->cartId; | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
src/Entities/DTO/MerchantBusinessEvent/OrderConfirmedBusinessEvent.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,151 @@ | ||
<?php | ||
|
||
namespace Alma\API\Entities\DTO\MerchantBusinessEvent; | ||
|
||
|
||
use Alma\API\Exceptions\ParametersException; | ||
|
||
class OrderConfirmedBusinessEvent extends AbstractBusinessEvent | ||
{ | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $almaP1XStatus; | ||
/** | ||
* @var bool | ||
*/ | ||
private $almaBNPLStatus; | ||
/** | ||
* @var bool | ||
*/ | ||
private $wasBNPLEligible; | ||
/** | ||
* @var string | ||
*/ | ||
private $orderId; | ||
/** | ||
* @var string | ||
*/ | ||
private $cartId; | ||
/** | ||
* @var string | null | ||
*/ | ||
private $almaPaymentId; | ||
|
||
|
||
/** | ||
* For non alma payment, almaPaymentId should be null | ||
* For Alma payment, almaPaymentId should be a string | ||
* | ||
* @param bool $isAlmaP1X | ||
* @param bool $isAlmaBNPL | ||
* @param bool $wasBNPLEligible | ||
* @param string $orderId | ||
* @param string $cartId | ||
* @param string | null $almaPaymentId | ||
* @throws ParametersException | ||
*/ | ||
public function __construct($isAlmaP1X, $isAlmaBNPL, $wasBNPLEligible, $orderId, $cartId, $almaPaymentId = null) | ||
{ | ||
$this->eventType = 'order_confirmed'; | ||
$this->almaP1XStatus = $isAlmaP1X; | ||
$this->almaBNPLStatus = $isAlmaBNPL; | ||
$this->wasBNPLEligible = $wasBNPLEligible; | ||
$this->orderId = $orderId; | ||
$this->cartId = $cartId; | ||
$this->almaPaymentId = $almaPaymentId; | ||
$this->validateData(); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isAlmaP1X() | ||
{ | ||
return $this->almaP1XStatus; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isAlmaBNPL() | ||
{ | ||
return $this->almaBNPLStatus; | ||
} | ||
|
||
/** | ||
* Was eligible at the time of payment | ||
* | ||
* @return bool | ||
*/ | ||
public function wasBNPLEligible() | ||
{ | ||
return $this->wasBNPLEligible; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getOrderId() | ||
{ | ||
return $this->orderId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCartId() | ||
{ | ||
return $this->cartId; | ||
} | ||
|
||
/** | ||
* @return string | null | ||
*/ | ||
public function getAlmaPaymentId() | ||
{ | ||
return $this->almaPaymentId; | ||
} | ||
|
||
/** | ||
* Check if it is an Alma payment | ||
* | ||
* @return bool | ||
*/ | ||
public function isAlmaPayment() | ||
{ | ||
return $this->almaP1XStatus || $this->almaBNPLStatus; | ||
} | ||
|
||
/** | ||
* @return void | ||
* @throws ParametersException | ||
*/ | ||
protected function validateData() | ||
{ | ||
if( | ||
!is_bool($this->almaP1XStatus) || | ||
!is_bool($this->almaBNPLStatus) || | ||
!is_bool($this->wasBNPLEligible) || | ||
(!is_string($this->orderId) || empty($this->orderId)) || | ||
(!is_string($this->cartId) || empty($this->cartId)) || | ||
// Alma payment id should be absent for non Alma payments | ||
(!$this->isAlmaPayment() && !is_null($this->almaPaymentId)) | ||
) | ||
{ | ||
throw new ParametersException('Invalid data type in OrderConfirmedBusinessEvent constructor'); | ||
} | ||
|
||
//Alma payment id for Alma payment, Must be a string | ||
if( | ||
$this->isAlmaPayment() && | ||
(!is_string($this->almaPaymentId) || empty($this->almaPaymentId)) | ||
) | ||
{ | ||
throw new ParametersException('Alma payment id is mandatory for Alma payment'); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.