Module Maintenance + création du module Recette
This commit is contained in:
37
local/modules/PayPlugModule/Event/Notification/PaymentNotificationEvent.php
Executable file
37
local/modules/PayPlugModule/Event/Notification/PaymentNotificationEvent.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Event\Notification;
|
||||
|
||||
use Payplug\Resource\Payment;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
class PaymentNotificationEvent extends ActionEvent
|
||||
{
|
||||
const PAYMENT_NOTIFICATION_EVENT = "payplugmodule_payment_notification_event";
|
||||
|
||||
/** @var Payment */
|
||||
protected $resource;
|
||||
|
||||
public function __construct(Payment $resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Payment
|
||||
*/
|
||||
public function getResource(): Payment
|
||||
{
|
||||
return $this->resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Payment $resource
|
||||
* @return PaymentNotificationEvent
|
||||
*/
|
||||
public function setResource(Payment $resource): PaymentNotificationEvent
|
||||
{
|
||||
$this->resource = $resource;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
37
local/modules/PayPlugModule/Event/Notification/RefundNotificationEvent.php
Executable file
37
local/modules/PayPlugModule/Event/Notification/RefundNotificationEvent.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Event\Notification;
|
||||
|
||||
use Payplug\Resource\Refund;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
class RefundNotificationEvent extends ActionEvent
|
||||
{
|
||||
const REFUND_NOTIFICATION_EVENT = "payplugmodule_refund_notification_event";
|
||||
|
||||
/** @var Refund */
|
||||
protected $resource;
|
||||
|
||||
public function __construct(Refund $resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Refund
|
||||
*/
|
||||
public function getResource(): Refund
|
||||
{
|
||||
return $this->resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Refund $resource
|
||||
* @return RefundNotificationEvent
|
||||
*/
|
||||
public function setResource(Refund $resource): RefundNotificationEvent
|
||||
{
|
||||
$this->resource = $resource;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
37
local/modules/PayPlugModule/Event/Notification/UnknownNotificationEvent.php
Executable file
37
local/modules/PayPlugModule/Event/Notification/UnknownNotificationEvent.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Event\Notification;
|
||||
|
||||
use Payplug\Resource\IVerifiableAPIResource;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
class UnknownNotificationEvent extends ActionEvent
|
||||
{
|
||||
const UNKNOWN_NOTIFICATION_EVENT = "payplugmodule_unknown_notification_event";
|
||||
|
||||
/** @var IVerifiableAPIResource */
|
||||
protected $resource;
|
||||
|
||||
public function __construct(IVerifiableAPIResource $resource)
|
||||
{
|
||||
$this->resource = $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IVerifiableAPIResource
|
||||
*/
|
||||
public function getResource(): IVerifiableAPIResource
|
||||
{
|
||||
return $this->resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IVerifiableAPIResource $resource
|
||||
* @return UnknownNotificationEvent
|
||||
*/
|
||||
public function setResource(IVerifiableAPIResource $resource): UnknownNotificationEvent
|
||||
{
|
||||
$this->resource = $resource;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
1605
local/modules/PayPlugModule/Event/PayPlugPaymentEvent.php
Executable file
1605
local/modules/PayPlugModule/Event/PayPlugPaymentEvent.php
Executable file
File diff suppressed because it is too large
Load Diff
249
local/modules/PayPlugModule/Event/PayPlugProduct.php
Normal file
249
local/modules/PayPlugModule/Event/PayPlugProduct.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Event;
|
||||
|
||||
use PayPlugModule\Model\PayPlugModuleDeliveryType;
|
||||
use PayPlugModule\PayPlugModule;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\Base\OrderProduct;
|
||||
use Thelia\Model\Base\OrderProductTax;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class PayPlugProduct
|
||||
{
|
||||
/** @var string */
|
||||
protected $brand;
|
||||
|
||||
/** @var string */
|
||||
protected $expectedDeliveryDate;
|
||||
|
||||
/** @var string */
|
||||
protected $deliveryLabel;
|
||||
|
||||
/** @var string */
|
||||
protected $deliveryType;
|
||||
|
||||
/** @var string */
|
||||
protected $merchantItemId;
|
||||
|
||||
/** @var string */
|
||||
protected $name;
|
||||
|
||||
/** @var integer */
|
||||
protected $price;
|
||||
|
||||
/** @var integer */
|
||||
protected $quantity;
|
||||
|
||||
/** @var integer */
|
||||
protected $totalAmount;
|
||||
|
||||
public function buildFromOrderProduct(OrderProduct $orderProduct, PayPlugModuleDeliveryType $payPlugModuleDeliveryType = null)
|
||||
{
|
||||
$storeName = ConfigQuery::read(
|
||||
'store_name',
|
||||
Translator::getInstance()->trans(
|
||||
'Unknown',
|
||||
[],
|
||||
PayPlugModule::DOMAIN_NAME
|
||||
)
|
||||
);
|
||||
|
||||
$deliveryType = $payPlugModuleDeliveryType !== null ? $payPlugModuleDeliveryType->getDeliveryType() : 'carrier';
|
||||
// Brand can't be find from order product but it's required so set store name as brand or "Unknown"
|
||||
$this->setBrand($storeName);
|
||||
$this->setExpectedDeliveryDate(date('Y-m-d'));
|
||||
$this->setDeliveryLabel($storeName);
|
||||
$this->setDeliveryType($deliveryType);
|
||||
$this->setMerchantItemId($orderProduct->getId());
|
||||
$this->setName($orderProduct->getTitle());
|
||||
|
||||
$orderProductTaxes = $orderProduct->getOrderProductTaxes();
|
||||
$tax = array_reduce(
|
||||
iterator_to_array($orderProductTaxes),
|
||||
function ($accumulator, OrderProductTax $orderProductTax) {
|
||||
return $accumulator + $orderProductTax->getAmount();
|
||||
},
|
||||
0
|
||||
);
|
||||
$promoTax = array_reduce(
|
||||
iterator_to_array($orderProductTaxes),
|
||||
function ($accumulator, OrderProductTax $orderProductTax) {
|
||||
return $accumulator + $orderProductTax->getPromoAmount();
|
||||
},
|
||||
0
|
||||
);
|
||||
|
||||
$taxedPrice = round((float) $orderProduct->getPrice() + $tax, 2);
|
||||
$taxedPromoPrice = round((float) $orderProduct->getPromoPrice() + $promoTax, 2);
|
||||
|
||||
$price = $orderProduct->getWasInPromo() ? $taxedPromoPrice : $taxedPrice;
|
||||
$this->setPrice($price * 100);
|
||||
$this->setQuantity($orderProduct->getQuantity());
|
||||
$this->setTotalAmount($price * $orderProduct->getQuantity() * 100);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBrand()
|
||||
{
|
||||
return $this->brand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $brand
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setBrand(string $brand): PayPlugProduct
|
||||
{
|
||||
$this->brand = $brand;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getExpectedDeliveryDate()
|
||||
{
|
||||
return $this->expectedDeliveryDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expectedDeliveryDate
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setExpectedDeliveryDate(string $expectedDeliveryDate): PayPlugProduct
|
||||
{
|
||||
$this->expectedDeliveryDate = $expectedDeliveryDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDeliveryLabel()
|
||||
{
|
||||
return $this->deliveryLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $deliveryLabel
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setDeliveryLabel(string $deliveryLabel): PayPlugProduct
|
||||
{
|
||||
$this->deliveryLabel = $deliveryLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDeliveryType()
|
||||
{
|
||||
return $this->deliveryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $deliveryType
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setDeliveryType(string $deliveryType): PayPlugProduct
|
||||
{
|
||||
$this->deliveryType = $deliveryType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMerchantItemId()
|
||||
{
|
||||
return $this->merchantItemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $merchantItemId
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setMerchantItemId(string $merchantItemId): PayPlugProduct
|
||||
{
|
||||
$this->merchantItemId = $merchantItemId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setName(string $name): PayPlugProduct
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $price
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setPrice(int $price): PayPlugProduct
|
||||
{
|
||||
$this->price = $price;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getQuantity()
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $quantity
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setQuantity(int $quantity): PayPlugProduct
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAmount()
|
||||
{
|
||||
return $this->totalAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $totalAmount
|
||||
* @return PayPlugProduct
|
||||
*/
|
||||
public function setTotalAmount(int $totalAmount): PayPlugProduct
|
||||
{
|
||||
$this->totalAmount = $totalAmount;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user