<?php
namespace Plugin\np42\Entity;
use Doctrine\ORM\Mapping as ORM;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Order;
use Plugin\np42\Service\PaymentApi\Cancel;
use Plugin\np42\Service\PaymentApi\Capture;
use Plugin\np42\Service\PaymentApi\Change;
use Plugin\np42\Service\PaymentApi\Register;
use Plugin\np42\ValueObject\ServiceType;
/**
* OrderAtone
*
* @ORM\Table(name="plg_np42_order_atone")
* @ORM\Entity(repositoryClass="Plugin\np42\Repository\OrderAtoneRepository")
*/
class OrderAtone
{
/** atone決済状況 オーソリ @var int */
const ATONE_STATUS_AUTH = 1;
/** atone決済状況 売上 @var int */
const ATONE_STATUS_CAPTURE = 2;
/** atone決済状況 キャンセル @var int */
const ATONE_STATUS_CANCEL = 3;
/** atone決済状況 仮登録 @var int */
const ATONE_STATUS_TEMPORARY_REGISTER = 4;
/**
* atone決済状況
* @var array
*/
const ATONE_STATUS_LIST = [
self::ATONE_STATUS_AUTH => 'オーソリ',
self::ATONE_STATUS_CAPTURE => '売上',
self::ATONE_STATUS_CANCEL => 'キャンセル',
// self::ATONE_STATUS_TEMPORARY_REGISTER => '仮登録',
];
/**
* atone サービス種別
* @var array
*/
const ATONE_SERVICE_TYPE_LIST = [
ServiceType::TYPE_ATONE => '翌月',
ServiceType::TYPE_TSU_DO_ATONE => 'つど',
];
/**
* @var int
*
* @ORM\Column(name="id", type="integer", options={"unsigned":true})
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var Order
* @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderAtone")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="order_id", referencedColumnName="id")
* })
*/
private $Order;
/**
* @var int $atone_status_id atone受注ステータスID
* @ORM\Column(name="atone_status_id", type="text", options={"default":"1", "comment":"atone受注ステータスID"})
*/
private $atone_status_id;
/**
* @var string
* @ORM\Column(name="atone_service_type", type="text", nullable=true, options={"default":"", "comment": "atone サービス種別 01=atone翌月払い、04=atoneつど後払い"})
*/
private $atone_service_type = '';
/**
* @var string $company_code 加盟企業コード
* @ORM\Column(name="company_code", type="text", options={"default":"", "comment": "加盟企業コード"})
*/
private $company_code = '';
/**
* @var string
* @ORM\Column(name="shop_branch_code", type="text", options={"default":"", "comment": "店舗支店コード"})
*/
private $shop_branch_code = '';
/**
* @var string $atone_module_authentication_token
*
* @ORM\Column(name="atone_module_authentication_token", type="text", options={"default":"", "comment": "決済認証トークン"})
*/
private $atone_module_authentication_token = '';
/**
* @var string
* @ORM\Column(name="shop_transaction_no", type="text", options={"default":"", "comment": "加盟店取引ID 半角英数字"})
*/
private $shop_transaction_no = '';
/**
* @var string $transaction_id
* @ORM\Column(name="transaction_id", type="text", options={"default":"", "comment": "取引ID format:YYMMDDXXXXXX"})
*/
private $transaction_id = '';
/**
* @var string $authorization_result 与信結果
* @ORM\Column(name="authorization_result", type="text", options={"default":"", "comment": "与信結果"})
*/
private $authorization_result = '';
/**
* @var string $authorization_result_ng_reason 与信NG事由
* @ORM\Column(name="authorization_result_ng_reason", type="text", options={"default":"", "comment": "与信NG事由"})
*/
private $authorization_result_ng_reason = '';
/**
* @var string
* @ORM\Column(name="authori_hold", type="text", options={"default":"", "comment": "与信保留事由"})
*/
private $authori_hold = '';
/**
* @var string $amount atone顧客請求金額
* @ORM\Column(name="amount", type="integer", options={"default":0, "comment": "顧客請求金額"})
*/
private $amount;
/**
* md5でハッシュ化された受注情報
*
* @var string $order_atone_detail_md5
*
* @ORM\Column(name="order_atone_detail_md5", type="text", length=65532, options={"default":"", "comment": "atone md5でハッシュ化された受注情報"})
*/
private $order_atone_detail_md5 = '';
/**
* @var string $order_diff
*
* @ORM\Column(name="order_diff", type="text", nullable=true, options={"default":"", "comment": "atone 差分情報"})
*/
private $order_diff = '';
/**
* @var \DateTime
*
* @ORM\Column(name="create_date", type="datetimetz", options={"comment": "作成日時"})
*/
private $create_date;
/**
* @var \DateTime
*
* @ORM\Column(name="update_date", type="datetimetz", options={"comment": "更新日時"})
*/
private $update_date;
public function getOrder()
{
return $this->Order;
}
public function setOrder(Order $Order)
{
$this->Order = $Order;
return $this;
}
/**
* Get atone_status_id
*
* @return integer
*/
public function getAtoneStatusId()
{
return $this->atone_status_id;
}
/**
* Set atone_status_id
*
* @param integer $atone_status_id
*
* @return OrderAtone
*/
public function setAtoneStatusId(int $atone_status_id)
{
$this->atone_status_id = $atone_status_id;
return $this;
}
/**
* @return string|null
*/
public function getAtoneServiceType(): ?string
{
return $this->atone_service_type;
}
/**
* @param string|null $atone_service_type
*/
public function setAtoneServiceType(?string $atone_service_type): self
{
$this->atone_service_type = $atone_service_type;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getCompanyCode(): ?string
{
return $this->company_code;
}
public function setCompanyCode(string $company_code): self
{
$this->company_code = $company_code;
return $this;
}
public function getShopBranchCode(): ?string
{
return $this->shop_branch_code;
}
public function setShopBranchCode(string $shop_branch_code): self
{
$this->shop_branch_code = $shop_branch_code;
return $this;
}
public function getAtoneModuleAuthenticationToken(): ?string
{
return $this->atone_module_authentication_token;
}
public function setAtoneModuleAuthenticationToken(string $atone_module_authentication_token): self
{
$this->atone_module_authentication_token = $atone_module_authentication_token;
return $this;
}
public function getShopTransactionNo(): ?string
{
return $this->shop_transaction_no;
}
public function setShopTransactionNo(string $shop_transaction_no): self
{
$this->shop_transaction_no = $shop_transaction_no;
return $this;
}
public function getTransactionId(): ?string
{
return $this->transaction_id;
}
public function setTransactionId(string $transaction_id): self
{
$this->transaction_id = $transaction_id;
return $this;
}
public function getAuthorizationResult(): ?string
{
return $this->authorization_result;
}
public function setAuthorizationResult(string $authorization_result): self
{
$this->authorization_result = $authorization_result;
return $this;
}
public function getAuthorizationResultNgReason(): ?string
{
return $this->authorization_result_ng_reason;
}
public function setAuthorizationResultNgReason(string $authorization_result_ng_reason): self
{
$this->authorization_result_ng_reason = $authorization_result_ng_reason;
return $this;
}
public function getAuthoriHold(): ?string
{
return $this->authori_hold;
}
public function setAuthoriHold(string $authori_hold): self
{
$this->authori_hold = $authori_hold;
return $this;
}
/**
* @return string
*/
public function getAmount(): string
{
return $this->amount;
}
/**
* @param string $amount
*/
public function setAmount(string $amount): self
{
$this->amount = $amount;
return $this;
}
/**
* Set createDate.
*
* @param \DateTime $createDate
*
* @return $this
*/
public function setCreateDate($createDate): self
{
$this->create_date = $createDate;
return $this;
}
/**
* Get createDate.
*
* @return \DateTime
*/
public function getCreateDate()
{
return $this->create_date;
}
/**
* Set updateDate.
*
* @param \DateTime $updateDate
*
* @return $this
*/
public function setUpdateDate($updateDate): self
{
$this->update_date = $updateDate;
return $this;
}
/**
* Get updateDate.
*
* @return \DateTime
*/
public function getUpdateDate()
{
return $this->update_date;
}
public function getOrderAtoneDetailMd5(): string
{
return $this->order_atone_detail_md5;
}
public function setOrderAtoneDetailMd5(string $order_atone_detail_md5): self
{
$this->order_atone_detail_md5 = $order_atone_detail_md5;
return $this;
}
/**
* @return string|null
*/
public function getOrderDiff(): ?string
{
return $this->order_diff;
}
/**
* @param string|null $order_diff
*/
public function setOrderDiff(?string $order_diff): self
{
$this->order_diff = $order_diff;
return $this;
}
public function getCancelRequestAction(): string
{
// 取引キャンセル
if ($this->getAtoneStatusId() != self::ATONE_STATUS_CANCEL) {
return Cancel::__REQUEST_ACTION;
}
return '';
}
public function getSubmitRequestAction(): string
{
/** * @var \Eccube\Entity\Order $Order */
$Order = $this->getOrder();
// 取引登録
// 売上確定
if ($this->getOrderAtoneDetailMd5() === $Order->getOrderAtoneDetailMd5()
&& $Order->getOrderStatus()->getId() != OrderStatus::CANCEL
&& $this->getAtoneStatusId() != self::ATONE_STATUS_CAPTURE
&& $this->getAtoneStatusId() != self::ATONE_STATUS_CANCEL
// 与信NG事由がない
&& empty($this->getAuthorizationResultNgReason())
// 与信保留事由がない
&& empty($this->getAuthoriHold())
) {
return Capture::__REQUEST_ACTION;
}
// 取引更新
if ($this->getOrderAtoneDetailMd5() != $Order->getOrderAtoneDetailMd5()
&& $Order->getOrderStatus()->getId() != OrderStatus::CANCEL
&& $this->getAtoneStatusId() != self::ATONE_STATUS_CAPTURE
&& $this->getAtoneStatusId() != self::ATONE_STATUS_CANCEL
) {
return Change::__REQUEST_ACTION;
}
return '';
}
}