<?php
namespace SabaiApps\Directories\Component\Payment\Controller;

use SabaiApps\Directories\Context;
use SabaiApps\Directories\Component\Form;

class PayOrder extends Form\AbstractMultiStepController {

	protected function _getSteps( Context $context, array &$formStorage ) {
		// Order may be complete after webhook has updated the order
		if ( ! $context->order->paymentOrderIsPendingPayment() ) {
			return array();
		}

		return array( 'checkout' => array( 'order' => 99 ) );
	}

	public function _getFormForStepCheckout( Context $context, array &$formStorage ) {
		$this->_submitButtons  = false;
		$context->is_dashboard = false;
		return $this->getComponent( 'Payment' )->getPaymentComponent( true )->paymentCheckoutForm( $context, $context->order );
	}

	protected function _complete( Context $context, array $formStorage ) {
		if ( ! $entity = $this->Entity_Entity( $context->order->paymentOrderEntityType(), $context->order->paymentOrderEntityId() ) ) {
			return false;
		}

		return $this->getComponent( 'Payment' )->getPaymentComponent( true )
			->paymentCheckoutComplete( $context, $context->order->paymentOrderPlan(), $entity, $context->order->paymentOrderAction() );
	}
}
