-
-
Notifications
You must be signed in to change notification settings - Fork 362
More backend issues resolved #3850
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
Changes from all commits
6209e07
443e813
cea42cc
c987dbd
be5da84
f719813
f5b8cea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| use Omnipay\Common\Exception\InvalidCreditCardException; | ||
| use Omnipay\Common\Message\RedirectResponseInterface; | ||
| use Omnipay\Common\Message\ResponseInterface; | ||
| use Omnipay\Dummy\Message\Response as DummyResponse; | ||
| use Omnipay\Mollie\Message\Response\FetchTransactionResponse; | ||
|
|
||
| /** | ||
|
|
@@ -103,13 +104,21 @@ public function processPayment(Order $order, string $return_url, string $cancel_ | |
| redirect_url: $redirect_url, | ||
| ); | ||
| } elseif ($response->isSuccessful()) { | ||
| if ($response instanceof DummyResponse) { | ||
| // We need those metadata for later completion | ||
| $metadata = []; | ||
| $reference = $response->getTransactionReference(); | ||
| $metadata['transactionReference'] = $reference; | ||
| Session::put('metadata.' . $order->id, $metadata); | ||
| } | ||
|
|
||
| // Payment was successful | ||
| $this->completePayment($order, $response); | ||
| $order->transaction_id = $response->getTransactionReference(); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only save the transaction id to make sure that we do a proper finalization. |
||
| $order->save(); | ||
|
|
||
| return new CheckoutDTO( | ||
| is_success: true, | ||
| is_redirect: false, | ||
| redirect_url: $return_url, | ||
| ); | ||
| } else { | ||
| // Payment failed | ||
|
|
@@ -122,8 +131,6 @@ public function processPayment(Order $order, string $return_url, string $cancel_ | |
| ); | ||
| } | ||
| } catch (\Exception|InvalidCreditCardException $e) { | ||
| // dd($e); | ||
| // TODO: later do better error management | ||
| Log::error('Error processing payment: ' . $e->getMessage(), [ | ||
| 'order_id' => $order->id, | ||
| 'transaction_id' => $order->transaction_id, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,16 +97,25 @@ public function process(ProcessRequest $request): CheckoutResource | |
| $request->additional_data ?? [] | ||
| ); | ||
|
|
||
| // If we have a success directly without redirection mark order as completed | ||
| if ($result->is_success && !$result->is_redirect) { | ||
| OrderCompleted::dispatchIf(Configs::getValueAsBool('webshop_auto_fulfill_enabled'), $order->id); | ||
| // This is a success we now need to complete the order. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This way the OrderCompleted event is only dispatched in the finalize step, not in the processing step. |
||
| $order->refresh(); | ||
|
|
||
| return new CheckoutResource( | ||
| is_success: true, | ||
| is_redirect: false, | ||
| complete_url: URL::route('shop.checkout.return', ['provider' => $order->provider->value, 'transaction_id' => $order->transaction_id]), | ||
| message: '', | ||
| order: OrderResource::fromModel($order), | ||
| ); | ||
| } | ||
|
|
||
| return new CheckoutResource( | ||
| is_success: $result->is_success, | ||
| is_redirect: $result->is_redirect, | ||
| redirect_url: $result->redirect_url, | ||
| message: $result->message ?? '', | ||
| order: OrderResource::fromModel($order), | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,8 @@ public function authorize(): bool | |
| return count( | ||
| array_diff( | ||
| array_column($this->items, 'id'), | ||
| $this->order->items->pluck('id')->toArray()) | ||
| $this->order->items->pluck('id')->toArray() | ||
| ) | ||
| ) === 0; | ||
| } | ||
|
|
||
|
|
@@ -65,7 +66,9 @@ protected function processValidatedValues(array $values, array $files): void | |
| /** @var int $order_id */ | ||
| $order_id = intval($values['order_id'] ?? null); | ||
| $this->order = Order::query() | ||
| ->where('status', '=', PaymentStatusType::COMPLETED) | ||
| ->where(fn ($query) => $query | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mark as delivered can be used to provide links/update links even when the request is closed. hence the change. |
||
| ->where('status', '=', PaymentStatusType::COMPLETED) | ||
| ->orWhere('status', '=', PaymentStatusType::CLOSED)) | ||
| ->where('id', '=', $order_id) | ||
| ->firstOrFail(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, only Dummy is successful directly. Later consider the other cases but I expect most integration will have a redirection.