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