<?php

namespace KnitPayUPI\Gateways\UpiQR\HdfcSmartHubVyapar;

use Pronamic\WordPress\Pay\Payments\PaymentStatus as Core_Statuses;

/**
 * Title: HDFC SmartHub Vyapar Statuses
 * Copyright: 2020-2026 Knit Pay
 *
 * @author  Knit Pay
 * @version 1.2.0.0
 * @since   1.2.0.0
 */
class Statuses {
	const COMPLETED = '3';
	
	const FAILED = '4';

	/**
	 * Transform an HDFC SmartHub Vyapar status to an Knit Pay status
	 *
	 * @param string $status
	 *
	 * @return string
	 */
	public static function transform( $transaction ) {
		$knit_pay_status = '';
		switch ( $transaction->status ) {
			case self::COMPLETED:
				$knit_pay_status = Core_Statuses::SUCCESS;
				break;

			case self::FAILED:
				$knit_pay_status = Core_Statuses::FAILURE;
				break;

			default:
				$knit_pay_status = Core_Statuses::OPEN;
				break;
		}

		if ( Core_Statuses::FAILURE == $knit_pay_status && 'Expired' === $transaction->txnmessage ) {
			$knit_pay_status = Core_Statuses::EXPIRED;
		}

		return $knit_pay_status;
	}
}
