| 1 |
<?php |
| 2 |
|
| 3 |
namespace Payplug\PayplugWoocommerce\Front\PayplugOney; |
| 4 |
|
| 5 |
use Payplug\PayplugWoocommerce\Gateway\PayplugGateway; |
| 6 |
|
| 7 |
class OneySimulation implements InterfaceOneySimulation |
| 8 |
{ |
| 9 |
|
| 10 |
/** |
| 11 |
* Dependency Injection |
| 12 |
* @var \Payplug\PayplugWoocommerce\Front\PayplugOney\Country\OneyBase |
| 13 |
*/ |
| 14 |
private $oney; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var |
| 18 |
*/ |
| 19 |
public $simulation = []; |
| 20 |
|
| 21 |
/** |
| 22 |
* Dependency injection |
| 23 |
* @param \Payplug\PayplugWoocommerce\Front\PayplugOney\Country\OneyBase $oney |
| 24 |
*/ |
| 25 |
public function __construct($oney) |
| 26 |
{ |
| 27 |
$this->oney = $oney; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Check if Oney Simulation is possible if it is returnss simulation data |
| 32 |
* @return array|false|object |
| 33 |
*/ |
| 34 |
public function OneySimulation() |
| 35 |
{ |
| 36 |
$this->oney->setTotalPrice($_POST['price']); |
| 37 |
|
| 38 |
if ($this->oney->getTotalPrice() < $this->oney->get_min_amount() || $this->oney->getTotalPrice() > $this->oney->get_max_amount()) |
| 39 |
return false; |
| 40 |
|
| 41 |
try { |
| 42 |
$this->simulation = $this->requestOneySimulation(); |
| 43 |
|
| 44 |
} catch (\Exception $e) { |
| 45 |
PayplugGateway::log("Simulate Oney " . $this->oney->getOneyType() ." Fees Payment, " . $e->getMessage() ); |
| 46 |
return false; |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
return $this->simulation; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* return oney simulation data for the order |
| 55 |
* @param $class |
| 56 |
* @return array|object |
| 57 |
*/ |
| 58 |
public function requestOneySimulation() |
| 59 |
{ |
| 60 |
$class = $this->oney->getSimulatedClass(); |
| 61 |
$api = new \Payplug\PayplugWoocommerce\Gateway\PayplugApi( new $class() ); |
| 62 |
$api->init(); |
| 63 |
return $api->simulate_oney_payment($this->oney->getTotalPrice(), $this->oney->getOneyType()); |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|