Commit 5db39b49 authored by Mark Harding's avatar Mark Harding

(fix): catch and rethrow stripe errors - closes #794

1 merge request!254&37 - Multi-currency
Pipeline #79206425 failed with stages
in 5 minutes and 50 seconds
......@@ -20,41 +20,15 @@ class connect implements Interfaces\Api
$connectManager = new Stripe\Connect\Manager();
switch ($pages[0]) {
case 'bank':
break;
default:
$account = $connectManager->getByUser($user);
return Factory::response([
'account' => $account->export(),
]);
}
$account = $connectManager->getByUser($user);
return Factory::response([
'account' => $account->export(),
]);
}
public function post($pages)
{
$user = Session::getLoggedInUser();
$connectManager = new Stripe\Connect\Manager();
switch ($pages[0]) {
case 'bank':
$account = $connectManager->getByUser($user);
if (!$account) {
return Factory::response([
'status' => 'error',
'message' => 'You must have a USD account to add a bank account',
]);
}
$account->setAccountNumber($_POST['accountNumber'])
->setCountry($_POST['country'])
->setRoutingNumber($_POST['routingNumber']);
$connectManager->addBankAccount($account);
break;
}
return Factory::response([]);
}
......
<?php
/**
*
*/
namespace Minds\Controllers\api\v2\payments\stripe\connect;
use Minds\Api\Factory;
use Minds\Common\Cookie;
use Minds\Core\Di\Di;
use Minds\Core\Config;
use Minds\Core\Session;
use Minds\Interfaces;
use Minds\Core\Payments\Stripe;
class bank implements Interfaces\Api
{
public function get($pages)
{
$user = Session::getLoggedInUser();
$connectManager = new Stripe\Connect\Manager();
return Factory::response([
]);
}
public function post($pages)
{
$user = Session::getLoggedInUser();
$connectManager = new Stripe\Connect\Manager();
$account = $connectManager->getByUser($user);
if (!$account) {
return Factory::response([
'status' => 'error',
'message' => 'You must have a USD account to add a bank account',
]);
}
$account->setAccountNumber($_POST['accountNumber'])
->setCountry($_POST['country'])
->setRoutingNumber($_POST['routingNumber']);
try {
$connectManager->addBankAccount($account);
} catch (\Exception $e) {
return Factory::response([
'status' => 'error',
'message' => $e->getMessage(),
]);
}
return Factory::response([]);
}
public function put($pages)
{
return Factory::response([]);
}
public function delete($pages)
{
return Factory::response([]);
}
}
......@@ -6,6 +6,7 @@ use Minds\Core\Entities\Actions\Save;
use Minds\Core\Payments\Stripe\Connect\Delegates\NotificationDelegate;
use Minds\Core\Payments\Stripe\Currencies;
use Minds\Core\Payments\Stripe\Instances\AccountInstance;
use Stripe;
use Minds\Entities\User;
class Manager
......@@ -185,7 +186,11 @@ class Manager
$stripeAccount->external_account['routing_number'] = $account->getRoutingNumber();
}
$stripeAccount->save();
try {
$stripeAccount->save();
} catch (Stripe\Error\InvalidRequest $e) {
throw new \Exception($e->getMessage());
}
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment