2016-07-14 22:37:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Datatables;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
use URL;
|
|
|
|
use App\Models\AccountGateway;
|
|
|
|
|
2016-07-14 22:37:04 +02:00
|
|
|
/**
|
|
|
|
* Class AccountGatewayDatatable
|
|
|
|
*/
|
2016-05-23 18:52:20 +02:00
|
|
|
class AccountGatewayDatatable extends EntityDatatable
|
|
|
|
{
|
|
|
|
public $entityType = ENTITY_ACCOUNT_GATEWAY;
|
|
|
|
|
2016-07-14 22:37:04 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-05-23 18:52:20 +02:00
|
|
|
public function columns()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'name',
|
|
|
|
function ($model) {
|
|
|
|
if ($model->deleted_at) {
|
|
|
|
return $model->name;
|
|
|
|
} elseif ($model->gateway_id != GATEWAY_WEPAY) {
|
|
|
|
return link_to("gateways/{$model->public_id}/edit", $model->name)->toHtml();
|
|
|
|
} else {
|
|
|
|
$accountGateway = AccountGateway::find($model->id);
|
|
|
|
$config = $accountGateway->getConfig();
|
|
|
|
$endpoint = WEPAY_ENVIRONMENT == WEPAY_STAGE ? 'https://stage.wepay.com/' : 'https://www.wepay.com/';
|
|
|
|
$wepayAccountId = $config->accountId;
|
|
|
|
$wepayState = isset($config->state)?$config->state:null;
|
|
|
|
$linkText = $model->name;
|
|
|
|
$url = $endpoint.'account/'.$wepayAccountId;
|
2016-07-03 18:11:58 +02:00
|
|
|
$html = link_to($url, $linkText, ['target'=>'_blank'])->toHtml();
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
if ($wepayState == 'action_required') {
|
2016-05-24 19:04:55 +02:00
|
|
|
$updateUri = $endpoint.'api/account_update/'.$wepayAccountId.'?redirect_uri='.urlencode(URL::to('gateways'));
|
2016-05-23 18:52:20 +02:00
|
|
|
$linkText .= ' <span style="color:#d9534f">('.trans('texts.action_required').')</span>';
|
2016-05-24 19:04:55 +02:00
|
|
|
$url = $updateUri;
|
2016-05-23 18:52:20 +02:00
|
|
|
$html = "<a href=\"{$url}\">{$linkText}</a>";
|
|
|
|
$model->setupUrl = $url;
|
|
|
|
} elseif ($wepayState == 'pending') {
|
|
|
|
$linkText .= ' ('.trans('texts.resend_confirmation_email').')';
|
|
|
|
$model->resendConfirmationUrl = $url = URL::to("gateways/{$accountGateway->public_id}/resend_confirmation");
|
|
|
|
$html = link_to($url, $linkText)->toHtml();
|
|
|
|
}
|
|
|
|
} catch(\WePayException $ex){}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-07-14 22:37:04 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-05-23 18:52:20 +02:00
|
|
|
public function actions()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
uctrans('texts.resend_confirmation_email'),
|
|
|
|
function ($model) {
|
|
|
|
return $model->resendConfirmationUrl;
|
|
|
|
},
|
|
|
|
function($model) {
|
|
|
|
return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY && !empty($model->resendConfirmationUrl);
|
|
|
|
}
|
|
|
|
] , [
|
|
|
|
uctrans('texts.edit_gateway'),
|
|
|
|
function ($model) {
|
|
|
|
return URL::to("gateways/{$model->public_id}/edit");
|
|
|
|
},
|
|
|
|
function($model) {
|
|
|
|
return !$model->deleted_at;
|
|
|
|
}
|
|
|
|
], [
|
2016-07-16 22:51:18 +02:00
|
|
|
uctrans('texts.finish_setup'),
|
|
|
|
function ($model) {
|
|
|
|
return $model->setupUrl;
|
|
|
|
},
|
|
|
|
function($model) {
|
|
|
|
return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY && !empty($model->setupUrl);
|
|
|
|
}
|
|
|
|
], [
|
|
|
|
uctrans('texts.manage_account'),
|
2016-05-23 18:52:20 +02:00
|
|
|
function ($model) {
|
|
|
|
$accountGateway = AccountGateway::find($model->id);
|
|
|
|
$endpoint = WEPAY_ENVIRONMENT == WEPAY_STAGE ? 'https://stage.wepay.com/' : 'https://www.wepay.com/';
|
2016-07-03 18:11:58 +02:00
|
|
|
return [
|
2016-05-23 18:52:20 +02:00
|
|
|
'url' => $endpoint.'account/'.$accountGateway->getConfig()->accountId,
|
|
|
|
'attributes' => 'target="_blank"'
|
2016-07-03 18:11:58 +02:00
|
|
|
];
|
2016-05-23 18:52:20 +02:00
|
|
|
},
|
|
|
|
function($model) {
|
|
|
|
return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY;
|
|
|
|
}
|
2016-07-18 21:58:56 +02:00
|
|
|
], [
|
|
|
|
uctrans('texts.terms_of_service'),
|
|
|
|
function ($model) {
|
|
|
|
return 'https://go.wepay.com/terms-of-service-us';
|
|
|
|
},
|
|
|
|
function($model) {
|
|
|
|
return $model->gateway_id == GATEWAY_WEPAY;
|
|
|
|
}
|
2016-05-23 18:52:20 +02:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|