関数
Listener::listen()
説明 説明
If the IPN is valid, the associated Welcart order object is updated
ファイル: src/IPN/Listener.php
public function listen() {
$body = file_get_contents('php://input');
$message = json_decode($body, true);
if (empty($message)) {
return;
}
if (!isset($message['Message'])) {
return;
}
$response = json_decode($message['Message'], true);
if (!isset($response['ObjectType']) || !isset($response['ObjectId'])) {
return;
}
$opts = $this->module->getActingOpts();
$opts['ipn_verified'] = true;
$this->module->updateActingOpts($opts);
switch ($response['ObjectType']) {
case EventNames::CHARGE:
$orderId = $this->getOrderIdFromChargeId($response['ObjectId']);
if ($orderId !== null) {
$order = new Models\OrderMeta($orderId);
if (!in_array($response['NotificationId'], $order->getIpnNotificationIds(), true)) {
$order->updateNotificationIds($response['NotificationId']);
$this->updateChargeState($order);
}
}
break;
case EventNames::REFUND:
$orderId = $this->getOrderIdFromRefundId($response['ObjectId']);
if ($orderId !== null) {
$order = new Models\OrderMeta($orderId);
if (!in_array($response['NotificationId'], $order->getIpnNotificationIds(), true)) {
$order->updateNotificationIds($response['NotificationId']);
$this->updateRefundState($order);
}
}
break;
}
}