diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19982ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..61c9777 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Rapidez MultiSafePay + +## Requirements + +You need the [MultiSafePay Magento 2](https://github.com/MultiSafepay/Magento2) and [MultiSafePay Magento 2 GraphQL](https://github.com/MultiSafepay/magento2-graphql) modules installed in your Magento 2 installation. + +### Temporary notice + +The magento2 core package from MultiSafePay currently contains a bug that prevents guest checkout from working. You can use [version 2.19.1 from this fork](https://github.com/Jade-GG/magento2-core) until the PR fixing this has been merged into the official repository. + +## Installation + +``` +composer require rapidez/multisafepay +``` + +And import the JS into your `resources/js/app.js`: + +``` +import 'Vendor/rapidez/multisafepay/resources/js/multisafepay.js'; +``` + +Then, in your magento -> configuration -> multisafepay -> general settings, enable custom return urls for PWA and use the following return URLs: + +``` +[your base rapidez url]/msp-return/cancel?quoteId={{quote.masked_id}} +[your base rapidez url]/msp-return/success?secureToken={{secure_token}}&orderId={{order.increment_id}}&paymentCode={{payment.code}} +``` + +Finally, note that MultiSafePay needs these magento URLs to work: + +``` +[your base magento url]/multisafepay/connect/success?[...] +[your base magento url]/multisafepay/connect/cancel?[...] +[your base magento url]/multisafepay/connect/notification?[...] +``` + +You will have to update your deployment to open up these specific URLs (i.e. to not redirect these to your rapidez frontend). +For example, for a standard rapidez installation you can update the regex as seen in the [Rapidez docs deployment page](https://docs.rapidez.io/0.x/deployment.html#redirecting-magento-to-rapidez) to include `multisafepay`. + +## Views + +You can publish the views with the following command: + +``` +php artisan vendor:publish --provider="Rapidez\MultiSafePay\MultiSafePayServiceProvider" --tag=views +``` \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a36d3ee --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "rapidez/multisafepay", + "description": "MultiSafePay support for Rapidez", + "autoload": { + "psr-4": { + "Rapidez\\Multisafepay\\": "src/" + } + }, + "authors": [ + { + "name": "Jade Geels", + "email": "jade@justbetter.nl" + } + ], + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": "^8.0|^8.1", + "illuminate/support": "^9.0", + "rapidez/core": "~0.54" + }, + "config": { + "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "Rapidez\\Multisafepay\\MultiSafePayServiceProvider" + ] + } + } +} diff --git a/resources/js/components/MSPPending.vue b/resources/js/components/MSPPending.vue new file mode 100644 index 0000000..566bfa6 --- /dev/null +++ b/resources/js/components/MSPPending.vue @@ -0,0 +1,37 @@ + diff --git a/resources/js/multisafepay.js b/resources/js/multisafepay.js new file mode 100644 index 0000000..1048b65 --- /dev/null +++ b/resources/js/multisafepay.js @@ -0,0 +1,15 @@ +import MSPPending from './components/MSPPending.vue' +Vue.component('msp-pending', MSPPending) + +document.addEventListener('turbo:load', () => { + window.app.$on('checkout-payment-saved', (data) => { + if (!data.order.payment_method_code.includes('multisafepay_')) { + return; + } + window.app.checkout.doNotGoToTheNextStep = true + let cart = window.app.user ? 'mine' : localStorage.mask; + magentoUser.get(`/multisafepay/${cart}/payment-url/${data.order.id}`).then(response => { + window.location.replace(response.data); + }); + }); +}) diff --git a/resources/views/cancel.blade.php b/resources/views/cancel.blade.php new file mode 100644 index 0000000..9012efe --- /dev/null +++ b/resources/views/cancel.blade.php @@ -0,0 +1,7 @@ +@extends('rapidez::layouts.app') + +@section('title', 'Checkout') + +@section('content') + +@endsection diff --git a/resources/views/pending.blade.php b/resources/views/pending.blade.php new file mode 100644 index 0000000..983bf5f --- /dev/null +++ b/resources/views/pending.blade.php @@ -0,0 +1,3 @@ +

@lang('Pending payment')

+

@lang('We did not receive the payment (yet). This page will auto-update every 2 seconds.')

+

@lang('Are you still seeing this page after a minute? Please contact us.')

diff --git a/resources/views/success.blade.php b/resources/views/success.blade.php new file mode 100644 index 0000000..1752f09 --- /dev/null +++ b/resources/views/success.blade.php @@ -0,0 +1,18 @@ +@extends('rapidez::layouts.app') + +@section('title', 'Checkout') + +@section('content') +
+ +
+
+ @include('rapidez::checkout.steps.success') +
+
+ @include('multisafepay::pending') +
+
+
+
+@endsection diff --git a/routes/web.php b/routes/web.php new file mode 100644 index 0000000..83387bd --- /dev/null +++ b/routes/web.php @@ -0,0 +1,21 @@ +group(function () { + Route::get('/msp-return/success', function(Request $request) { + $order = (object)[ + 'increment_id' => $request->get('orderId'), + 'secure_token' => $request->get('secureToken'), + 'payment_method' => $request->get('paymentCode'), + ]; + + return view('multisafepay::success', ['t_order' => $order]); + })->name('multisafepay.success'); + Route::get('/msp-return/cancel', function(Request $request) { + return view('multisafepay::cancel', ['quoteId' => $request->get('quoteId')]); + })->name('multisafepay.cancel'); +}); diff --git a/src/MultiSafePayServiceProvider.php b/src/MultiSafePayServiceProvider.php new file mode 100644 index 0000000..0489b6d --- /dev/null +++ b/src/MultiSafePayServiceProvider.php @@ -0,0 +1,20 @@ +loadRoutesFrom(__DIR__.'/../routes/web.php'); + $this->loadViewsFrom(__DIR__.'/../resources/views', 'multisafepay'); + + if($this->app->runningInConsole()) { + $this->publishes([ + __DIR__.'/../resources/views' => resource_path('views/vendor/multisafepay'), + ], 'views'); + } + } +} \ No newline at end of file