* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @copyright PayPal */ namespace PaypalAddons\services; use Configuration; use MethodEC; use MethodMB; use MethodPPP; use PaypalAddons\classes\AbstractMethodPaypal; use PaypalAddons\classes\Constants\WebHookType; class StatusMapping { /** * @return string $transactionStatus * @return int */ public function getPsOrderStatusByTransaction($transactionStatus) { $orderStatus = 0; switch ($transactionStatus) { case 'Completed': $orderStatus = $this->getAcceptedStatus(); break; case 'Refunded': $orderStatus = $this->getRefundStatus(); break; case 'Failed': $orderStatus = $this->getFailedStatus(); break; case 'Reversed': $orderStatus = $this->getFailedStatus(); break; case 'Denied': $orderStatus = $this->getFailedStatus(); break; } return $orderStatus; } public function getAcceptedStatus() { if ($this->isCustomize()) { if ($this->isModeSale()) { return (int) Configuration::get('PAYPAL_OS_ACCEPTED_TWO'); } return (int) Configuration::get('PAYPAL_OS_ACCEPTED'); } return (int) Configuration::get('PS_OS_PAYMENT'); } public function getRefundStatus($method = null) { if (is_null($method)) { $method = AbstractMethodPaypal::load(); } if ($this->isCustomize()) { if ($method instanceof MethodMB) { return (int) Configuration::get('PAYPAL_OS_REFUNDED_PAYPAL'); } return (int) Configuration::get('PAYPAL_OS_REFUNDED'); } return (int) Configuration::get('PS_OS_REFUND'); } public function getFailedStatus() { if ($this->isCustomize()) { return (int) Configuration::get('PAYPAL_OS_VALIDATION_ERROR'); } return (int) Configuration::get('PS_OS_CANCELED'); } public function getCanceledStatus($method = null) { if (is_null($method)) { $method = AbstractMethodPaypal::load(); } if ($this->isCustomize()) { if ($method instanceof MethodEC) { if ($this->isModeSale()) { return (int) Configuration::get('PAYPAL_OS_CANCELED'); } return (int) Configuration::get('PAYPAL_OS_CAPTURE_CANCELED'); } } return (int) Configuration::get('PS_OS_CANCELED'); } public function getWaitValidationStatus() { if ($this->isCustomize()) { return (int) Configuration::get('PAYPAL_OS_WAITING_VALIDATION'); } return (int) Configuration::get('PAYPAL_OS_WAITING'); } public function isCustomize() { return (bool) Configuration::get('PAYPAL_CUSTOMIZE_ORDER_STATUS'); } public function isModeSale($method = null) { if (is_null($method)) { $method = AbstractMethodPaypal::load(); } if ($method instanceof MethodPPP) { return true; } if ($method instanceof MethodMB) { return true; } return Configuration::get('PAYPAL_API_INTENT') == 'sale'; } /** * @param string $eventType * * @return int */ public function getPsOrderStatusByEventType($eventType) { $orderStatus = 0; switch ($eventType) { case WebHookType::CAPTURE_COMPLETED: $orderStatus = $this->getAcceptedStatus(); break; case WebHookType::CAPTURE_REFUNDED: $orderStatus = $this->getRefundStatus(); break; case WebHookType::CAPTURE_REVERSED: $orderStatus = $this->getRefundStatus(); break; case WebHookType::CAPTURE_DENIED: $orderStatus = $this->getCanceledStatus(); break; case WebHookType::AUTHORIZATION_VOIDED: $orderStatus = $this->getCanceledStatus(); break; } return $orderStatus; } }