Fixes for Stripe Connect

This commit is contained in:
David Bomba 2021-05-12 12:03:46 +10:00
parent 67f0286333
commit 619179aba0
3 changed files with 47 additions and 13 deletions

View File

@ -405,11 +405,26 @@ class StripePaymentDriver extends BaseDriver
*/ */
public function attach(string $payment_method, $customer): void public function attach(string $payment_method, $customer): void
{ {
$this->init();
try { try {
$stripe_payment_method = $this->getStripePaymentMethod($payment_method); $stripe_payment_method = $this->getStripePaymentMethod($payment_method);
$stripe_payment_method->attach(['customer' => $customer->id], null, $this->stripe_connect_auth); $stripe_payment_method->attach(['customer' => $customer->id], $this->stripe_connect_auth);
} catch (ApiErrorException | Exception $e) { } catch (ApiErrorException | Exception $e) {
$this->processInternallyFailedPayment($this, $e);
nlog($e->getMessage());
SystemLogger::dispatch([
'server_response' => $e->getMessage(),
'data' => request()->all(),
],
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_STRIPE,
$this->client);
} }
} }
@ -422,18 +437,27 @@ class StripePaymentDriver extends BaseDriver
*/ */
public function detach(ClientGatewayToken $token) public function detach(ClientGatewayToken $token)
{ {
$stripe = new StripeClient(
$this->company_gateway->getConfigField('apiKey') $this->init();
);
try{ try{
$stripe_payment_method = $this->getStripePaymentMethod($token->token);
$stripe_payment_method->detach($token->token, null, $this->stripe_connect_auth); $pm = $this->getStripePaymentMethod($token->token);
//$stripe->paymentMethods->detach($token->token, $this->stripe_connect_auth); $pm->detach([], $this->stripe_connect_auth);
} catch (Exception $e) {
} catch (ApiErrorException | Exception $e) {
nlog($e->getMessage());
SystemLogger::dispatch([ SystemLogger::dispatch([
'server_response' => $e->getMessage(), 'data' => request()->all(), 'server_response' => $e->getMessage(),
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client); 'data' => request()->all(),
],
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_STRIPE,
$this->client);
} }
} }
@ -452,9 +476,13 @@ class StripePaymentDriver extends BaseDriver
public function getStripePaymentMethod(string $source) public function getStripePaymentMethod(string $source)
{ {
try { try {
return PaymentMethod::retrieve($source, $this->stripe_connect_auth); return PaymentMethod::retrieve($source, $this->stripe_connect_auth);
} catch (ApiErrorException | Exception $e) { } catch (ApiErrorException | Exception $e) {
return $this->processInternallyFailedPayment($this, $e); return $this->processInternallyFailedPayment($this, $e);
} }
} }
} }

View File

@ -29,7 +29,7 @@ class StripeConnectGateway extends Migration
Gateway::create($gateway); Gateway::create($gateway);
if (Ninja::isNinja()) { if (Ninja::isHosted()) {
Gateway::whereIn('id', [20])->update(['visible' => 0]); Gateway::whereIn('id', [20])->update(['visible' => 0]);
Gateway::whereIn('id', [56])->update(['visible' => 1]); Gateway::whereIn('id', [56])->update(['visible' => 1]);
} }

View File

@ -12,6 +12,7 @@ namespace Database\Seeders;
use App\Models\Gateway; use App\Models\Gateway;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\Utils\Ninja;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
@ -97,6 +98,11 @@ class PaymentLibrariesSeeder extends Seeder
Gateway::whereIn('id', [1,15,20,39,55,50])->update(['visible' => 1]); Gateway::whereIn('id', [1,15,20,39,55,50])->update(['visible' => 1]);
if (Ninja::isHosted()) {
Gateway::whereIn('id', [20])->update(['visible' => 0]);
Gateway::whereIn('id', [56])->update(['visible' => 1]);
}
Gateway::all()->each(function ($gateway) { Gateway::all()->each(function ($gateway) {
$gateway->site_url = $gateway->getHelp(); $gateway->site_url = $gateway->getHelp();
$gateway->save(); $gateway->save();