MissingPaymentMethodMiddleware.php
2 years ago
SubscriptionNonceVerificationMiddleware.php
2 years ago
SubscriptionPermissionsControllerMiddleware.php
2 years ago
UpdateSubscriptionMiddleware.php
2 years ago
MissingPaymentMethodMiddleware.php
41 lines
| 1 | <?php |
| 2 | namespace SureCartBlocks\Controllers\Middleware; |
| 3 | |
| 4 | use Closure; |
| 5 | use SureCart\Models\Subscription; |
| 6 | use SureCartBlocks\Controllers\PaymentMethodController; |
| 7 | |
| 8 | /** |
| 9 | * Handles a showing a view for the missing payment element. |
| 10 | * If the subscription is missing it. |
| 11 | */ |
| 12 | class MissingPaymentMethodMiddleware { |
| 13 | /** |
| 14 | * Handle the middleware. |
| 15 | * |
| 16 | * @param string $action Action. |
| 17 | * @param Closure $next Next. |
| 18 | * @return function |
| 19 | */ |
| 20 | public function handle( string $action, Closure $next ) { |
| 21 | $id = sanitize_text_field( wp_unslash( $_GET['id'] ?? '' ) ); |
| 22 | $tab = sanitize_text_field( wp_unslash( $_GET['tab'] ?? '' ) ); |
| 23 | |
| 24 | // get the subscription. |
| 25 | $subscription = Subscription::find( $id ); |
| 26 | |
| 27 | // no payment method, show the payment method form. |
| 28 | if ( empty( $subscription->payment_method ) && empty( $subscription->manual_payment_method ) ) { |
| 29 | $current_url = home_url( add_query_arg( [ 'tab' => esc_attr( $tab ) ] ) ); |
| 30 | |
| 31 | return ( new PaymentMethodController() )->create( |
| 32 | [ |
| 33 | 'success_url' => $current_url, |
| 34 | ] |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | return $next(); |
| 39 | } |
| 40 | } |
| 41 |