Skip to content

Commit dd2a03d

Browse files
committed
Merge branch 'release/3.2.0'
2 parents e4abc78 + 5606fc6 commit dd2a03d

File tree

10 files changed

+107
-26
lines changed

10 files changed

+107
-26
lines changed

.github/FUNDING.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [janhenckens]

.github/workflows/build-docs.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy docs
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: 16
17+
cache: yarn
18+
- run: yarn install --frozen-lockfile
19+
20+
- name: Build
21+
run: yarn docs:build
22+
23+
- name: Deploy
24+
uses: peaceiris/actions-gh-pages@v3
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
publish_dir: docs/.vitepress/dist

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 3.2.0 - 2024-04-24
8+
### Added
9+
- It's now possible to update fields saved on a payment in the control panel
10+
- There is a new permission to enable this
11+
712
## 3.1.3 - 2023-03-10
813
### Fixed
914
- Fixed a missing namespace

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
Easily accept payment with Mollie Payments. Note that this plugin does not work with or require Craft Commerce.
44

5-
![Screenshot](https://www.studioespresso.co/resources/mollie/banner.png)
65
## Requirements
76

87
This plugin requires Craft CMS 3.1.0 or later.
@@ -22,9 +21,10 @@ To install the plugin, follow these instructions.
2221
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Mollie Payments.
2322

2423

25-
## Documentation
2624

27-
Extensive documentation can be found [here](https://studioespresso.github.io/craft-mollie-payments/)
25+
| 📑 [More information & documentation is available here](https://studioespresso.github.io/craft-mollie-payments/) |
26+
|------------------------------------------------------------------------------------------------------------------|
27+
2828

2929
---
3030
Brought to you by [Studio Espresso](https://studioespresso.co)

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "studioespresso/craft-mollie-payments",
33
"description": "Easily accept payments with Mollie Payments",
44
"type": "craft-plugin",
5-
"version": "3.1.3",
5+
"version": "3.2.0",
66
"keywords": [
77
"craft",
88
"cms",

docs/.vitepress/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
title: 'Mollie Payments for Craft',
3-
base: '/craft-mollie-payment',
3+
base: '/craft-mollie-payments',
44
themeConfig: {
55

66
// logo: {light: '/icon-vuepress.svg', dark: '/icon-vuepress-light.svg'},

src/MolliePayments.php

+20
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
use craft\base\Model;
1414
use craft\events\RebuildConfigEvent;
15+
use craft\events\RegisterUserPermissionsEvent;
1516
use craft\helpers\UrlHelper;
1617
use craft\services\ProjectConfig;
18+
use craft\services\UserPermissions;
1719
use studioespresso\molliepayments\behaviours\CraftVariableBehavior;
1820
use studioespresso\molliepayments\elements\Payment;
1921
use studioespresso\molliepayments\services\Currency;
@@ -163,6 +165,24 @@ function (RegisterComponentTypesEvent $event) {
163165
]);
164166
});
165167

168+
Event::on(
169+
UserPermissions::class,
170+
UserPermissions::EVENT_REGISTER_PERMISSIONS,
171+
function(RegisterUserPermissionsEvent $event) {
172+
173+
// Register our custom permissions
174+
$permissions = [
175+
"heading" => Craft::t('mollie-payments', 'Mollie Payments'),
176+
"permissions" => [
177+
'mollie-payments:edit-payments' => [
178+
'label' => Craft::t('mollie-payments', 'Edit Payments'),
179+
],
180+
],
181+
];
182+
$event->permissions[Craft::t('mollie-payments', 'Mollie Payments')] = $permissions;
183+
}
184+
);
185+
166186
}
167187

168188
public function getCpNavItem(): array

src/controllers/PaymentController.php

+31-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use studioespresso\molliepayments\MolliePayments;
1212
use yii\base\InvalidArgumentException;
1313
use yii\base\InvalidConfigException;
14+
use yii\web\ForbiddenHttpException;
1415
use yii\web\HttpException;
1516
use yii\web\NotFoundHttpException;
1617

@@ -173,26 +174,51 @@ public function actionDonate()
173174
* @param $uid
174175
* @since 1.0.0
175176
*/
176-
public function actionEdit($uid)
177+
public function actionEdit($uid, $element = null)
177178
{
178-
$query = Payment::find();
179-
$query->uid = $uid;
180-
$payment = $query->one();
179+
if ($element) {
180+
181+
$payment = $element;
182+
} else {
183+
$query = Payment::find();
184+
$query->uid = $uid;
185+
$payment = $query->one();
186+
}
181187

182188
$paymentForm = MolliePayments::getInstance()->forms->getFormByid($payment->formId);
183189
$transactions = MolliePayments::getInstance()->transaction->getAllByPayment($payment->id);
184190

185191
$this->renderTemplate('mollie-payments/_payment/_edit', ['element' => $payment, 'transactions' => $transactions, 'form' => $paymentForm]);
186192
}
187193

194+
public function actionSaveCp()
195+
{
196+
$currentUser = Craft::$app->getUser()->getIdentity();
197+
if(!$currentUser->can('mollie-payments:edit-payments')) {
198+
throw new ForbiddenHttpException();
199+
}
200+
$element = Payment::findOne(['id' => $this->request->getRequiredBodyParam('paymentId')]);
201+
$element->setFieldValuesFromRequest('fields');
202+
$element->setScenario('live');
203+
if (!$element->validate()) {
204+
// Send the payment back to the template
205+
206+
return $this->runAction('edit', ['uid' => $element->uid, 'element' => $element]);
207+
}
208+
209+
Craft::$app->getElements()->saveElement($element);
210+
return $this->redirect(UrlHelper::cpUrl($element->getCpEditUrl()));
211+
212+
}
213+
188214
public function actionRedirect()
189215
{
190216
$uid = Craft::$app->getRequest()->getRequiredParam('order_id');
191217
$redirect = Craft::$app->getRequest()->getParam('redirect');
192218

193219
$payment = Payment::findOne(['uid' => $uid]);
194220
$transaction = MolliePayments::getInstance()->transaction->getTransactionbyPayment($payment->id);
195-
if($redirect != $transaction->redirect) {
221+
if ($redirect != $transaction->redirect) {
196222
throw new InvalidArgumentException("Invalid redirect");
197223
}
198224

src/icon.svg

+8-11
Loading

src/templates/_payment/_edit.twig

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
{% set fullPageForm = true %}
55
{% set saveShortcutRedirect = continueEditingUrl ?? "" %}
6+
{% set mainFormAttributes = {
7+
action: actionUrl('mollie-payments/payment/save-cp'),
8+
method: 'post'
9+
} %}
610

711
{% set crumbs = [
812
{ label: "Payments", url: cpUrl('mollie-payments') },
@@ -12,7 +16,9 @@
1216
{% set title = "Payment for "|t('mollie-payments') ~ form.title ~' - '~ element.email %}
1317
{% block header %}
1418
{{ block('pageTitle') }}
15-
{{ block('actionButton') }}
19+
{% if currentUser.can('mollie-payments:edit-payments') %}
20+
{{ block('actionButton') }}
21+
{% endif %}
1622
{% endblock %}
1723

1824
{% set tabData = [] %}
@@ -29,17 +35,14 @@
2935
{% hook 'cp.payments.edit' %}
3036

3137
{% block content %}
32-
38+
{{ hiddenInput('paymentId', element.id) }}
3339
{% if element.getFieldLayout() %}
34-
3540
{% set form = element.getFieldLayout().createForm(element) %}
3641
<div id="fields">
3742
{{ form.render()|raw }}
3843
</div>
3944
{% endif %}
4045

41-
42-
4346
<div id="tab-transactions" class="{% if tabs|length %}hidden{% endif %}">
4447
{% include 'mollie-payments/_payment/_transactions.twig' with {transactions : transactions } only %}
4548
</div>

0 commit comments

Comments
 (0)