|
11 | 11 | use studioespresso\molliepayments\MolliePayments;
|
12 | 12 | use yii\base\InvalidArgumentException;
|
13 | 13 | use yii\base\InvalidConfigException;
|
| 14 | +use yii\web\ForbiddenHttpException; |
14 | 15 | use yii\web\HttpException;
|
15 | 16 | use yii\web\NotFoundHttpException;
|
16 | 17 |
|
@@ -173,26 +174,51 @@ public function actionDonate()
|
173 | 174 | * @param $uid
|
174 | 175 | * @since 1.0.0
|
175 | 176 | */
|
176 |
| - public function actionEdit($uid) |
| 177 | + public function actionEdit($uid, $element = null) |
177 | 178 | {
|
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 | + } |
181 | 187 |
|
182 | 188 | $paymentForm = MolliePayments::getInstance()->forms->getFormByid($payment->formId);
|
183 | 189 | $transactions = MolliePayments::getInstance()->transaction->getAllByPayment($payment->id);
|
184 | 190 |
|
185 | 191 | $this->renderTemplate('mollie-payments/_payment/_edit', ['element' => $payment, 'transactions' => $transactions, 'form' => $paymentForm]);
|
186 | 192 | }
|
187 | 193 |
|
| 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 | + |
188 | 214 | public function actionRedirect()
|
189 | 215 | {
|
190 | 216 | $uid = Craft::$app->getRequest()->getRequiredParam('order_id');
|
191 | 217 | $redirect = Craft::$app->getRequest()->getParam('redirect');
|
192 | 218 |
|
193 | 219 | $payment = Payment::findOne(['uid' => $uid]);
|
194 | 220 | $transaction = MolliePayments::getInstance()->transaction->getTransactionbyPayment($payment->id);
|
195 |
| - if($redirect != $transaction->redirect) { |
| 221 | + if ($redirect != $transaction->redirect) { |
196 | 222 | throw new InvalidArgumentException("Invalid redirect");
|
197 | 223 | }
|
198 | 224 |
|
|
0 commit comments