Merge pull request #5677 from turbo124/v5-develop

Fixes for stripe authorize card
This commit is contained in:
David Bomba 2021-05-12 07:58:35 +10:00 committed by GitHub
commit d00bb8d36d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 16 deletions

View File

@ -62,9 +62,6 @@ class Charge
$this->stripe->init(); $this->stripe->init();
// $local_stripe = new StripeClient(
// $this->stripe->company_gateway->getConfigField('apiKey')
// );
$response = null; $response = null;
@ -79,7 +76,7 @@ class Charge
'description' => $description, 'description' => $description,
]; ];
$response = $this->stripe->createPaymentIntent($data); $response = $this->stripe->createPaymentIntent($data, $this->stripe->stripe_connect_auth);
// $response = $local_stripe->paymentIntents->create($data); // $response = $local_stripe->paymentIntents->create($data);
SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client); SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->stripe->client);

View File

@ -252,8 +252,10 @@ class StripePaymentDriver extends BaseDriver
public function createPaymentIntent($data): ?PaymentIntent public function createPaymentIntent($data): ?PaymentIntent
{ {
$this->init(); $this->init();
$meta = $this->stripe_connect_auth;
return PaymentIntent::create($data); return PaymentIntent::create($data, $meta);
} }
/** /**
@ -267,7 +269,10 @@ class StripePaymentDriver extends BaseDriver
{ {
$this->init(); $this->init();
return SetupIntent::create(); $params = [];
$meta = $this->stripe_connect_auth;
return SetupIntent::create($params, $meta);
} }
/** /**
@ -291,13 +296,13 @@ class StripePaymentDriver extends BaseDriver
$customer = null; $customer = null;
$this->init(); $this->init();
$client_gateway_token = ClientGatewayToken::whereClientId($this->client->id)->whereCompanyGatewayId($this->company_gateway->id)->first(); $client_gateway_token = ClientGatewayToken::whereClientId($this->client->id)->whereCompanyGatewayId($this->company_gateway->id)->first();
if ($client_gateway_token && $client_gateway_token->gateway_customer_reference) { if ($client_gateway_token && $client_gateway_token->gateway_customer_reference) {
$customer = Customer::retrieve($client_gateway_token->gateway_customer_reference); $customer = Customer::retrieve($client_gateway_token->gateway_customer_reference);
} else { } else {
$meta = [];
$data['name'] = $this->client->present()->name(); $data['name'] = $this->client->present()->name();
$data['phone'] = $this->client->present()->phone(); $data['phone'] = $this->client->present()->phone();
@ -305,10 +310,7 @@ class StripePaymentDriver extends BaseDriver
$data['email'] = $this->client->present()->email(); $data['email'] = $this->client->present()->email();
} }
if($this->stripe->stripe_connect) $customer = Customer::create($data, $this->stripe_connect_auth);
$meta['account_id'] = $this->company_gateway->getConfigField('account_id');
$customer = Customer::create($data, $meta);
} }
if (!$customer) { if (!$customer) {
@ -322,13 +324,15 @@ class StripePaymentDriver extends BaseDriver
{ {
$this->init(); $this->init();
$meta = $this->stripe_connect_auth;
/** Response from Stripe SDK/API. */ /** Response from Stripe SDK/API. */
$response = null; $response = null;
try { try {
$response = $this->stripe $response = $this->stripe
->refunds ->refunds
->create(['charge' => $payment->transaction_reference, 'amount' => $this->convertToStripeAmount($amount, $this->client->currency()->precision)]); ->create(['charge' => $payment->transaction_reference, 'amount' => $this->convertToStripeAmount($amount, $this->client->currency()->precision)], $meta);
if ($response->status == $response::STATUS_SUCCEEDED) { if ($response->status == $response::STATUS_SUCCEEDED) {
SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client); SystemLogger::dispatch(['server_response' => $response, 'data' => request()->all(),], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_SUCCESS, SystemLog::TYPE_STRIPE, $this->client);
@ -403,7 +407,7 @@ class StripePaymentDriver extends BaseDriver
{ {
try { try {
$stripe_payment_method = $this->getStripePaymentMethod($payment_method); $stripe_payment_method = $this->getStripePaymentMethod($payment_method);
$stripe_payment_method->attach(['customer' => $customer->id]); $stripe_payment_method->attach(['customer' => $customer->id], $this->stripe_connect_auth);
} catch (ApiErrorException | Exception $e) { } catch (ApiErrorException | Exception $e) {
$this->processInternallyFailedPayment($this, $e); $this->processInternallyFailedPayment($this, $e);
} }
@ -423,7 +427,7 @@ class StripePaymentDriver extends BaseDriver
); );
try { try {
$stripe->paymentMethods->detach($token->token); $stripe->paymentMethods->detach($token->token, $this->stripe_connect_auth);
} catch (Exception $e) { } catch (Exception $e) {
SystemLogger::dispatch([ SystemLogger::dispatch([
'server_response' => $e->getMessage(), 'data' => request()->all(), 'server_response' => $e->getMessage(), 'data' => request()->all(),
@ -446,7 +450,7 @@ class StripePaymentDriver extends BaseDriver
public function getStripePaymentMethod(string $source) public function getStripePaymentMethod(string $source)
{ {
try { try {
return PaymentMethod::retrieve($source); 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);
} }