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 {
return response()->json($this->smartButton->createOrder($this->buildRequestBody()));
} 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'));
return $this->saveOrder();
} 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';
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'paypal');
$this->loadViewsFrom(__DIR__ . '/../Resources/views', 'paypal');
$this->app->register(EventServiceProvider::class);

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,6 +14,12 @@
</style>
<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() {
eventBus.$on('after-payment-method-selected', function (payment) {
if (payment.method != 'paypal_smart_button') {
@ -23,11 +29,7 @@
}
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')}}'" }];
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();
options.alertBox(messages.sdkValidationError);
return;
}
@ -38,8 +40,16 @@
shape: 'rect',
},
authorizationFailed: false,
enableStandardCardFields: false,
alertBox: function (message) {
window.flashMessages = [{'type': 'alert-error', 'message': message }];
window.flashMessages.alertMessage = message;
app.addFlashMessages();
},
createOrder: function(data, actions) {
return window.axios.get("{{ route('paypal.smart-button.create-order') }}")
.then(function(response) {
@ -48,7 +58,14 @@
.then(function(orderData) {
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) {
@ -74,16 +91,10 @@
})
},
onCancel: function (data) {
console.log('Canceled payment...');
},
onError: function (err) {
window.flashMessages = [{'type': 'alert-error', 'message': err }];
window.flashMessages.alertMessage = err;
app.addFlashMessages();
onError: function (error) {
if (! options.authorizationFailed) {
options.alertBox(error);
}
}
};