mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Support latest version of Stripe API
This commit is contained in:
parent
ed97890b7e
commit
0210cededc
@ -48,7 +48,7 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->job(new VersionCheck)->daily();
|
||||
|
||||
/* Checks and cleans redundant files */
|
||||
$schedule->job(new DiskCleanup)->daily()->withoutOverlapping();
|
||||
$schedule->job(new DiskCleanup)->dailyAt('02:10')->withoutOverlapping();
|
||||
|
||||
/* Send reminders */
|
||||
$schedule->job(new ReminderJob)->hourly()->withoutOverlapping();
|
||||
@ -63,7 +63,7 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->job(new UpdateExchangeRates)->dailyAt('23:30')->withoutOverlapping();
|
||||
|
||||
/* Runs cleanup code for subscriptions */
|
||||
$schedule->job(new SubscriptionCron)->daily()->withoutOverlapping();
|
||||
$schedule->job(new SubscriptionCron)->dailyAt('00:01')->withoutOverlapping();
|
||||
|
||||
/* Sends recurring invoices*/
|
||||
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping();
|
||||
@ -72,22 +72,22 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->job(new RecurringExpensesCron)->dailyAt('00:10')->withoutOverlapping();
|
||||
|
||||
/* Fires notifications for expired Quotes */
|
||||
$schedule->job(new QuoteCheckExpired)->dailyAt('05:00')->withoutOverlapping();
|
||||
$schedule->job(new QuoteCheckExpired)->dailyAt('05:10')->withoutOverlapping();
|
||||
|
||||
/* Performs auto billing */
|
||||
$schedule->job(new AutoBillCron)->dailyAt('06:00')->withoutOverlapping();
|
||||
$schedule->job(new AutoBillCron)->dailyAt('06:20')->withoutOverlapping();
|
||||
|
||||
/* Checks the status of the scheduler */
|
||||
$schedule->job(new SchedulerCheck)->daily()->withoutOverlapping();
|
||||
$schedule->job(new SchedulerCheck)->dailyAt('01:10')->withoutOverlapping();
|
||||
|
||||
/* Checks for scheduled tasks */
|
||||
$schedule->job(new TaskScheduler())->daily()->withoutOverlapping();
|
||||
$schedule->job(new TaskScheduler())->dailyAt('06:50')->withoutOverlapping();
|
||||
|
||||
/* Performs system maintenance such as pruning the backup table */
|
||||
$schedule->job(new SystemMaintenance)->weekly()->withoutOverlapping();
|
||||
|
||||
/* Pulls in bank transactions from third party services */
|
||||
$schedule->job(new BankTransactionSync)->dailyAt('04:00')->withoutOverlapping();
|
||||
$schedule->job(new BankTransactionSync)->dailyAt('04:10')->withoutOverlapping();
|
||||
|
||||
if (Ninja::isSelfHost()) {
|
||||
|
||||
|
@ -138,7 +138,7 @@ class CreditCard
|
||||
'payment_method' => $this->stripe->payment_hash->data->server_response->payment_method,
|
||||
'payment_type' => PaymentType::parseCardType(strtolower($stripe_method->card->brand)) ?: PaymentType::CREDIT_CARD_OTHER,
|
||||
'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->server_response->amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
|
||||
'transaction_reference' => optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id,
|
||||
'transaction_reference' => isset($this->stripe->payment_hash->data->payment_intent->latest_charge) ? $this->stripe->payment_hash->data->payment_intent->latest_charge : optional($this->stripe->payment_hash->data->payment_intent->charges->data[0])->id,
|
||||
'gateway_type_id' => GatewayType::CREDIT_CARD,
|
||||
];
|
||||
|
||||
|
@ -60,118 +60,124 @@ class PaymentIntentWebhook implements ShouldQueue
|
||||
|
||||
$company = Company::where('company_key', $this->company_key)->first();
|
||||
|
||||
foreach ($this->stripe_request as $transaction) {
|
||||
nlog($this->stripe_request);
|
||||
|
||||
if(array_key_exists('payment_intent', $transaction))
|
||||
{
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where(function ($query) use ($transaction) {
|
||||
$query->where('transaction_reference', $transaction['payment_intent'])
|
||||
->orWhere('transaction_reference', $transaction['id']);
|
||||
})
|
||||
->first();
|
||||
}
|
||||
else
|
||||
{
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('transaction_reference', $transaction['id'])
|
||||
->first();
|
||||
}
|
||||
// foreach ($this->stripe_request as $transaction) {
|
||||
|
||||
if ($payment) {
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
$payment->save();
|
||||
// if(array_key_exists('payment_intent', $transaction))
|
||||
// {
|
||||
// $payment = Payment::query()
|
||||
// ->where('company_id', $company->id)
|
||||
// ->where(function ($query) use ($transaction) {
|
||||
// $query->where('transaction_reference', $transaction['payment_intent'])
|
||||
// ->orWhere('transaction_reference', $transaction['id']);
|
||||
// })
|
||||
// ->first();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $payment = Payment::query()
|
||||
// ->where('company_id', $company->id)
|
||||
// ->where('transaction_reference', $transaction['id'])
|
||||
// ->first();
|
||||
// }
|
||||
|
||||
// if ($payment) {
|
||||
// $payment->status_id = Payment::STATUS_COMPLETED;
|
||||
// $payment->save();
|
||||
|
||||
$this->payment_completed = true;
|
||||
}
|
||||
}
|
||||
// $this->payment_completed = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
if($this->payment_completed)
|
||||
return;
|
||||
// if($this->payment_completed)
|
||||
// return;
|
||||
|
||||
|
||||
if(isset($this->stripe_request['object']['charges']) && optional($this->stripe_request['object']['charges']['data'][0])['id']){
|
||||
// if(isset($this->stripe_request['object']['charges']) && optional($this->stripe_request['object']['charges']['data'][0])['id']){
|
||||
|
||||
$company = Company::where('company_key', $this->company_key)->first();
|
||||
// $company = Company::where('company_key', $this->company_key)->first();
|
||||
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('transaction_reference', $this->stripe_request['object']['charges']['data'][0]['id'])
|
||||
->first();
|
||||
// $payment = Payment::query()
|
||||
// ->where('company_id', $company->id)
|
||||
// ->where('transaction_reference', $this->stripe_request['object']['charges']['data'][0]['id'])
|
||||
// ->first();
|
||||
|
||||
//return early
|
||||
if($payment && $payment->status_id == Payment::STATUS_COMPLETED){
|
||||
nlog(" payment found and status correct - returning ");
|
||||
return;
|
||||
}
|
||||
elseif($payment){
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
$payment->save();
|
||||
}
|
||||
// //return early
|
||||
// if($payment && $payment->status_id == Payment::STATUS_COMPLETED){
|
||||
// nlog(" payment found and status correct - returning ");
|
||||
// return;
|
||||
// }
|
||||
// elseif($payment){
|
||||
// $payment->status_id = Payment::STATUS_COMPLETED;
|
||||
// $payment->save();
|
||||
// }
|
||||
|
||||
|
||||
$hash = optional($this->stripe_request['object']['charges']['data'][0]['metadata'])['payment_hash'];
|
||||
// $hash = optional($this->stripe_request['object']['charges']['data'][0]['metadata'])['payment_hash'];
|
||||
|
||||
$payment_hash = PaymentHash::where('hash', $hash)->first();
|
||||
// $payment_hash = PaymentHash::where('hash', $hash)->first();
|
||||
|
||||
if(!$payment_hash)
|
||||
return;
|
||||
// if(!$payment_hash)
|
||||
// return;
|
||||
|
||||
nlog("payment intent");
|
||||
nlog($this->stripe_request);
|
||||
// nlog("payment intent");
|
||||
// nlog($this->stripe_request);
|
||||
|
||||
if(array_key_exists('allowed_source_types', $this->stripe_request['object']) && optional($this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']) && in_array('card', $this->stripe_request['object']['allowed_source_types']))
|
||||
{
|
||||
nlog("hash found");
|
||||
// if(array_key_exists('allowed_source_types', $this->stripe_request['object']) && optional($this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']) && in_array('card', $this->stripe_request['object']['allowed_source_types']))
|
||||
// {
|
||||
// nlog("hash found");
|
||||
|
||||
$hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash'];
|
||||
// $hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash'];
|
||||
|
||||
$payment_hash = PaymentHash::where('hash', $hash)->first();
|
||||
$invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id);
|
||||
$client = $invoice->client;
|
||||
// $payment_hash = PaymentHash::where('hash', $hash)->first();
|
||||
// $invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id);
|
||||
// $client = $invoice->client;
|
||||
|
||||
$this->updateCreditCardPayment($payment_hash, $client);
|
||||
}
|
||||
elseif(array_key_exists('payment_method_types', $this->stripe_request['object']) && optional($this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']) && in_array('card', $this->stripe_request['object']['payment_method_types']))
|
||||
{
|
||||
nlog("hash found");
|
||||
// $this->updateCreditCardPayment($payment_hash, $client);
|
||||
// }
|
||||
// elseif(array_key_exists('payment_method_types', $this->stripe_request['object']) && optional($this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']) && in_array('card', $this->stripe_request['object']['payment_method_types']))
|
||||
// {
|
||||
// nlog("hash found");
|
||||
|
||||
$hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash'];
|
||||
// $hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash'];
|
||||
|
||||
$payment_hash = PaymentHash::where('hash', $hash)->first();
|
||||
$invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id);
|
||||
$client = $invoice->client;
|
||||
// $payment_hash = PaymentHash::where('hash', $hash)->first();
|
||||
// $invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id);
|
||||
// $client = $invoice->client;
|
||||
|
||||
$this->updateCreditCardPayment($payment_hash, $client);
|
||||
}
|
||||
elseif(array_key_exists('payment_method_types', $this->stripe_request['object']) && optional($this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']) && in_array('us_bank_account', $this->stripe_request['object']['payment_method_types']))
|
||||
{
|
||||
nlog("hash found");
|
||||
// $this->updateCreditCardPayment($payment_hash, $client);
|
||||
// }
|
||||
// elseif(array_key_exists('payment_method_types', $this->stripe_request['object']) && optional($this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash']) && in_array('us_bank_account', $this->stripe_request['object']['payment_method_types']))
|
||||
// {
|
||||
// nlog("hash found");
|
||||
|
||||
$hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash'];
|
||||
// $hash = $this->stripe_request['object']['charges']['data'][0]['metadata']['payment_hash'];
|
||||
|
||||
$payment_hash = PaymentHash::where('hash', $hash)->first();
|
||||
$invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id);
|
||||
$client = $invoice->client;
|
||||
// $payment_hash = PaymentHash::where('hash', $hash)->first();
|
||||
// $invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id);
|
||||
// $client = $invoice->client;
|
||||
|
||||
$this->updateAchPayment($payment_hash, $client);
|
||||
}
|
||||
// $this->updateAchPayment($payment_hash, $client);
|
||||
// }
|
||||
|
||||
SystemLogger::dispatch(
|
||||
['response' => $this->stripe_request, 'data' => []],
|
||||
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
SystemLog::EVENT_GATEWAY_SUCCESS,
|
||||
SystemLog::TYPE_STRIPE,
|
||||
null,
|
||||
$company,
|
||||
);
|
||||
// SystemLogger::dispatch(
|
||||
// ['response' => $this->stripe_request, 'data' => []],
|
||||
// SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
||||
// SystemLog::EVENT_GATEWAY_SUCCESS,
|
||||
// SystemLog::TYPE_STRIPE,
|
||||
// null,
|
||||
// $company,
|
||||
// );
|
||||
|
||||
return;
|
||||
// return;
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
nlog("if");
|
||||
|
||||
nlog($this->stripe_request['object']['latest_charge']);
|
||||
|
||||
if(isset($this->stripe_request['object']['latest_charge']))
|
||||
{
|
||||
@ -179,6 +185,8 @@ class PaymentIntentWebhook implements ShouldQueue
|
||||
|
||||
$charge = reset($pi->charges->data);
|
||||
|
||||
nlog($charge);
|
||||
|
||||
$company = Company::where('company_key', $this->company_key)->first();
|
||||
|
||||
$payment = Payment::query()
|
||||
|
@ -116,11 +116,14 @@ class StripePaymentDriver extends BaseDriver
|
||||
throw new StripeConnectFailure('Stripe Connect has not been configured');
|
||||
}
|
||||
} else {
|
||||
|
||||
$this->stripe = new StripeClient(
|
||||
$this->company_gateway->getConfigField('apiKey')
|
||||
);
|
||||
|
||||
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
|
||||
// Stripe::setApiVersion('2022-11-15');
|
||||
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
Loading…
x
Reference in New Issue
Block a user