Undo wrapper in transaction as it would somehow not work
This commit is contained in:
parent
6838280386
commit
9bc60dbaa0
3 changed files with 46 additions and 41 deletions
|
|
@ -7,6 +7,7 @@ use App\Models\Customer\Customer;
|
|||
use App\Models\Payment\Transaction;
|
||||
use App\Models\Shop\Order;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class InShopPaymentAdapter extends PaymentAdapter
|
||||
{
|
||||
|
|
@ -31,16 +32,18 @@ class InShopPaymentAdapter extends PaymentAdapter
|
|||
): RedirectResponse {
|
||||
// phpcs:enable
|
||||
return $this->wrapAction(function () use ($customer, $order, $transaction, $succeed) {
|
||||
// * Enregistrement commande.
|
||||
if (!$order->save()) {
|
||||
throw new \RuntimeException("Order saving error happened.");
|
||||
}
|
||||
return DB::transaction(function () use ($succeed, $customer, $order, $transaction) {
|
||||
// * Enregistrement commande.
|
||||
if (!$order->save()) {
|
||||
throw new \RuntimeException("Order saving error happened.");
|
||||
}
|
||||
|
||||
if ($succeed) {
|
||||
$succeed($customer, $order, $transaction);
|
||||
}
|
||||
if ($succeed) {
|
||||
$succeed($customer, $order, $transaction);
|
||||
}
|
||||
|
||||
return \response()->redirectTo($this->successRoute($transaction));
|
||||
return \response()->redirectTo($this->successRoute($transaction));
|
||||
});
|
||||
}, $failed);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,37 +63,42 @@ class StripePaymentAdapter extends PaymentAdapter
|
|||
): RedirectResponse {
|
||||
// phpcs:enable
|
||||
return $this->wrapAction(function () use ($succeed, $customer, $order, $transaction) {
|
||||
// * Associate transaction to order
|
||||
$transaction->order()->associate($order);
|
||||
return DB::transaction(function () use ($succeed, $customer, $order, $transaction) {
|
||||
// * Associate transaction to order
|
||||
$transaction->order()->associate($order);
|
||||
|
||||
// * Enregistrement commande avant checkout.
|
||||
if (!$order->save() or !$transaction->save()) {
|
||||
report(new \RuntimeException("Order saving error happened."));
|
||||
throw ValidationException::withMessages([
|
||||
'error' => trans('Une erreur est survenue, veuillez réssayer')
|
||||
]);
|
||||
}
|
||||
// * Enregistrement commande avant checkout.
|
||||
if (!$order->save() or !$transaction->save()) {
|
||||
report(new \RuntimeException("Order saving error happened."));
|
||||
throw ValidationException::withMessages([
|
||||
'error' => trans('Une erreur est survenue, veuillez réssayer')
|
||||
]);
|
||||
}
|
||||
|
||||
$checkout = $customer->checkout(
|
||||
[[
|
||||
'price_data' => [
|
||||
'currency' => Str::lower($transaction->currency->getCode()),
|
||||
'unit_amount' => $order->total_ttc,
|
||||
'product_data' => ['name' => trans('Commande :ref', ['ref' => $order->ref])]
|
||||
],
|
||||
'quantity' => 1,
|
||||
]],
|
||||
[
|
||||
'success_url' => $this->successRoute($transaction, ['session_id' => '{CHECKOUT_SESSION_ID}']),
|
||||
'cancel_url' => $this->cancelRoute($order),
|
||||
]
|
||||
);
|
||||
$transaction->assignPaymentId($checkout->asStripeCheckoutSession()->payment_intent);
|
||||
if (!$transaction->save()) {
|
||||
throw new \RuntimeException('Failed to save transaction id');
|
||||
}
|
||||
$succeed($customer, $order, $transaction);
|
||||
return $checkout->toResponse(\request());
|
||||
$checkout = $customer
|
||||
->checkout(
|
||||
[[
|
||||
'price_data' => [
|
||||
'currency' => Str::lower($transaction->currency->getCode()),
|
||||
'unit_amount' => $order->total_ttc,
|
||||
'product_data' => ['name' => trans('Commande :ref', ['ref' => $order->ref])]
|
||||
],
|
||||
'quantity' => 1,
|
||||
]],
|
||||
[
|
||||
'success_url' => $this->successRoute($transaction, [
|
||||
'session_id' => '{CHECKOUT_SESSION_ID}'
|
||||
]),
|
||||
'cancel_url' => $this->cancelRoute($order),
|
||||
]
|
||||
);
|
||||
$transaction->assignPaymentId($checkout->asStripeCheckoutSession()->payment_intent);
|
||||
if (!$transaction->save()) {
|
||||
throw new \RuntimeException('Failed to save transaction id');
|
||||
}
|
||||
$succeed($customer, $order, $transaction);
|
||||
return $checkout->toResponse(\request());
|
||||
});
|
||||
}, $failed);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use App\Models\Customer\Customer;
|
|||
use App\Models\Payment\Transaction;
|
||||
use App\Models\Shop\Order;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
abstract class PaymentAdapter
|
||||
|
|
@ -36,9 +35,7 @@ abstract class PaymentAdapter
|
|||
{
|
||||
// phpcs:enable
|
||||
try {
|
||||
return DB::transaction(function () use ($action) {
|
||||
return $action();
|
||||
});
|
||||
return $action();
|
||||
} catch (\Exception $e) {
|
||||
// Sentry report failed action.
|
||||
\report($e);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue