クラス
State
CheckoutSession stateソース ソース
ファイル: src/Models/CheckoutSession/State.php
class State extends ErrorStore
{
const OPEN = 'Open';
const CANCELED = 'Canceled';
const COMPLETED = 'Completed';
/**
* `statusDetails`'s `state` key value
*
* @var string
*/
private $state;
/**
* `statusDetails`'s `reasonCode` key value
*
* @var string|null
*/
private $reasonCode;
/**
* `statusDetails`'s `reasonDescription` key value
*
* @var string|null
*/
private $reasonDescription;
/**
* Initializes a `AmazonOrderState` object
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @param string $state
* @param string|null $reasonCode
* @param string|null $reasonDescription
* @return void
*/
public function __construct($state, $reasonCode = null, $reasonDescription = null) {
$this->state = $state;
$this->reasonCode = $reasonCode;
$this->reasonDescription = $reasonDescription;
parent::__construct();
$this->populate();
}
/**
* Returns `GenericError` instance created from a `Canceled` state.
*
* This method returns an `UNKNOWN_ERROR` `GenericError` instance if the state
* is not canceled.
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return GenericError
*/
public function getErrorResponseFromCanceledState() {
$error = $this->getErrorResponse(self::UNKNOWN_ERROR);
if ($this->state !== self::CANCELED) {
return $error;
}
return $this->getErrorResponse($this->reasonCode, [$this->reasonDescription]);
}
/**
* Returns `true` if state is 'Open', `false` otherwise
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return bool
*/
public function isOpen() {
return $this->state === self::OPEN;
}
/**
* Returns `true` if state is 'Completed', `false` otherwise
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return bool
*/
public function isCompleted() {
return $this->state === self::COMPLETED;
}
/**
* Returns `true` if state is 'Canceled', `false` otherwise
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return bool
*/
public function isCanceled() {
return $this->state === self::CANCELED;
}
/**
* Getter for `state`
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return string
*/
public function getState() {
return $this->state;
}
/**
* Getter for `reasonCode`
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return string|null
*/
public function getReasonCode() {
return $this->reasonCode;
}
/**
* Getter for `reasonDescription`
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return string|null
*/
public function getReasonDescription() {
return $this->reasonDescription;
}
/**
* `CheckoutSession` specific errors for a `Canceled` state
*
* @author Evan D Shaw <evandanielshaw@gmail.com>
* @return void
* @throws InvalidArgumentException Thrown if the `errorcode` is already added.
*/
public function populate() {
$this->addError(new GenericError(
CanceledReasonCodes::BUYER_CANCELED,
'BUYER_CANCELED',
400,
function ($message) {
return $message;
},
__('The purchase was canceled', 'wcexaap')
));
$this->addError(new GenericError(
CanceledReasonCodes::EXPIRED,
'EXPIRED',
400,
function ($message) {
return $message;
},
__('The checkout session has expired. Please try again', 'wcexaap')
));
$this->addError(new GenericError(
CanceledReasonCodes::AMAZON_CANCELED,
'AMAZON_CANCELED',
503,
function ($message) {
return $message;
},
__('Amazon canceled the purchase due to service unavailability.', 'wcexaap')
));
$this->addError(new GenericError(
CanceledReasonCodes::DECLINED,
'DECLINED',
403,
function ($message) {
return $message;
},
__('The purchase was declined by Amazon.', 'wcexaap')
));
}
}
- __construct — Initializes a `AmazonOrderState` object
- getErrorResponseFromCanceledState — Returns `GenericError` instance created from a `Canceled` state.
- getReasonCode — Getter for `reasonCode`
- getReasonDescription — Getter for `reasonDescription`
- getState — Getter for `state`
- isCanceled — Returns `true` if state is 'Canceled', `false` otherwise
- isCompleted — Returns `true` if state is 'Completed', `false` otherwise
- isOpen — Returns `true` if state is 'Open', `false` otherwise
- populate — `CheckoutSession` specific errors for a `Canceled` state