# payplug/2.10.0/src/Front/PayplugOney/OneySimulation.php

PayPlug for WooCommerce (Official), version 2.10.0. 67 lines.

- Page: https://pluginprobe.com/plugins/payplug/2.10.0/code/src/Front/PayplugOney/OneySimulation.php
- Raw: https://pluginprobe.com/plugins/payplug/2.10.0/raw/src/Front/PayplugOney/OneySimulation.php
- Modified: 2024-10-24T16:13:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/payplug/2.10.0/code/src/Front/PayplugOney/OneySimulation.php#L10-L20`.

```php
<?php

namespace Payplug\PayplugWoocommerce\Front\PayplugOney;

use Payplug\PayplugWoocommerce\Gateway\PayplugGateway;

class OneySimulation implements InterfaceOneySimulation
{

	/**
	 * Dependency Injection
	 * @var \Payplug\PayplugWoocommerce\Front\PayplugOney\Country\OneyBase
	 */
	private $oney;

	/**
	 * @var
	 */
	public $simulation = [];

	/**
	 * Dependency injection
	 * @param \Payplug\PayplugWoocommerce\Front\PayplugOney\Country\OneyBase $oney
	 */
	public function __construct($oney)
	{
		$this->oney = $oney;
	}

	/**
	 * Check if Oney Simulation is possible if it is returnss simulation data
	 * @return array|false|object
	 */
	public function OneySimulation()
	{
		$this->oney->setTotalPrice($_POST['price']);

		if ($this->oney->getTotalPrice() < $this->oney->get_min_amount() || $this->oney->getTotalPrice() > $this->oney->get_max_amount())
			return false;

		try {
			$this->simulation = $this->requestOneySimulation();

		} catch (\Exception $e) {
			PayplugGateway::log("Simulate Oney " . $this->oney->getOneyType() ." Fees Payment, " . $e->getMessage() );
			return false;

		}

		return $this->simulation;
	}

	/**
	 * return oney simulation data for the order
	 * @param $class
	 * @return array|object
	 */
	public function requestOneySimulation()
	{
		$class = $this->oney->getSimulatedClass();
		$api = new \Payplug\PayplugWoocommerce\Gateway\PayplugApi( new $class() );
		$api->init();
		return $api->simulate_oney_payment($this->oney->getTotalPrice(), $this->oney->getOneyType());
	}

}

```
