Test Stripe credentials when adding gateway

This commit is contained in:
Hillel Coren 2016-07-29 14:58:26 +03:00
parent af8a5b5360
commit af78a3dd2d
4 changed files with 35 additions and 1 deletions

View File

@ -60,6 +60,8 @@ class AccountGatewayController extends BaseController
$data['hiddenFields'] = Gateway::$hiddenFields; $data['hiddenFields'] = Gateway::$hiddenFields;
$data['selectGateways'] = Gateway::where('id', '=', $accountGateway->gateway_id)->get(); $data['selectGateways'] = Gateway::where('id', '=', $accountGateway->gateway_id)->get();
$this->testGateway($accountGateway);
return View::make('accounts.account_gateway', $data); return View::make('accounts.account_gateway', $data);
} }
@ -322,6 +324,16 @@ class AccountGatewayController extends BaseController
} }
} }
private function testGateway($accountGateway)
{
$paymentDriver = $accountGateway->paymentDriver();
$result = $paymentDriver->isValid();
if ($result !== true) {
Session::flash('error', $result . ' - ' . trans('texts.gateway_config_error'));
}
}
protected function getWePayUpdateUri($accountGateway) protected function getWePayUpdateUri($accountGateway)
{ {
if ($accountGateway->gateway_id != GATEWAY_WEPAY) { if ($accountGateway->gateway_id != GATEWAY_WEPAY) {

View File

@ -44,6 +44,11 @@ class BasePaymentDriver
return $this->accountGateway->gateway_id == $gatewayId; return $this->accountGateway->gateway_id == $gatewayId;
} }
public function isValid()
{
return true;
}
// optionally pass a paymentMethod to determine the type from the token // optionally pass a paymentMethod to determine the type from the token
protected function isGatewayType($gatewayType, $paymentMethod = false) protected function isGatewayType($gatewayType, $paymentMethod = false)
{ {

View File

@ -39,6 +39,21 @@ class StripePaymentDriver extends BasePaymentDriver
return $rules; return $rules;
} }
public function isValid()
{
$result = $this->makeStripeCall(
'GET',
'charges',
'limit=1'
);
if (array_get($result, 'object') == 'list') {
return true;
} else {
return $result;
}
}
protected function checkCustomerExists($customer) protected function checkCustomerExists($customer)
{ {
$response = $this->gateway() $response = $this->gateway()

View File

@ -2049,6 +2049,8 @@ $LANG = array(
'no_contact_selected' => 'Please select a contact', 'no_contact_selected' => 'Please select a contact',
'no_client_selected' => 'Please select a client', 'no_client_selected' => 'Please select a client',
'gateway_config_error' => 'It may help to set new passwords or generate new API keys.',
); );
return $LANG; return $LANG;