From bf00219bbedbedfbeef0dcf0deac0cc1c5e4dce6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 19 Jul 2024 10:51:52 +1000 Subject: [PATCH 1/3] Minor fixes when restoring designs --- app/Repositories/DesignRepository.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Repositories/DesignRepository.php b/app/Repositories/DesignRepository.php index e9c979e5e4a5..f63e54b45ec3 100644 --- a/app/Repositories/DesignRepository.php +++ b/app/Repositories/DesignRepository.php @@ -11,6 +11,7 @@ namespace App\Repositories; +use App\Utils\Ninja; use App\Models\Design; use Illuminate\Support\Str; @@ -54,4 +55,20 @@ class DesignRepository extends BaseRepository return $design; } + + /** + * @param $entity + */ + public function restore($design) + { + + $design->name = str_ireplace("_deleted_", "_restored_", $design->name); + + parent::restore($design); + + return $design; + + } + + } From 684533a5914c587587463fa33bf8fe7e24104196 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 20 Jul 2024 13:36:38 +1000 Subject: [PATCH 2/3] Fixes for paypal driver --- .../PayPal/PayPalBasePaymentDriver.php | 86 +++++++++++-------- .../PayPalRestPaymentDriver.php | 79 ++++++++++------- .../gateways/paypal/ppcp/card.blade.php | 32 +++---- 3 files changed, 106 insertions(+), 91 deletions(-) diff --git a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php index 4e01c7582c0b..ec637548d3ae 100644 --- a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php +++ b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php @@ -530,56 +530,68 @@ class PayPalBasePaymentDriver extends BaseDriver public function createNinjaPayment($request, $response) { - $data = [ - 'payment_type' => $this->getPaymentMethod($request->gateway_type_id), - 'amount' => $response['purchase_units'][0]['payments']['captures'][0]['amount']['value'], - 'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'], - 'gateway_type_id' => GatewayType::PAYPAL, - ]; + if(isset($response['purchase_units'][0]['payments']['captures'][0]['status']) && in_array($response['purchase_units'][0]['payments']['captures'][0]['status'], ['COMPLETED', 'PENDING'])) + { - $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); + $payment_status = $response['purchase_units'][0]['payments']['captures'][0]['status'] == 'COMPLETED' ? \App\Models\Payment::STATUS_COMPLETED : \App\Models\Payment::STATUS_PENDING; - if ($request->has('store_card') && $request->input('store_card') === true) { - $payment_source = $response->json()['payment_source'] ?? false; + $data = [ + 'payment_type' => $this->getPaymentMethod($request->gateway_type_id), + 'amount' => $response['purchase_units'][0]['payments']['captures'][0]['amount']['value'], + 'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'], + 'gateway_type_id' => GatewayType::PAYPAL, + ]; - if(isset($payment_source['card']) && ($payment_source['card']['attributes']['vault']['status'] ?? false) && $payment_source['card']['attributes']['vault']['status'] == 'VAULTED') { + $payment = $this->createPayment($data, $payment_status); - $last4 = $payment_source['card']['last_digits']; - $expiry = $payment_source['card']['expiry']; //'2025-01' - $expiry_meta = explode('-', $expiry); - $brand = $payment_source['card']['brand']; + if ($request->has('store_card') && $request->input('store_card') === true) { + $payment_source = $response->json()['payment_source'] ?? false; - $payment_meta = new \stdClass(); - $payment_meta->exp_month = $expiry_meta[1] ?? ''; - $payment_meta->exp_year = $expiry_meta[0] ?? $expiry; - $payment_meta->brand = $brand; - $payment_meta->last4 = $last4; - $payment_meta->type = GatewayType::CREDIT_CARD; + if(isset($payment_source['card']) && ($payment_source['card']['attributes']['vault']['status'] ?? false) && $payment_source['card']['attributes']['vault']['status'] == 'VAULTED') { - $token = $payment_source['card']['attributes']['vault']['id']; // 09f28652d01257021 - $gateway_customer_reference = $payment_source['card']['attributes']['vault']['customer']['id']; //rbTHnLsZqE; + $last4 = $payment_source['card']['last_digits']; + $expiry = $payment_source['card']['expiry']; //'2025-01' + $expiry_meta = explode('-', $expiry); + $brand = $payment_source['card']['brand']; - $data['token'] = $token; - $data['payment_method_id'] = GatewayType::PAYPAL_ADVANCED_CARDS; - $data['payment_meta'] = $payment_meta; + $payment_meta = new \stdClass(); + $payment_meta->exp_month = $expiry_meta[1] ?? ''; + $payment_meta->exp_year = $expiry_meta[0] ?? $expiry; + $payment_meta->brand = $brand; + $payment_meta->last4 = $last4; + $payment_meta->type = GatewayType::CREDIT_CARD; - $additional['gateway_customer_reference'] = $gateway_customer_reference; + $token = $payment_source['card']['attributes']['vault']['id']; // 09f28652d01257021 + $gateway_customer_reference = $payment_source['card']['attributes']['vault']['customer']['id']; //rbTHnLsZqE; - $this->storeGatewayToken($data, $additional); + $data['token'] = $token; + $data['payment_method_id'] = GatewayType::PAYPAL_ADVANCED_CARDS; + $data['payment_meta'] = $payment_meta; + $additional['gateway_customer_reference'] = $gateway_customer_reference; + + $this->storeGatewayToken($data, $additional); + + } } + + SystemLogger::dispatch( + ['response' => $response->json(), 'data' => $data], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_PAYPAL, + $this->client, + $this->client->company, + ); + + return response()->json(['redirect' => route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)], false)]); } - SystemLogger::dispatch( - ['response' => $response->json(), 'data' => $data], - SystemLog::CATEGORY_GATEWAY_RESPONSE, - SystemLog::EVENT_GATEWAY_SUCCESS, - SystemLog::TYPE_PAYPAL, - $this->client, - $this->client->company, - ); - - return response()->json(['redirect' => route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)], false)]); + SystemLogger::dispatch($response, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_PAYPAL, $this->client, $this->client->company); + + $error = isset($response['purchase_units'][0]['payments']['captures'][0]['status_details'][0]) ? $response['purchase_units'][0]['payments']['captures'][0]['status_details'][0] : $response['purchase_units'][0]['payments']['captures'][0]['status']; + + return response()->json(['message' => $error], 400); } diff --git a/app/PaymentDrivers/PayPalRestPaymentDriver.php b/app/PaymentDrivers/PayPalRestPaymentDriver.php index d6e8dbadcf5c..524b59f8c632 100644 --- a/app/PaymentDrivers/PayPalRestPaymentDriver.php +++ b/app/PaymentDrivers/PayPalRestPaymentDriver.php @@ -288,8 +288,6 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver $orderId = $this->createOrder($data); - // $r = $this->gatewayRequest("/v2/checkout/orders/{$orderId}", 'get', ['body' => '']); - try { $r = $this->gatewayRequest("/v2/checkout/orders/{$orderId}", 'get', ['body' => '']); @@ -318,25 +316,33 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver $response = $r->json(); - $data = [ - 'payment_type' => $this->getPaymentMethod($request->gateway_type_id), - 'amount' => $response['purchase_units'][0]['payments']['captures'][0]['amount']['value'], - 'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'], - 'gateway_type_id' => $this->gateway_type_id, - ]; + if(isset($response['purchase_units'][0]['payments']['captures'][0]['status']) && $response['purchase_units'][0]['payments']['captures'][0]['status'] == 'COMPLETED') + { + $data = [ + 'payment_type' => $this->getPaymentMethod($request->gateway_type_id), + 'amount' => $response['purchase_units'][0]['payments']['captures'][0]['amount']['value'], + 'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'], + 'gateway_type_id' => $this->gateway_type_id, + ]; - $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); + $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); - SystemLogger::dispatch( - ['response' => $response, 'data' => $data], - SystemLog::CATEGORY_GATEWAY_RESPONSE, - SystemLog::EVENT_GATEWAY_SUCCESS, - SystemLog::TYPE_PAYPAL, - $this->client, - $this->client->company, - ); + SystemLogger::dispatch( + ['response' => $response, 'data' => $data], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_PAYPAL, + $this->client, + $this->client->company, + ); - return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); + return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); + + } + + + + } @@ -387,24 +393,31 @@ class PayPalRestPaymentDriver extends PayPalBasePaymentDriver $response = $r->json(); - $data = [ - 'payment_type' => $this->getPaymentMethod((string)$cgt->gateway_type_id), - 'amount' => $response['purchase_units'][0]['payments']['captures'][0]['amount']['value'], - 'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'], - 'gateway_type_id' => $this->gateway_type_id, - ]; + if(isset($response['purchase_units'][0]['payments']['captures'][0]['status']) && $response['purchase_units'][0]['payments']['captures'][0]['status'] == 'COMPLETED') + { - $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); + $data = [ + 'payment_type' => $this->getPaymentMethod((string)$cgt->gateway_type_id), + 'amount' => $response['purchase_units'][0]['payments']['captures'][0]['amount']['value'], + 'transaction_reference' => $response['purchase_units'][0]['payments']['captures'][0]['id'], + 'gateway_type_id' => $this->gateway_type_id, + ]; - SystemLogger::dispatch( - ['response' => $response, 'data' => $data], - SystemLog::CATEGORY_GATEWAY_RESPONSE, - SystemLog::EVENT_GATEWAY_SUCCESS, - SystemLog::TYPE_PAYPAL_PPCP, - $this->client, - $this->client->company, - ); + $payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED); + SystemLogger::dispatch( + ['response' => $response, 'data' => $data], + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_SUCCESS, + SystemLog::TYPE_PAYPAL_PPCP, + $this->client, + $this->client->company, + ); + } + + $this->processInternallyFailedPayment($this, new \Exception('Auto billing failed.', 400)); + + SystemLogger::dispatch($data, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_PAYPAL, $this->client, $this->client->company); } } diff --git a/resources/views/portal/ninja2020/gateways/paypal/ppcp/card.blade.php b/resources/views/portal/ninja2020/gateways/paypal/ppcp/card.blade.php index 63e1578f3dd8..43554bebb306 100644 --- a/resources/views/portal/ninja2020/gateways/paypal/ppcp/card.blade.php +++ b/resources/views/portal/ninja2020/gateways/paypal/ppcp/card.blade.php @@ -14,10 +14,10 @@ @endphp @section('gateway_head') - + script-src 'self' https://c.paypal.com;"> --> @endsection @section('gateway_content') @@ -86,7 +86,7 @@ } - + @if(isset($merchantId)) @@ -138,10 +138,15 @@ body: formData, }) .then(response => { + if (!response.ok) { - throw new Error('Network response was not ok ' + response.statusText); + return response.json().then(errorData => { + throw new Error(errorData.message); + }); } + return response.json(); + }) .then(data => { @@ -164,7 +169,6 @@ document.getElementById('errors').textContent = `Sorry, your transaction could not be processed...\n\n${error.message}`; document.getElementById('errors').hidden = false; - }); }, @@ -172,20 +176,6 @@ window.location.href = "/client/invoices/"; }, - // onError: function(error) { - - - // console.log("submit catch"); - // const errorM = parseError(error); - - // console.log(errorM); - - // const msg = handle422Error(errorM); - - // document.getElementById('errors').textContent = `Sorry, your transaction could not be processed...\n\n${msg.description}`; - // document.getElementById('errors').hidden = false; - - // }, onClick: function (){ } @@ -195,8 +185,8 @@ // Render each field after checking for eligibility if (cardField.isEligible()) { - // const nameField = cardField.NameField(); - // nameField.render("#card-name-field-container"); + const nameField = cardField.NameField(); + nameField.render("#card-name-field-container"); const numberField = cardField.NumberField({ inputEvents: { From e6186e9a83856e139f58efcf79a89bfdbc09ef44 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 20 Jul 2024 13:38:12 +1000 Subject: [PATCH 3/3] V5.10.12 --- VERSION.txt | 2 +- config/ninja.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index e9ea7868d298..645ef4b2679d 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.10.11 \ No newline at end of file +5.10.12 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index 21f22b804175..44f971416b66 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -17,8 +17,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => env('APP_VERSION', '5.10.11'), - 'app_tag' => env('APP_TAG', '5.10.11'), + 'app_version' => env('APP_VERSION', '5.10.12'), + 'app_tag' => env('APP_TAG', '5.10.12'), 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false),