Skip to content

Commit

Permalink
Do some fixes on routing to avoid problems and duplication with other…
Browse files Browse the repository at this point in the history
… plugins
  • Loading branch information
lruozzi9 committed Aug 5, 2024
1 parent baabe02 commit 662ddfd
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@
4. Import the routes needed for cancelling the payments. Add the following to your config/routes.yaml file:
```yaml
webgriffe_sylius_pagolight_plugin:
webgriffe_sylius_pagolight_plugin_shop:
resource: "@WebgriffeSyliusPagolightPlugin/config/shop_routing.php"
prefix: /{_locale}
requirements:
_locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$
webgriffe_sylius_pagolight_plugin_ajax:
resource: "@WebgriffeSyliusPagolightPlugin/config/shop_ajax_routing.php"
sylius_shop_payum_cancel:
resource: "@PayumBundle/Resources/config/routing/cancel.xml"
```
**NB:** you should avoid to have any param prefix in your routes, otherwise the plugin won't work properly.
**NB:** The file shop_routing needs to be after the prefix _locale, so that messages can be displayed in the right
language. You should also include the cancel routes from the Payum bundle if you do not have it already!
5. Add the WebhookToken entity. Create a new file `src/Entity/Payment/WebhookToken.php` with the following content:
```php
Expand Down
13 changes: 13 additions & 0 deletions config/shop_ajax_routing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function (RoutingConfigurator $routes): void {
$routes->add('webgriffe_sylius_pagolight_plugin_payment_status', '/payment/{paymentId}/status')
->controller(['webgriffe_sylius_pagolight.controller.payment', 'statusAction'])
->methods(['GET'])
->requirements(['paymentId' => '\d+'])
;
};
10 changes: 1 addition & 9 deletions config/shop_routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function (RoutingConfigurator $routes): void {
$routes->import('@PayumBundle/Resources/config/routing/cancel.xml');

$routes->add('webgriffe_sylius_pagolight_plugin_payment_process', '/order/{tokenValue}/payment/process')
$routes->add('webgriffe_sylius_pagolight_plugin_payment_process', '/order/{tokenValue}/payment/pagolight-process')
->controller(['webgriffe_sylius_pagolight.controller.payment', 'processAction'])
->methods(['GET'])
;

$routes->add('webgriffe_sylius_pagolight_plugin_payment_status', '/payment/{paymentId}/status')
->controller(['webgriffe_sylius_pagolight.controller.payment', 'statusAction'])
->methods(['GET'])
->requirements(['paymentId' => '\d+'])
;
};
12 changes: 6 additions & 6 deletions public/poll_payment.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
(function () {
async function checkForCapturedPayment() {
try {
const response = await fetch(window.paymentStatusUrl);
const data = await response.json();
const response = await fetch(window.paymentStatusUrl)
const data = await response.json()

if (data.captured) {
window.location.replace(window.afterUrl);
window.location.replace(window.afterUrl)
return;
}
} catch (e) {
console.log(e);
console.log(e)
}

setTimeout(checkForCapturedPayment, 5000);
setTimeout(checkForCapturedPayment, 5000)
}

checkForCapturedPayment();
checkForCapturedPayment()
})();

4 changes: 3 additions & 1 deletion templates/Process/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<img src="{{ asset('build/shop/images/loading.gif', 'shop') }}" alt="{{ 'webgriffe_sylius_pagolight.ui.loading'|trans }}">

{% if redirectUrl %}
<p>{{ 'webgriffe_sylius_pagolight.ui.return_to_pagolight_checkout'|trans({'{redirectUrl}': redirectUrl})|raw }}</p>
<a href="{{ redirectUrl }}">
{{ 'webgriffe_sylius_pagolight.ui.return_to_pagolight_checkout'|trans }}
</a>
{% endif %}
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
webgriffe_sylius_pagolight_plugin:
webgriffe_sylius_pagolight_plugin_shop:
resource: "@WebgriffeSyliusPagolightPlugin/config/shop_routing.php"
prefix: /{_locale}
requirements:
_locale: ^[a-z]{2}(?:_[A-Z]{2})?$
_locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$

webgriffe_sylius_pagolight_plugin_ajax:
resource: "@WebgriffeSyliusPagolightPlugin/config/shop_ajax_routing.php"

sylius_shop_payum_cancel:
resource: "@PayumBundle/Resources/config/routing/cancel.xml"

0 comments on commit 662ddfd

Please sign in to comment.