diff --git a/app/Jobs/Cron/UpdateCalculatedFields.php b/app/Jobs/Cron/UpdateCalculatedFields.php index 9145ab8f9842..8abf9a2bd48e 100644 --- a/app/Jobs/Cron/UpdateCalculatedFields.php +++ b/app/Jobs/Cron/UpdateCalculatedFields.php @@ -63,11 +63,14 @@ class UpdateCalculatedFields Project::query()->with('tasks')->whereHas('tasks', function ($query) { $query->where('updated_at', '>', now()->subHours(2)); }) - ->cursor() - ->each(function ($project) { - $project->current_hours = $this->calculateDuration($project); - $project->save(); - }); + ->cursor() + ->each(function ($project) { + $project->current_hours = $this->calculateDuration($project); + $project->save(); + }); + + //Clean password resets table + \DB::connection($db)->table('password_resets')->where('created_at', '<', now()->subHour())->delete(); } } diff --git a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php index 5c86fae72acc..35709850a55d 100644 --- a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php +++ b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php @@ -292,7 +292,32 @@ class PayPalPPCPPaymentDriver extends BaseDriver } - $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); + try { + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); + } catch(\Exception $e) { + + //Rescue for duplicate invoice_id + if(stripos($e->getMessage(), 'DUPLICATE_INVOICE_ID') !== false) { + + + $_invoice = collect($this->payment_hash->data->invoices)->first(); + $invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id)); + $new_invoice_number = $invoice->number."_".Str::random(5); + + $update_data = + [[ + "op" => "replace", + "path" => "/purchase_units/@reference_id=='default'/invoice_id", + "value" => $new_invoice_number, + ]]; + + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}", 'patch', $update_data); + + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); + + } + + } $response = $r; diff --git a/app/PaymentDrivers/PayPalRestPaymentDriver.php b/app/PaymentDrivers/PayPalRestPaymentDriver.php index 1d2bbd90bac3..323392205afe 100644 --- a/app/PaymentDrivers/PayPalRestPaymentDriver.php +++ b/app/PaymentDrivers/PayPalRestPaymentDriver.php @@ -18,6 +18,7 @@ use App\Models\Invoice; use App\Models\SystemLog; use App\Models\GatewayType; use App\Models\PaymentType; +use Illuminate\Support\Str; use App\Jobs\Util\SystemLogger; use App\Utils\Traits\MakesHash; use App\Exceptions\PaymentFailed; @@ -211,7 +212,8 @@ class PayPalRestPaymentDriver extends BaseDriver $request['gateway_response'] = str_replace("Error: ", "", $request['gateway_response']); $response = json_decode($request['gateway_response'], true); - + + nlog($response); //capture $orderID = $response['orderID']; @@ -235,7 +237,33 @@ class PayPalRestPaymentDriver extends BaseDriver } - $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); + try{ + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); + } + catch(\Exception $e) { + + //Rescue for duplicate invoice_id + if(stripos($e->getMessage(), 'DUPLICATE_INVOICE_ID') !== false){ + + + $_invoice = collect($this->payment_hash->data->invoices)->first(); + $invoice = Invoice::withTrashed()->find($this->decodePrimaryKey($_invoice->invoice_id)); + $new_invoice_number = $invoice->number."_".Str::random(5); + + $update_data = + [[ + "op" => "replace", + "path" => "/purchase_units/@reference_id=='default'/invoice_id", + "value" => $new_invoice_number, + ]]; + + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}", 'patch', $update_data); + + $r = $this->gatewayRequest("/v2/checkout/orders/{$orderID}/capture", 'post', ['body' => '']); + + } + + } $response = $r; diff --git a/resources/views/portal/ninja2020/gateways/paypal/pay.blade.php b/resources/views/portal/ninja2020/gateways/paypal/pay.blade.php index db7b9d563d64..05a9f6cf84f0 100644 --- a/resources/views/portal/ninja2020/gateways/paypal/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/paypal/pay.blade.php @@ -46,8 +46,8 @@ var errorDetail = Array.isArray(data.details) && data.details[0]; if (errorDetail && ['INSTRUMENT_DECLINED', 'PAYER_ACTION_REQUIRED'].includes(errorDetail.issue)) { - return actions.restart(); - } + return actions.restart(); + } document.getElementById("gateway_response").value =JSON.stringify( data ); document.getElementById("server_response").submit();