New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error handling and validation #12
Comments
Hi @AidasK , Your form is not successful if you get an exception, at that stage the If you disable the http exceptions on the config file, Your code would look like this: $method = new \Checkout\Models\Payments\TokenSource($request->get('token'));
$payment = new \Checkout\Models\Payments\Payment($method, $order->product_currency);
$payment->amount = bcmul($order->product_price, 100);
$payment->reference = $order->id;
/** @var Payment $response **/
$response = $checkoutApi->payments()->request($payment);
if(!$response->isSuccessful()) {
throw ValidationException::withMessages(['payment_method' => [$response->getErrors()]]);
/**Obs: you won't have message here.**/
}
$order->status = Order::STATUS_APPROVED; |
Thanks for your brief response. It does look cleaner. $checkoutApi = new CheckoutApi(
config('services.checkout.secret_key'),
config('app.debug'),
config('services.checkout.public_key'),
false
);
HttpHandler::$throw = false;
$method = new \Checkout\Models\Payments\TokenSource($request->get('token'));
$payment = new \Checkout\Models\Payments\Payment($method, $order->product_currency);
$payment->amount = bcmul($order->product_price, 100);
$payment->reference = \Brand::getId() . '-' . $order->id;
/** @var Payment $response */
$response = $checkoutApi->payments()->request($payment);
if (!$response->isSuccessful()) {
throw ValidationException::withMessages([
'payment_method' => $response->getErrors() ?: ['Invalid card data (' . $response->getCode() . ')']
]);
}
$order->status = Order::STATUS_APPROVED; It is a pity, that I can not provide config as an array to CheckoutApi class, so it does not look clean |
These are not configurations you want to update all the times, as this will affect how your code is executed with the SDK. You should either edit the default one or specify a custom as fourth parameter. $checkoutApi = new CheckoutApi(
config('services.checkout.secret_key'),
config('app.debug'),
config('services.checkout.public_key'),
'/project/var/checkout.ini'
); |
I just don't want any physical files to configure this. It is not a good practice |
I understand that if you have an automated deployment it is indeed impracticable to have hard files, but passing a long array is also impracticable if someone has to explicitly type the config. I am afraid |
It's not about long arrays. It should be a developers choice how to save
this config. Maybe I would like to use json files instead of .ini?
…On Fri, Apr 26, 2019 at 2:17 PM Áquila Freitas ***@***.***> wrote:
I understand that if you have an automated deployment it is indeed
impracticable to have files, but passing a long array is also impracticable
if someone has to explicitly type the config. I am afraid HttpHandler::$throw
= false; will be the only way to set individually this.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAP54JAI7L25CCZH4X5MSJTPSLQENANCNFSM4HFPILCA>
.
|
@AidasK, could you please confirm if you are expecting something like this:
If not, please provide a code snippet illustrating your expectations. |
Yes, that would be much better :) |
@AidasK, the SDK has been updated to accept a config array in the constructor as described above. We're closing this issue for now, please reopen if needed. |
Thanks! |
I have read all the wiki, but error handling and validation is not covered.
Currently I am using this snippet. I don't like it, because it contains two different catch blocks and a check after all of it. The biggest problem is that I can't tell to the user what is wrong with a form if
$response->isSuccessful()
is not successful, because$response->getErrors()
is always empty.The text was updated successfully, but these errors were encountered: