mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Vouchers\Services;
|
|
|
|
use ErrorException;
|
|
|
|
class RedeemsVoucher
|
|
{
|
|
|
|
/** @var VoucherifyClient */
|
|
private $voucherifyClient;
|
|
|
|
|
|
/**
|
|
* RedeemsVoucher constructor.
|
|
*
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->voucherifyClient = createVoucherifyClient();
|
|
}
|
|
|
|
/**
|
|
* @param string $promoCode
|
|
* @param string $amount
|
|
* @param object $employee
|
|
* @return null|object
|
|
* @throws ErrorException
|
|
*/
|
|
public function execute(string $promoCode, string $amount, object $employee)
|
|
{
|
|
try {
|
|
$result = $this->voucherifyClient->redemptions->redeem($promoCode, [
|
|
"customer" => [
|
|
// "id" => $employee->id,
|
|
"name" => $employee->name,
|
|
"email" => $employee->email,
|
|
],
|
|
"order" => [
|
|
"amount" => $amount * 100 //converting it to cents
|
|
]
|
|
]);
|
|
return $result;
|
|
} catch (\Voucherify\ClientException $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|