diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..1871015 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,4 @@ +* benjamin.freoua@getalma.eu +* claire.bonachera@getalma.eu +* francois.gomis@getalma.eu + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..977e538 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,31 @@ +### Reason for change + + + +[ClickUp task](https://app.clickup.com/20427503/v/b/4-32476982-2/CLICKUP_ISSUE_ID) + +### Code changes + + + +### How to test + +_As a reviewer, you are encouraged to test the PR locally._ + + + +### Checklist for authors and reviewers + + + +- [ ] The title of the PR uses business wording, not technical jargon, for the changelog readers to understand it +- [ ] The PR implements the changes asked in the referenced task / issue +- [ ] The automated tests are compliant with the [testing strategy](https://www.notion.so/almapay/Backend-testing-strategy-06c642cec1bf47b9b8feca3a91ea8d4a) +- [ ] The tests are relevant, and cover the corner/error cases, not only the happy path +- [ ] You understand the impact of this PR on existing code/features +- [ ] The changes include adequate logging and Datadog traces +- [ ] Documentation is updated (API, developer documentation, ADR, Notion...) + +### Non applicable + + \ No newline at end of file diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..008ab7f --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,30 @@ +name: PHP Composer + +on: + push: + branches: [main,develop] + pull_request: + branches: [main,develop] + workflow_dispatch: ~ + +jobs: + lint: + runs-on: ubuntu-20.04 + defaults: + run: + working-directory: . + + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + diff --git a/.gitignore b/.gitignore index f486a1f..bc9be13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /vendor/ /node_modules/ /composer.lock - +.idea/* /etc/build/* !/etc/build/.gitignore @@ -11,3 +11,4 @@ /behat.yml /phpspec.yml /phpunit.xml +/crowdin.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index cf543ff..9223d23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +v2.0.0 +------ + +- Fix: Compatibility Sylius 1.12 +- Feat: Add installment P10/12X +- Feat: Display installment's plan in checkout page + v1.3.0 ------ diff --git a/README.md b/README.md index 67a4858..ef2b530 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- logo alma + logo alma

@@ -10,26 +10,54 @@ ## Documentation ### Installation -Use Composer to install the plugin: +1. Use Composer to install the plugin: ``` $ composer require alma/sylius-payment-plugin ``` -Update your shop's translation catalogs: +2. Import routes: + +``` +# config/routes/sylius_shop.yaml + +sylius_alma: + resource: "@AlmaSyliusPaymentPlugin/Resources/config/shop_routing.yaml" + prefix: /{_locale} + requirements: + _locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$ +``` + +3. Override Sylius' templates: + +``` +cp -R vendor/alma/sylius-payment-plugin/src/Resources/views/bundles/* templates/bundles/ +``` + +4. Export assets: + +``` +bin/console sylius:install:asset +``` + +5. Update your shop's translation catalogs: ``` $ php bin/console translation:update --dump-messages fr AlmaSyliusPaymentPlugin $ php bin/console translation:update --dump-messages en AlmaSyliusPaymentPlugin ``` -Finally, clear your cache: +6. Finally, clear your cache: ``` $ php bin/console cache:clear ``` ### Requirements + +- PHP version >= 7.3 +- Sylius version >= 1.9.0 + Alma currently accepts Euros only; make sure you activate your payment method on channels that use that currency, else you won't see it at checkout. diff --git a/behat.yml.dist b/behat.yml.dist index 962eb94..20c0cd4 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -6,7 +6,7 @@ default: extensions: DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~ - Lakion\Behat\MinkDebugExtension: + FriendsOfBehat\MinkDebugExtension: directory: etc/build clean_start: false screenshot: true diff --git a/composer.json b/composer.json index e4144f5..d87c232 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "description": "Payment plugin to integrate Alma installments and pay later payments with your Sylius shop", "license": "MIT", "require": { - "php": ">=7.1", - "alma/alma-php-client": "^1.11.1", - "sylius/sylius": ">=1.6.9", + "php": "~7.3 || ~7.4 || ~8.0 || ~8.1 || ~8.2", + "alma/alma-php-client": ">=1.11.2", + "sylius/sylius": ">=v1.9.0", "ext-json": "*" }, "require-dev": { @@ -30,23 +30,23 @@ "friends-of-behat/suite-settings-extension": "^1.0", "friends-of-behat/symfony-extension": "^2.1", "friends-of-behat/variadic-extension": "^1.3", - "friends-of-behat/mink-debug-extension": "^2.1.0", - "phpspec/phpspec": "^6.1|^7.0", + "friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev", + "lakion/mink-debug-extension": "^2.0.0", + "phpspec/phpspec": "^7.0", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "1.10.29", - "phpstan/phpstan-doctrine": "^1.3.42", - "phpstan/phpstan-strict-rules": "^1.5.1", - "phpstan/phpstan-webmozart-assert": "^1.2.4", - "phpunit/phpunit": "^8.5", + "phpstan/phpstan": "0.12.88", + "phpstan/phpstan-doctrine": "0.12.37", + "phpstan/phpstan-strict-rules": "^0.12.0", + "phpstan/phpstan-webmozart-assert": "0.12.12", + "phpunit/phpunit": "^9.5", "sensiolabs/security-checker": "^6.0", - "sylius-labs/coding-standard": "^4.3.1", - "symfony/browser-kit": "^4.4", - "symfony/debug-bundle": "^4.4|^5.0", - "symfony/dotenv": "^4.4|^5.0", - "symfony/intl": "^4.4|^5.0", - "symfony/web-profiler-bundle": "^4.4|^5.0", - "symfony/web-server-bundle": "^4.4|^5.0", - "vimeo/psalm": "3.11.4" + "sylius-labs/coding-standard": "^3.1", + "symfony/browser-kit": "^4.4 || ^5.2", + "symfony/debug-bundle": "^4.4 || ^5.2", + "symfony/dotenv": "^4.4 || ^5.2", + "symfony/intl": "^4.4 || ^5.2", + "symfony/web-profiler-bundle": "^4.4 || ^5.2", + "vimeo/psalm": "4.6.4" }, "autoload": { "psr-4": { @@ -62,12 +62,19 @@ "Tests\\Alma\\SyliusPaymentPlugin\\": "tests/" } }, + "authors": [ + { + "name": "Alma", + "email": "contact@almapay.com" + } + ], "config": { "sort-packages": true, "allow-plugins": { "symfony/thanks": true, "dealerdirect/phpcodesniffer-composer-installer": true, - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "symfony/flex": true } } } diff --git a/crowdin.example.yaml b/crowdin.example.yaml new file mode 100644 index 0000000..63dc09e --- /dev/null +++ b/crowdin.example.yaml @@ -0,0 +1,13 @@ +"project_id" : "35" +"api_token" : "MY_API_TOKEN" +"base_path" : "src/" +"base_url" : "https://mycompany.crowdin.com" +"preserve_hierarchy": true + +files: + - + source: Resources/translations/messages.en.yml + translation: Resources/translations/messages.%two_letters_code%.yml + - + source: Resources/translations/flashes.en.yml + translation: Resources/translations/flashes.%two_letters_code%.yml \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 0de6f71..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,15 +0,0 @@ -parameters: - customRulesetUsed: true - reportUnmatchedIgnoredErrors: false - checkMissingIterableValueType: false - - excludes_analyse: - # Makes PHPStan crash - - 'src/DependencyInjection/Configuration.php' - - # Test dependencies - - 'tests/Application/app/**.php' - - 'tests/Application/src/**.php' - - ignoreErrors: - - '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./' diff --git a/src/AlmaSyliusPaymentPlugin.php b/src/AlmaSyliusPaymentPlugin.php index d61e35d..8b152a2 100644 --- a/src/AlmaSyliusPaymentPlugin.php +++ b/src/AlmaSyliusPaymentPlugin.php @@ -11,7 +11,7 @@ final class AlmaSyliusPaymentPlugin extends Bundle { - const VERSION = "1.3.0"; + const VERSION = "2.0.0"; use SyliusPluginTrait; diff --git a/src/Bridge/AlmaBridge.php b/src/Bridge/AlmaBridge.php index 9492920..10ed236 100644 --- a/src/Bridge/AlmaBridge.php +++ b/src/Bridge/AlmaBridge.php @@ -141,6 +141,23 @@ function getEligibilities(PaymentInterface $payment, array $installmentsCounts): return []; } + /** + * Retrieve the eligibilities from the data array sent + * + * @param array $data + * @return \Alma\API\Endpoints\Results\Eligibility|\Alma\API\Endpoints\Results\Eligibility[]|array + */ + public function retrieveEligibilities(array $data) + { + $alma = $this->getDefaultClient(); + try { + return $alma->payments->eligibility($data, true); + } catch (RequestError $e) { + $this->logger->error("[Alma] Eligibility call failed with error: " . $e->getMessage()); + } + + return []; + } /** * @inheritDoc */ diff --git a/src/Controller/InstallmentsController.php b/src/Controller/InstallmentsController.php new file mode 100644 index 0000000..df25bbf --- /dev/null +++ b/src/Controller/InstallmentsController.php @@ -0,0 +1,117 @@ +twig = $twig; + $this->orderRepository = $orderRepository; + $this->paymentMethodRepository = $paymentMethodRepository; + $this->eligibilityHelper = $eligibilityHelper; + $this->logger = $logger; + } + + /** + * @param Request $request + * @return Response + */ + public function renderInstallmentPlanAction(Request $request): Response + { + try { + $orderId = $request->attributes->getInt('orderId'); + $methodId = $request->attributes->getInt('methodPaymentId'); + + /** @var OrderInterface $order */ + $order = $this->orderRepository->find($orderId); + + /** @var PaymentMethodInterface $paymentMethod */ + $paymentMethod = $this->paymentMethodRepository->find($methodId); + $installmentsCount = $paymentMethod->getGatewayConfig()->getConfig()["installments_count"]; + $totalCart = $order->getTotal(); + + $eligibilities = $this->eligibilityHelper->getEligibilities( + $totalCart, + $installmentsCount, + $order->getBillingAddress()->getCountryCode(), + $order->getShippingAddress()->getCountryCode(), + substr($request->getLocale(), 0, 2) + ); + /** + * @var FeePlan $plan + */ + $plan = $eligibilities['general_'.$installmentsCount.'_0_0']; + + return new Response($this->twig->render('@AlmaSyliusPaymentPlugin/installmentPlan.html.twig', [ + 'plans' => $plan, + 'installmentsCount' => $installmentsCount, + 'creditInfo' => [ + 'totalCart' => $totalCart, + 'costCredit' => $plan->customerTotalCostAmount, + 'totalCredit' => $plan->customerTotalCostAmount + $totalCart, + 'taeg' => $plan->annualInterestRate, + ] + ])); + } catch (\Exception $exception) { + $this->logger->error( + sprintf( + '[Alma] An error as occurred %s', + $exception->getMessage() + ), $exception->getTrace() + ); + + return new Response(''); + } + } +} diff --git a/src/DataBuilder/EligibilityDataBuilder.php b/src/DataBuilder/EligibilityDataBuilder.php new file mode 100644 index 0000000..94b27f5 --- /dev/null +++ b/src/DataBuilder/EligibilityDataBuilder.php @@ -0,0 +1,43 @@ + $amount, + "queries" => [ + [ + "installments_count" => $installmentCounts, + "deferred_days" => "0", + "deferred_months" => "0" + ] + ], + "billing_address" => [ + "country" => $billingCountryCode, + ], + "shipping_address" => [ + "country" => $shippingCountryCode + ], + "locale" => $locale, + ]; + } +} \ No newline at end of file diff --git a/src/Form/Type/AlmaGatewayConfigurationType.php b/src/Form/Type/AlmaGatewayConfigurationType.php index 4676fb5..47286c2 100644 --- a/src/Form/Type/AlmaGatewayConfigurationType.php +++ b/src/Form/Type/AlmaGatewayConfigurationType.php @@ -89,6 +89,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ['%installments_count%' => 3]) => 3, $this->translator->trans('alma_sylius_payment_plugin.config.installments_count_choice_label', ['%installments_count%' => 4]) => 4, + $this->translator->trans('alma_sylius_payment_plugin.config.installments_count_choice_label', + ['%installments_count%' => 10]) => 10, + $this->translator->trans('alma_sylius_payment_plugin.config.installments_count_choice_label', + ['%installments_count%' => 12]) => 12, ], 'label' => $this->translator->trans('alma_sylius_payment_plugin.config.installments_count_label'), ] diff --git a/src/Helper/EligibilityHelper.php b/src/Helper/EligibilityHelper.php new file mode 100644 index 0000000..ea0f77d --- /dev/null +++ b/src/Helper/EligibilityHelper.php @@ -0,0 +1,64 @@ +almaBridge = $almaBridge; + $this->eligibilityDataBuilder = $eligibilityDataBuilder; + } + + /** + * @param int $amount + * @param int $installmentCounts + * @param string $billingCountryCode + * @param string $shippingCountryCode + * @param string $locale + * @return Eligibility|Eligibility[]|array + */ + public function getEligibilities( + int $amount, + int $installmentCounts, + string $billingCountryCode, + string $shippingCountryCode, + string $locale + ) + { + $data = $this->eligibilityDataBuilder; + + return $this->almaBridge->retrieveEligibilities( + $data( + $amount, + $installmentCounts, + $billingCountryCode, + $shippingCountryCode, + $locale + ) + ); + } +} \ No newline at end of file diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 4f6caa7..a9f22f4 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -1,7 +1,10 @@ imports: - services/api.yml + - services/helpers.yml + - services/assets.yml + - services/controllers.yml - services/gateway.yml - services/actions.yml - services/extensions.yml - services/resolvers.yml - - services/data_builders.yml + - services/data_builders.yml \ No newline at end of file diff --git a/src/Resources/config/services/assets.yml b/src/Resources/config/services/assets.yml new file mode 100644 index 0000000..16910c4 --- /dev/null +++ b/src/Resources/config/services/assets.yml @@ -0,0 +1,7 @@ +services: + app.block_event_listener.layout.after_javascripts: + class: Sylius\Bundle\UiBundle\Block\BlockEventListener + arguments: + - '@@AlmaSyliusPaymentPlugin/_partials/_javascript.html.twig' + tags: + - { name: kernel.event_listener, event: sonata.block.event.sylius.shop.layout.javascripts, method: onBlockEvent } diff --git a/src/Resources/config/services/controllers.yml b/src/Resources/config/services/controllers.yml new file mode 100644 index 0000000..5ee75e6 --- /dev/null +++ b/src/Resources/config/services/controllers.yml @@ -0,0 +1,15 @@ +services: + _defaults: + public: true + autowire: true + + Alma\SyliusPaymentPlugin\Controller\InstallmentsController: + class: Alma\SyliusPaymentPlugin\Controller\InstallmentsController + public: true + arguments: + $twig: '@twig' + $orderRepository: '@sylius.repository.order' + $paymentMethodRepository: '@sylius.repository.payment_method' + $eligibilityHelper: '@alma.sylius_payment_plugin.helper.eligibility' + $logger: '@logger' + tags: [ 'controller.service_arguments' ] diff --git a/src/Resources/config/services/data_builders.yml b/src/Resources/config/services/data_builders.yml index aaae6f3..4aa1fff 100644 --- a/src/Resources/config/services/data_builders.yml +++ b/src/Resources/config/services/data_builders.yml @@ -37,7 +37,7 @@ services: - name: alma_sylius_payment_plugin.payment_data_builder id: shipping_info - alma_sylius_payment_plugin.payment_data_builder.cart : + alma_sylius_payment_plugin.payment_data_builder.cart: class: Alma\SyliusPaymentPlugin\DataBuilder\CartDataBuilder arguments: $router: '@router' @@ -46,3 +46,8 @@ services: tags: - name: alma_sylius_payment_plugin.payment_data_builder id: cart + alma_sylius_payment_plugin.eligibility_data_builder: + class: Alma\SyliusPaymentPlugin\DataBuilder\EligibilityDataBuilder + tags: + - name: alma_sylius_payment_plugin.eligibility_data_builder + id: eligibility diff --git a/src/Resources/config/services/extensions.yml b/src/Resources/config/services/extensions.yml index d8610c7..1eaa59c 100644 --- a/src/Resources/config/services/extensions.yml +++ b/src/Resources/config/services/extensions.yml @@ -8,3 +8,8 @@ services: tags: - name: payum.extension factory: alma_payments + + Alma\SyliusPaymentPlugin\Twig\AlmaExtension: + public: true + tags: + - name: twig.extension diff --git a/src/Resources/config/services/helpers.yml b/src/Resources/config/services/helpers.yml new file mode 100644 index 0000000..4e0c53f --- /dev/null +++ b/src/Resources/config/services/helpers.yml @@ -0,0 +1,6 @@ +services: + alma.sylius_payment_plugin.helper.eligibility: + class: Alma\SyliusPaymentPlugin\Helper\EligibilityHelper + arguments: + $almaBridge: '@alma_sylius_payment_plugin.bridge' + $eligibilityDataBuilder: '@alma_sylius_payment_plugin.eligibility_data_builder' \ No newline at end of file diff --git a/src/Resources/config/shop_routing.yaml b/src/Resources/config/shop_routing.yaml new file mode 100644 index 0000000..2603944 --- /dev/null +++ b/src/Resources/config/shop_routing.yaml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin_render_plans: + path: /alma-render-plans/{orderId} + methods: [GET] + defaults: + _controller: alma_sylius_payment_plugin.controller.installments::renderInstallmentPlanAction diff --git a/src/Resources/public/css/alma.css b/src/Resources/public/css/alma.css new file mode 100644 index 0000000..65dbf27 --- /dev/null +++ b/src/Resources/public/css/alma.css @@ -0,0 +1,9 @@ +.alma .grey { + color: #7a7a7a; +} +.alma .ui.tiny.header{ + font-size: 1rem !important; +} +.alma .hidden{ + display: none; +} \ No newline at end of file diff --git a/src/Resources/public/img/15j_logo.svg b/src/Resources/public/img/15j_logo.svg new file mode 100644 index 0000000..52f9e71 --- /dev/null +++ b/src/Resources/public/img/15j_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/30j_logo.svg b/src/Resources/public/img/30j_logo.svg new file mode 100644 index 0000000..8abdd05 --- /dev/null +++ b/src/Resources/public/img/30j_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/45j_logo.svg b/src/Resources/public/img/45j_logo.svg new file mode 100644 index 0000000..d50a4b3 --- /dev/null +++ b/src/Resources/public/img/45j_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/alma-logo.svg b/src/Resources/public/img/alma-logo.svg new file mode 100644 index 0000000..d284c39 --- /dev/null +++ b/src/Resources/public/img/alma-logo.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/src/Resources/public/img/p10x_logo.svg b/src/Resources/public/img/p10x_logo.svg new file mode 100644 index 0000000..6c2f37b --- /dev/null +++ b/src/Resources/public/img/p10x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p11x_logo.svg b/src/Resources/public/img/p11x_logo.svg new file mode 100644 index 0000000..4a5cfa9 --- /dev/null +++ b/src/Resources/public/img/p11x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p12x_logo.svg b/src/Resources/public/img/p12x_logo.svg new file mode 100644 index 0000000..d4fbe0c --- /dev/null +++ b/src/Resources/public/img/p12x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p1x_logo.svg b/src/Resources/public/img/p1x_logo.svg new file mode 100644 index 0000000..5341da0 --- /dev/null +++ b/src/Resources/public/img/p1x_logo.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/Resources/public/img/p2x_logo.svg b/src/Resources/public/img/p2x_logo.svg new file mode 100644 index 0000000..586ce1a --- /dev/null +++ b/src/Resources/public/img/p2x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p3x_logo.svg b/src/Resources/public/img/p3x_logo.svg new file mode 100644 index 0000000..8d19624 --- /dev/null +++ b/src/Resources/public/img/p3x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p4x_logo.svg b/src/Resources/public/img/p4x_logo.svg new file mode 100644 index 0000000..f3d9bee --- /dev/null +++ b/src/Resources/public/img/p4x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p5x_logo.svg b/src/Resources/public/img/p5x_logo.svg new file mode 100644 index 0000000..fca5d78 --- /dev/null +++ b/src/Resources/public/img/p5x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p6x_logo.svg b/src/Resources/public/img/p6x_logo.svg new file mode 100644 index 0000000..e81aafa --- /dev/null +++ b/src/Resources/public/img/p6x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p7x_logo.svg b/src/Resources/public/img/p7x_logo.svg new file mode 100644 index 0000000..2a27a6c --- /dev/null +++ b/src/Resources/public/img/p7x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p8x_logo.svg b/src/Resources/public/img/p8x_logo.svg new file mode 100644 index 0000000..eee4888 --- /dev/null +++ b/src/Resources/public/img/p8x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/img/p9x_logo.svg b/src/Resources/public/img/p9x_logo.svg new file mode 100644 index 0000000..b4f1cd4 --- /dev/null +++ b/src/Resources/public/img/p9x_logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Resources/public/js/alma.js b/src/Resources/public/js/alma.js new file mode 100644 index 0000000..9b6df68 --- /dev/null +++ b/src/Resources/public/js/alma.js @@ -0,0 +1,12 @@ +$(function() { + if ($('.alma.ui').length > 0) { + $('.ui.form .item').each(function (i, e) { + $(e).find('.ui.radio').on('click', function () { + $('.ui.form .item .content .hidden').hide(); + if ($(e).find('input[type=radio]').is(':checked')) { + $(e).find('.hidden').show(); + } + }); + }); + } +}); \ No newline at end of file diff --git a/src/Resources/translations/flashes.de.yml b/src/Resources/translations/flashes.de.yml new file mode 100644 index 0000000..3c9c6d5 --- /dev/null +++ b/src/Resources/translations/flashes.de.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: Es ist ein Fehler aufgetreten. Ihre Alma-Zahlung wurde vollständig zurückerstattet. Bitte versuchen Sie es erneut. + failed_not_refunded: 'Es ist ein Fehler aufgetreten und Ihre Alma-Zahlung konnte nicht erstattet werden. Bitte kontaktieren Sie uns und geben Sie die folgende Referenz an: %pid%' + creation_failed: Bei der Initialisierung der Zahlung ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut oder wählen Sie eine andere Zahlungsmethode. diff --git a/src/Resources/translations/flashes.es.yml b/src/Resources/translations/flashes.es.yml new file mode 100644 index 0000000..16020f7 --- /dev/null +++ b/src/Resources/translations/flashes.es.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: Se ha producido un error. Su pago Alma ha sido reembolsado en su totalidad. Por favor, inténtelo de nuevo. + failed_not_refunded: 'Se ha producido un error y no se ha podido reembolsar su pago Alma. Póngase en contacto con nosotros y facilítenos la siguiente referencia: %pid%' + creation_failed: Se ha producido un error durante la inicialización del pago. Por favor, inténtelo de nuevo o elija otro método de pago. diff --git a/src/Resources/translations/flashes.it.yml b/src/Resources/translations/flashes.it.yml new file mode 100644 index 0000000..d6e46d8 --- /dev/null +++ b/src/Resources/translations/flashes.it.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: Si è verificato un errore. Il pagamento Alma è stato completamente rimborsato. Si prega di riprovare. + failed_not_refunded: 'Si è verificato un errore e non è stato possibile rimborsare il pagamento Alma. Si prega di contattarci e di fornire il seguente riferimento: %pid%' + creation_failed: Si è verificato un errore durante l'inizializzazione del pagamento. Riprovare o scegliere un altro metodo di pagamento. diff --git a/src/Resources/translations/flashes.nl.yml b/src/Resources/translations/flashes.nl.yml new file mode 100644 index 0000000..f2bfe60 --- /dev/null +++ b/src/Resources/translations/flashes.nl.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: Er heeft zich een fout voorgedaan. Uw Alma-betaling is volledig terugbetaald. Probeer het opnieuw. + failed_not_refunded: 'Er is een fout opgetreden en uw Alma-betaling kon niet worden terugbetaald. Neem contact met ons op en vermeld de volgende referentie: %pid%' + creation_failed: Er is een fout opgetreden tijdens het initialiseren van de betaling. Probeer het opnieuw of kies een andere betaalmethode. diff --git a/src/Resources/translations/flashes.pt.yml b/src/Resources/translations/flashes.pt.yml new file mode 100644 index 0000000..28f09f6 --- /dev/null +++ b/src/Resources/translations/flashes.pt.yml @@ -0,0 +1,5 @@ +alma_sylius_payment_plugin: + payment: + failed_refunded: Ocorreu um erro. O seu pagamento Alma foi totalmente reembolsado. Por favor, tente novamente. + failed_not_refunded: 'Ocorreu um erro e não foi possível efetuar o reembolso do seu pagamento Alma. Por favor, contacte-nos e indique a seguinte referência: %pid%' + creation_failed: Ocorreu um erro durante a inicialização do pagamento. Tente novamente ou seleccione outro método de pagamento. diff --git a/src/Resources/translations/messages.de.yml b/src/Resources/translations/messages.de.yml new file mode 100644 index 0000000..06f27c9 --- /dev/null +++ b/src/Resources/translations/messages.de.yml @@ -0,0 +1,29 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Live-API-Schlüssel + test_api_key_label: API-Schlüssel testen + find_api_keys_in_dashboard: Sie können Ihre API-Schlüssel auf Ihrem Dashboardfinden. + api_mode_label: API-Modus + api_mode_tip: Da der Testmodus den Abschluss einer Bestellung mit einer Testkreditkarte ermöglicht, sollten Sie ihn nicht in der Produktion aktivieren. + installments_count_label: Raten zählen + installments_count_choice_label: '%installments_count% Ratenzahlungen' + payment_page_mode_label: Modus der Zahlungsseite + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Weiterleitung zu Alma (empfohlen) + errors: + invalid_api_key: API-Schlüssel ist ungültig + empty_api_key: Bitte geben Sie einen API-Schlüssel an + api: + live_mode: Live + test_mode: Test + checkout: + logo_alma: Logo Alma + fast_and_secure_payment_by_credit_card: Schnelle und sichere Zahlung per Kreditkarte + today: Heute + installment_one_line: '%firstAmount% heute dann %installment% x %nextAmount%' + your_credit: Ihr Kredit + cart_total: Warenkorb gesamt + cost_of_credit: Kosten des Kredits + fixed_apr: Fester effektiver Jahreszins + total: Insgesamt + including_fees: "Einschließlich Gebühren: %includingFees%" diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 55b9228..5062ca0 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -3,21 +3,27 @@ alma_sylius_payment_plugin: live_api_key_label: Live API key test_api_key_label: Test API key find_api_keys_in_dashboard: You can find your API keys on your dashboard. - api_mode_label: API mode api_mode_tip: As the Test mode allows completing an order with a test credit card, you should avoid activating it in production. - installments_count_label: Installments count installments_count_choice_label: '%installments_count% installments' - payment_page_mode_label: Payment page mode payment_page_mode_in_page: Iframe - payment_page_mode_redirect: Redirect to Alma - + payment_page_mode_redirect: Redirect to Alma (Recommended) errors: invalid_api_key: API key is invalid empty_api_key: Please provide an API key - api: live_mode: Live test_mode: Test + checkout: + logo_alma: Logo Alma + fast_and_secure_payment_by_credit_card: Fast and secure payment by credit card + today: Today + installment_one_line: '%firstAmount% today then %installment% x %nextAmount%' + your_credit: Your credit + cart_total: Cart total + cost_of_credit: Cost of credit + fixed_apr: Fixed APR + total: Total + including_fees: "Including fees: %includingFees%" diff --git a/src/Resources/translations/messages.es.yml b/src/Resources/translations/messages.es.yml new file mode 100644 index 0000000..d4e3902 --- /dev/null +++ b/src/Resources/translations/messages.es.yml @@ -0,0 +1,29 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Clave Live API + test_api_key_label: Clave API de prueba + find_api_keys_in_dashboard: Puede encontrar sus claves API en su panel de control. + api_mode_label: Modo API + api_mode_tip: Como el modo de prueba permite completar un pedido con una tarjeta de crédito de prueba, debe evitar activarlo en producción. + installments_count_label: Los plazos cuentan + installments_count_choice_label: '%installments_count% plazos' + payment_page_mode_label: Modo de página de pago + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Redirigir a Alma (Recomendado) + errors: + invalid_api_key: La clave API no es válida + empty_api_key: Proporcione una clave API + api: + live_mode: En directo + test_mode: Prueba + checkout: + logo_alma: Logo Alma + fast_and_secure_payment_by_credit_card: Pago rápido y seguro con tarjeta de crédito + today: Hoy + installment_one_line: '%firstAmount% hoy entonces %installment% x %nextAmount%' + your_credit: Su crédito + cart_total: Total de la cesta + cost_of_credit: Coste del crédito + fixed_apr: TAE fija + total: Total + including_fees: "Tasas incluidas: %includingFees%" diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 3b71c65..8c8de37 100644 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -3,21 +3,27 @@ alma_sylius_payment_plugin: live_api_key_label: Clé d'API Live test_api_key_label: Clé d'API Test find_api_keys_in_dashboard: Vous trouverez vos clés d'API sur votre dashboard. - api_mode_label: Mode de l'API api_mode_tip: Le mode Test permet de finaliser une commande avec une carte bancaire de test, évitez donc son activation en production. - installments_count_label: Nombre d'échéances installments_count_choice_label: '%installments_count% échéances' - payment_page_mode_label: Mode de la page de paiement payment_page_mode_in_page: Intégré (iframe) - payment_page_mode_redirect: Redirection vers Alma - + payment_page_mode_redirect: Redirection vers Alma (Recommandé) errors: invalid_api_key: Clé d'API invalide empty_api_key: La clé d'API doit être renseignée - api: live_mode: Live test_mode: Test + checkout: + logo_alma: Logo Alma + fast_and_secure_payment_by_credit_card: Paiement rapide et sécurisé, par carte bancaire. + today: "Aujourd'hui" + installment_one_line: "%firstAmount% aujourd'hui puis %installment% x %nextAmount%" + your_credit: Votre crédit + cart_total: Votre panier + cost_of_credit: Coût du crédit + fixed_apr: TAEG fixe + total: Total + including_fees: "Dont frais inclus: %includingFees%" diff --git a/src/Resources/translations/messages.it.yml b/src/Resources/translations/messages.it.yml new file mode 100644 index 0000000..23bbbbf --- /dev/null +++ b/src/Resources/translations/messages.it.yml @@ -0,0 +1,29 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Chiave API live + test_api_key_label: Chiave API di prova + find_api_keys_in_dashboard: Potete trovare le vostre chiavi API sul vostro cruscotto. + api_mode_label: Modalità API + api_mode_tip: Poiché la modalità di prova consente di completare un ordine con una carta di credito di prova, si dovrebbe evitare di attivarla in produzione. + installments_count_label: Conteggio delle rate + installments_count_choice_label: '%installments_count% rate' + payment_page_mode_label: Modalità della pagina di pagamento + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Reindirizzamento ad Alma (consigliato) + errors: + invalid_api_key: La chiave API non è valida + empty_api_key: Fornire una chiave API + api: + live_mode: In diretta + test_mode: Test + checkout: + logo_alma: Logo Alma + fast_and_secure_payment_by_credit_card: Pagamento rapido e sicuro con carta di credito + today: Oggi + installment_one_line: '%firstAmount% oggi poi %installment% x %nextAmount%' + your_credit: Il vostro credito + cart_total: Totale carrello + cost_of_credit: Costo del credito + fixed_apr: TAEG fisso + total: Totale + including_fees: "Comprese le tasse: %includingFees%" diff --git a/src/Resources/translations/messages.nl.yml b/src/Resources/translations/messages.nl.yml new file mode 100644 index 0000000..339e922 --- /dev/null +++ b/src/Resources/translations/messages.nl.yml @@ -0,0 +1,29 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Live API-sleutel + test_api_key_label: Test API-sleutel + find_api_keys_in_dashboard: Je kunt je API-sleutels vinden op je dashboard. + api_mode_label: API-modus + api_mode_tip: Aangezien je met de Testmodus een bestelling kunt voltooien met een testcreditcard, moet je deze modus niet activeren in productie. + installments_count_label: Termijnen tellen + installments_count_choice_label: '%installments_count% termijnen' + payment_page_mode_label: Modus betalingspagina + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Doorverwijzen naar Alma (aanbevolen) + errors: + invalid_api_key: API-sleutel is ongeldig + empty_api_key: Geef een API-sleutel op + api: + live_mode: Live + test_mode: Test + checkout: + logo_alma: Logo Alma + fast_and_secure_payment_by_credit_card: Snelle en veilige betaling met creditcard + today: Vandaag + installment_one_line: '%firstAmount% vandaag dan %installment% x %nextAmount%' + your_credit: Uw krediet + cart_total: Totaal winkelwagen + cost_of_credit: Kosten van krediet + fixed_apr: Vast JKP + total: Totaal + including_fees: "Inclusief kosten: %includingFees%" diff --git a/src/Resources/translations/messages.pt.yml b/src/Resources/translations/messages.pt.yml new file mode 100644 index 0000000..226ffbe --- /dev/null +++ b/src/Resources/translations/messages.pt.yml @@ -0,0 +1,29 @@ +alma_sylius_payment_plugin: + config: + live_api_key_label: Chave da API em direto + test_api_key_label: Testar chave API + find_api_keys_in_dashboard: Pode encontrar as suas chaves API no seu painel de controlo. + api_mode_label: Modo API + api_mode_tip: Uma vez que o modo de teste permite concluir uma encomenda com um cartão de crédito de teste, deve evitar activá-lo na produção. + installments_count_label: As prestações contam + installments_count_choice_label: '%installments_count% prestações' + payment_page_mode_label: Modo da página de pagamento + payment_page_mode_in_page: Iframe + payment_page_mode_redirect: Redirecionar para Alma (Recomendado) + errors: + invalid_api_key: A chave da API é inválida + empty_api_key: Fornecer uma chave API + api: + live_mode: Em direto + test_mode: Teste + checkout: + logo_alma: Logótipo Alma + fast_and_secure_payment_by_credit_card: Pagamento rápido e seguro por cartão de crédito + today: Hoje + installment_one_line: '%firstAmount% hoje então %installment% x %nextAmount%' + your_credit: O seu crédito + cart_total: Total do carrinho + cost_of_credit: Custo do crédito + fixed_apr: TAEG fixa + total: Total + including_fees: "Incluindo taxas: %includingFees%" diff --git a/src/Resources/views/_partials/_almaCredit.html.twig b/src/Resources/views/_partials/_almaCredit.html.twig new file mode 100644 index 0000000..c245549 --- /dev/null +++ b/src/Resources/views/_partials/_almaCredit.html.twig @@ -0,0 +1,34 @@ +{% set firstAmount = plans.paymentPlan[0].total_amount %} +{% set nextAmount = plans.paymentPlan[1].total_amount %} + \ No newline at end of file diff --git a/src/Resources/views/_partials/_almaPnx.html.twig b/src/Resources/views/_partials/_almaPnx.html.twig new file mode 100644 index 0000000..9b18a72 --- /dev/null +++ b/src/Resources/views/_partials/_almaPnx.html.twig @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/src/Resources/views/_partials/_javascript.html.twig b/src/Resources/views/_partials/_javascript.html.twig new file mode 100644 index 0000000..ce4d09a --- /dev/null +++ b/src/Resources/views/_partials/_javascript.html.twig @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig new file mode 100644 index 0000000..822eb59 --- /dev/null +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_choiceAlma.html.twig @@ -0,0 +1,21 @@ +
+
+
+ {{ form_widget(form, sylius_test_form_attribute('payment-method-select')|sylius_merge_recursive( {'attr': {'data-payment': 'alma-method-id-' ~ method.id}})) }} +
+
+
+ + {{ form_label(form, null, {'label_attr': {'data-test-payment-method-label': ''}}) }} + {{ 'alma_sylius_payment_plugin.checkout.logo_alma'|trans }} + + {% if method.description is not null %} +
+

{{ method.description }}

+
+ {% endif %} + {{ render(controller('Alma\\SyliusPaymentPlugin\\Controller\\InstallmentsController::renderInstallmentPlanAction', {'orderId': order.id, 'methodPaymentId': method.id})) }} +
+
+ + diff --git a/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_payment.html.twig b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_payment.html.twig new file mode 100644 index 0000000..233dd8f --- /dev/null +++ b/src/Resources/views/bundles/SyliusShopBundle/Checkout/SelectPayment/_payment.html.twig @@ -0,0 +1,18 @@ +{% block stylesheets %} + +{% endblock %} +
+
{{ 'sylius.ui.payment'|trans }} #{{ loop.index }}
+
+ {{ form_errors(form.method) }} + {% for key, choice_form in form.method %} + {% if form.method.vars.choices[key].data.gatewayConfig.factoryName == 'alma_payments' %} + {% include '@SyliusShop/Checkout/SelectPayment/_choiceAlma.html.twig' with {'form': choice_form, 'method': form.method.vars.choices[key].data} %} + {% else %} + {% include '@SyliusShop/Checkout/SelectPayment/_choice.html.twig' with {'form': choice_form, 'method': form.method.vars.choices[key].data} %} + {% endif %} + {% else %} + {% include '@SyliusShop/Checkout/SelectPayment/_unavailable.html.twig' %} + {% endfor %} +
+
diff --git a/src/Resources/views/installmentPlan.html.twig b/src/Resources/views/installmentPlan.html.twig new file mode 100644 index 0000000..251e0c5 --- /dev/null +++ b/src/Resources/views/installmentPlan.html.twig @@ -0,0 +1,7 @@ +
+ {% if installmentsCount <= 4 %} + {% include '@AlmaSyliusPaymentPlugin/_partials/_almaPnx.html.twig' with {'installmentsCount': installmentsCount, 'plans': plans} %} + {% else %} + {% include '@AlmaSyliusPaymentPlugin/_partials/_almaCredit.html.twig' with {'installmentsCount': installmentsCount, 'plans': plans, 'creditInfo': creditInfo} %} + {% endif %} +
diff --git a/src/Twig/AlmaExtension.php b/src/Twig/AlmaExtension.php new file mode 100644 index 0000000..68a4b27 --- /dev/null +++ b/src/Twig/AlmaExtension.php @@ -0,0 +1,37 @@ +