diff --git a/app/Helpers/Bank/Nordigen/Nordigen.php b/app/Helpers/Bank/Nordigen/Nordigen.php index d946e85def4b..6f71155140a4 100644 --- a/app/Helpers/Bank/Nordigen/Nordigen.php +++ b/app/Helpers/Bank/Nordigen/Nordigen.php @@ -167,7 +167,8 @@ class Nordigen $mo->email_template_body = 'nordigen_requisition_body'; $mo->email_template_subject = 'nordigen_requisition_subject'; - Email::dispatch($mo, $bank_integration->company);if( + Email::dispatch($mo, $bank_integration->company); + Cache::put($cache_key, true, 60 * 60 * 24); } diff --git a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php index 47141b678dfa..6918f951c221 100644 --- a/app/PaymentDrivers/PayPalPPCPPaymentDriver.php +++ b/app/PaymentDrivers/PayPalPPCPPaymentDriver.php @@ -303,6 +303,8 @@ class PayPalPPCPPaymentDriver extends PayPalBasePaymentDriver $r = $this->gatewayRequest('/v2/checkout/orders', 'post', $order); + $this->payment_hash->withData("orderID", $r->json()['id']); + return $r->json()['id']; } diff --git a/app/PaymentDrivers/PayPalRestPaymentDriver.php b/app/PaymentDrivers/PayPalRestPaymentDriver.php index 5e19429d6ff2..56c699193848 100644 --- a/app/PaymentDrivers/PayPalRestPaymentDriver.php +++ b/app/PaymentDrivers/PayPalRestPaymentDriver.php @@ -72,6 +72,12 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver return $this->processTokenPayment($request, $response); //capture + + if(!isset($response['orderID']) && isset($response['name']) && $response['name'] == "UNPROCESSABLE_ENTITY"){ + $this->handleDuplicateInvoiceId($this->payment_hash->data->orderID); + $response['orderID'] = $this->payment_hash->data->orderID; + } + $orderID = $response['orderID']; if($this->company_gateway->require_shipping_address) { @@ -109,21 +115,8 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver //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' => '']); + + $r = $this->handleDuplicateInvoiceId($orderID); } @@ -162,6 +155,27 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver } + private function handleDuplicateInvoiceId(string $orderID) + { + + $_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' => '']); + + return $r; + } + private function createNinjaPayment($request, $response) { $data = [ @@ -273,6 +287,9 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver $r = $this->gatewayRequest('/v2/checkout/orders', 'post', $order); nlog($r->json()); + + $this->payment_hash->withData("orderID", $r->json()['id']); + return $r->json()['id']; }