Skip to content

Commit

Permalink
Merge branch 'release/3.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Apr 24, 2024
2 parents e4abc78 + 5606fc6 commit dd2a03d
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [janhenckens]
27 changes: 27 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy docs

on:
push:
branches:
- master
- develop

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn
- run: yarn install --frozen-lockfile

- name: Build
run: yarn docs:build

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/.vitepress/dist
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

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

## 3.2.0 - 2024-04-24
### Added
- It's now possible to update fields saved on a payment in the control panel
- There is a new permission to enable this

## 3.1.3 - 2023-03-10
### Fixed
- Fixed a missing namespace
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

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

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


## Documentation

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


---
Brought to you by [Studio Espresso](https://studioespresso.co)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "studioespresso/craft-mollie-payments",
"description": "Easily accept payments with Mollie Payments",
"type": "craft-plugin",
"version": "3.1.3",
"version": "3.2.0",
"keywords": [
"craft",
"cms",
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
title: 'Mollie Payments for Craft',
base: '/craft-mollie-payment',
base: '/craft-mollie-payments',
themeConfig: {

// logo: {light: '/icon-vuepress.svg', dark: '/icon-vuepress-light.svg'},
Expand Down
20 changes: 20 additions & 0 deletions src/MolliePayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

use craft\base\Model;
use craft\events\RebuildConfigEvent;
use craft\events\RegisterUserPermissionsEvent;
use craft\helpers\UrlHelper;
use craft\services\ProjectConfig;
use craft\services\UserPermissions;
use studioespresso\molliepayments\behaviours\CraftVariableBehavior;
use studioespresso\molliepayments\elements\Payment;
use studioespresso\molliepayments\services\Currency;
Expand Down Expand Up @@ -163,6 +165,24 @@ function (RegisterComponentTypesEvent $event) {
]);
});

Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
function(RegisterUserPermissionsEvent $event) {

// Register our custom permissions
$permissions = [
"heading" => Craft::t('mollie-payments', 'Mollie Payments'),
"permissions" => [
'mollie-payments:edit-payments' => [
'label' => Craft::t('mollie-payments', 'Edit Payments'),
],
],
];
$event->permissions[Craft::t('mollie-payments', 'Mollie Payments')] = $permissions;
}
);

}

public function getCpNavItem(): array
Expand Down
36 changes: 31 additions & 5 deletions src/controllers/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use studioespresso\molliepayments\MolliePayments;
use yii\base\InvalidArgumentException;
use yii\base\InvalidConfigException;
use yii\web\ForbiddenHttpException;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;

Expand Down Expand Up @@ -173,26 +174,51 @@ public function actionDonate()
* @param $uid
* @since 1.0.0
*/
public function actionEdit($uid)
public function actionEdit($uid, $element = null)
{
$query = Payment::find();
$query->uid = $uid;
$payment = $query->one();
if ($element) {

$payment = $element;
} else {
$query = Payment::find();
$query->uid = $uid;
$payment = $query->one();
}

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

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

public function actionSaveCp()
{
$currentUser = Craft::$app->getUser()->getIdentity();
if(!$currentUser->can('mollie-payments:edit-payments')) {
throw new ForbiddenHttpException();
}
$element = Payment::findOne(['id' => $this->request->getRequiredBodyParam('paymentId')]);
$element->setFieldValuesFromRequest('fields');
$element->setScenario('live');
if (!$element->validate()) {
// Send the payment back to the template

return $this->runAction('edit', ['uid' => $element->uid, 'element' => $element]);
}

Craft::$app->getElements()->saveElement($element);
return $this->redirect(UrlHelper::cpUrl($element->getCpEditUrl()));

}

public function actionRedirect()
{
$uid = Craft::$app->getRequest()->getRequiredParam('order_id');
$redirect = Craft::$app->getRequest()->getParam('redirect');

$payment = Payment::findOne(['uid' => $uid]);
$transaction = MolliePayments::getInstance()->transaction->getTransactionbyPayment($payment->id);
if($redirect != $transaction->redirect) {
if ($redirect != $transaction->redirect) {
throw new InvalidArgumentException("Invalid redirect");
}

Expand Down
19 changes: 8 additions & 11 deletions src/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 8 additions & 5 deletions src/templates/_payment/_edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

{% set fullPageForm = true %}
{% set saveShortcutRedirect = continueEditingUrl ?? "" %}
{% set mainFormAttributes = {
action: actionUrl('mollie-payments/payment/save-cp'),
method: 'post'
} %}

{% set crumbs = [
{ label: "Payments", url: cpUrl('mollie-payments') },
Expand All @@ -12,7 +16,9 @@
{% set title = "Payment for "|t('mollie-payments') ~ form.title ~' - '~ element.email %}
{% block header %}
{{ block('pageTitle') }}
{{ block('actionButton') }}
{% if currentUser.can('mollie-payments:edit-payments') %}
{{ block('actionButton') }}
{% endif %}
{% endblock %}

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

{% block content %}

{{ hiddenInput('paymentId', element.id) }}
{% if element.getFieldLayout() %}

{% set form = element.getFieldLayout().createForm(element) %}
<div id="fields">
{{ form.render()|raw }}
</div>
{% endif %}



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

0 comments on commit dd2a03d

Please sign in to comment.