Skip to content

Commit

Permalink
Init (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored Feb 7, 2023
1 parent 91fade6 commit c12ab76
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "rapidez/multisafepay",
"description": "MultiSafePay support for Rapidez",
"autoload": {
"psr-4": {
"Rapidez\\Multisafepay\\": "src/"
}
},
"authors": [
{
"name": "Jade Geels",
"email": "[email protected]"
}
],
"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"
]
}
}
}
37 changes: 37 additions & 0 deletions resources/js/components/MSPPending.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script>
export default {
props: {
order: Object
},
data() {
return {
completed: false,
}
},
mounted() {
this.order.customer_email = window.localStorage.email;
this.checkStatus();
},
render() {
return this.$scopedSlots.default({
completed: this.completed,
order: this.order
})
},
methods: {
async checkStatus() {
magento.get(`/multisafepay/orders/${this.order.increment_id}/${this.order.secure_token}`).then(response => {
if(['processing', 'success'].includes(response.data?.status)) {
this.completed = true;
} else {
window.setTimeout(this.checkStatus, 2000);
}
})
}
},
}
</script>
15 changes: 15 additions & 0 deletions resources/js/multisafepay.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
})
7 changes: 7 additions & 0 deletions resources/views/cancel.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@extends('rapidez::layouts.app')

@section('title', 'Checkout')

@section('content')
<graphql query='mutation { restoreQuote(input: {cart_id:"{{ $quoteId }}"}) }' check="restoreQuote" redirect="/checkout"></graphql>
@endsection
3 changes: 3 additions & 0 deletions resources/views/pending.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1 class="font-bold text-4xl mb-5">@lang('Pending payment')</h1>
<p>@lang('We did not receive the payment (yet). This page will auto-update every 2 seconds.')</p>
<p>@lang('Are you still seeing this page after a minute? Please contact us.')</p>
18 changes: 18 additions & 0 deletions resources/views/success.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@extends('rapidez::layouts.app')

@section('title', 'Checkout')

@section('content')
<div class="container">
<msp-pending :order='@json($t_order)' v-cloak>
<div slot-scope="{ completed, order }">
<div v-if="completed">
@include('rapidez::checkout.steps.success')
</div>
<div v-else>
@include('multisafepay::pending')
</div>
</div>
</msp-pending>
</div>
@endsection
21 changes: 21 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;

Route::middleware('web')->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');
});
20 changes: 20 additions & 0 deletions src/MultiSafePayServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rapidez\MultiSafePay;

use Illuminate\Support\ServiceProvider;

class MultiSafePayServiceProvider extends ServiceProvider
{
public function boot()
{
$this->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');
}
}
}

0 comments on commit c12ab76

Please sign in to comment.