mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class FetchesVoucherifyVoucher
|
|
{
|
|
|
|
/** @var VoucherifyClient */
|
|
private $voucherifyClient;
|
|
|
|
|
|
/**
|
|
* FetchesVoucherifyVoucher constructor.
|
|
*
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->voucherifyClient = createVoucherifyClient();
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @param string $voucherifyVoucherCode
|
|
* @return null|object
|
|
* @throws \Voucherify\ClientException
|
|
*/
|
|
public function execute(User $user, string $voucherifyVoucherCode)
|
|
{
|
|
try {
|
|
$result = $this->voucherifyClient->vouchers->get($voucherifyVoucherCode);
|
|
|
|
if (isset($result->metadata) && isset($result->metadata->email)) {
|
|
if($user->email != $result->metadata->email){
|
|
$result->reason = 'Invalid Code';
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
} catch (\Voucherify\ClientException $e) {
|
|
Log::error('FetchesVoucherifyVoucher '.$e);
|
|
return null;
|
|
}
|
|
}
|
|
}
|