Merge pull request #4669 from devansh-webkul/issue-4641

User Friendly Messages Updated #4641
This commit is contained in:
Glenn Hermans 2021-02-22 14:35:50 +01:00 committed by GitHub
commit 30c0560e96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 123 additions and 20 deletions

View File

@ -61,7 +61,7 @@ class SmartButtonController extends Controller
try { try {
return response()->json($this->smartButton->createOrder($this->buildRequestBody())); return response()->json($this->smartButton->createOrder($this->buildRequestBody()));
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; return response()->json(json_decode($e->getMessage()), 400);
} }
} }
@ -76,7 +76,7 @@ class SmartButtonController extends Controller
$this->smartButton->captureOrder(request()->input('orderData.orderID')); $this->smartButton->captureOrder(request()->input('orderData.orderID'));
return $this->saveOrder(); return $this->saveOrder();
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; return response()->json(json_decode($e->getMessage()), 400);
} }
} }

View File

@ -15,6 +15,8 @@ class PaypalServiceProvider extends ServiceProvider
{ {
include __DIR__ . '/../Http/routes.php'; include __DIR__ . '/../Http/routes.php';
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'paypal');
$this->loadViewsFrom(__DIR__ . '/../Resources/views', 'paypal'); $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'paypal');
$this->app->register(EventServiceProvider::class); $this->app->register(EventServiceProvider::class);
@ -29,7 +31,7 @@ class PaypalServiceProvider extends ServiceProvider
{ {
$this->registerConfig(); $this->registerConfig();
} }
/** /**
* Register package config. * Register package config.
* *

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -0,0 +1,9 @@
<?php
return [
'error' => [
'universal-error' => 'Something went wrong!',
'sdk-validation-error' => 'Client ID not recognized for either production or sandbox!',
'authorization-error' => 'Client ID and Client Secret should be valid!'
]
];

View File

@ -14,8 +14,14 @@
</style> </style>
<script> <script>
let messages = {
universalError: "{{ __('paypal::app.error.universal-error') }}",
sdkValidationError: "{{ __('paypal::app.error.sdk-validation-error') }}",
authorizationError: "{{ __('paypal::app.error.authorization-error') }}"
};
window.onload = (function() { window.onload = (function() {
eventBus.$on('after-payment-method-selected', function(payment) { eventBus.$on('after-payment-method-selected', function (payment) {
if (payment.method != 'paypal_smart_button') { if (payment.method != 'paypal_smart_button') {
$('.paypal-buttons').remove(); $('.paypal-buttons').remove();
@ -23,11 +29,7 @@
} }
if (typeof paypal == 'undefined') { if (typeof paypal == 'undefined') {
window.flashMessages = [{'type': 'alert-error', 'message': "SDK Validation error: 'client-id not recognized for either production or sandbox: {{core()->getConfigData('sales.paymentmethods.paypal_smart_button.client_id')}}'" }]; options.alertBox(messages.sdkValidationError);
window.flashMessages.alertMessage = "SDK Validation error: 'client-id not recognized for either production or sandbox: {{core()->getConfigData('sales.paymentmethods.paypal_smart_button.client_id')}}'";
app.addFlashMessages();
return; return;
} }
@ -38,8 +40,16 @@
shape: 'rect', shape: 'rect',
}, },
authorizationFailed: false,
enableStandardCardFields: false, enableStandardCardFields: false,
alertBox: function (message) {
window.flashMessages = [{'type': 'alert-error', 'message': message }];
window.flashMessages.alertMessage = message;
app.addFlashMessages();
},
createOrder: function(data, actions) { createOrder: function(data, actions) {
return window.axios.get("{{ route('paypal.smart-button.create-order') }}") return window.axios.get("{{ route('paypal.smart-button.create-order') }}")
.then(function(response) { .then(function(response) {
@ -48,7 +58,14 @@
.then(function(orderData) { .then(function(orderData) {
return orderData.id; return orderData.id;
}) })
.catch(function (error) {}) .catch(function (error) {
if (error.response.data.error === 'invalid_client') {
options.authorizationFailed = true;
options.alertBox(messages.authorizationError);
}
return error;
});
}, },
onApprove: function(data, actions) { onApprove: function(data, actions) {
@ -74,16 +91,10 @@
}) })
}, },
onCancel: function (data) { onError: function (error) {
console.log('Canceled payment...'); if (! options.authorizationFailed) {
}, options.alertBox(error);
}
onError: function (err) {
window.flashMessages = [{'type': 'alert-error', 'message': err }];
window.flashMessages.alertMessage = err;
app.addFlashMessages();
} }
}; };