@@ -81,8 +81,6 @@ public function actionSubscribe()
81
81
$ subscription ->customerId = $ subscriber ->customerId ;
82
82
83
83
if (!$ subscription ->validate ()) {
84
- // TODO Remove this before release
85
- dd ($ subscription ->getErrors ());
86
84
// Send the payment back to the template
87
85
Craft::$ app ->getUrlManager ()->setRouteParams ([
88
86
'subscription ' => $ subscription ,
@@ -160,10 +158,11 @@ public function actionRedirect()
160
158
161
159
$ redirect = $ request ->getQueryParam ('redirect ' );
162
160
$ element = Subscription::findOne (['uid ' => $ uid ]);
161
+ $ form = MolliePayments::getInstance ()->forms ->getFormByid ($ element ->formId );
163
162
$ transaction = MolliePayments::$ plugin ->transaction ->getTransactionbyPayment ($ element ->id );
164
163
165
164
try {
166
- $ molliePayment = MolliePayments::$ plugin ->mollie ->getStatus ($ transaction ->id );
165
+ $ molliePayment = MolliePayments::$ plugin ->mollie ->getStatus ($ transaction ->id , $ form -> handle );
167
166
$ this ->redirect (UrlHelper::url ($ redirect , ['subscription ' => $ uid , 'status ' => $ molliePayment ->status ]));
168
167
} catch (\Exception $ e ) {
169
168
throw new NotFoundHttpException ('Payments not found ' , '404 ' );
@@ -178,7 +177,9 @@ public function actionWebhook(): void
178
177
{
179
178
$ id = Craft::$ app ->getRequest ()->getRequiredParam ('id ' );
180
179
$ transaction = MolliePayments::getInstance ()->transaction ->getTransactionbyId ($ id );
181
- $ molliePayment = MolliePayments::getInstance ()->mollie ->getStatus ($ id );
180
+ $ element = Subscription::findOne (['id ' => $ transaction ->payment ]);
181
+ $ form = MolliePayments::getInstance ()->forms ->getFormByid ($ element ->formId );
182
+ $ molliePayment = MolliePayments::getInstance ()->mollie ->getStatus ($ id , $ form ->handle );
182
183
183
184
// If we have a subscription id, the payment belongs to an active subscription
184
185
// So we need to create a new transaction for it.
@@ -283,7 +284,7 @@ public function actionGetSubscribers()
283
284
$ page = $ this ->request ->getQueryParam ('page ' , 1 );
284
285
$ baseUrl = 'mollie-payments/subscription/get-subscribers ' ;
285
286
$ data = MolliePayments::getInstance ()->subscriber ->getAllSubscribers ();
286
- $ subscribers = collect ($ data )->map (function ($ subscriber ) {
287
+ $ subscribers = collect ($ data )->map (function ($ subscriber ) {
287
288
return [
288
289
'title ' => $ subscriber ->email ,
289
290
'id ' => $ subscriber ->customerId ,
@@ -335,8 +336,13 @@ public function actionGetSubscribers()
335
336
336
337
public function actionDeleteSubscriber ()
337
338
{
338
- MolliePayments::getInstance ()->mollie ->deleteCustomer ($ this ->request ->getRequiredBodyParam ('id ' ));
339
- MolliePayments::getInstance ()->subscriber ->deleteById ($ this ->request ->getRequiredBodyParam ('id ' ));
340
- return $ this ->asJson (['success ' => true ]);
339
+ try {
340
+ MolliePayments::getInstance ()->mollie ->deleteCustomer ($ this ->request ->getRequiredBodyParam ('id ' ));
341
+ MolliePayments::getInstance ()->subscriber ->deleteById ($ this ->request ->getRequiredBodyParam ('id ' ));
342
+ return $ this ->asJson (['success ' => true ]);
343
+ } catch (\Throwable $ e ) {
344
+ Craft::error ($ e ->getMessage (), MolliePayments::class);
345
+ return $ this ->asJson (['success ' => false ]);
346
+ }
341
347
}
342
348
}
0 commit comments