| 1 |
<?php |
| 2 |
namespace SureCartBlocks\Controllers; |
| 3 |
|
| 4 |
use SureCart\Models\Component; |
| 5 |
use SureCart\Models\Price; |
| 6 |
use SureCart\Models\Product; |
| 7 |
use SureCart\Models\Subscription; |
| 8 |
use SureCart\Models\SubscriptionProtocol; |
| 9 |
use SureCart\Models\User; |
| 10 |
use SureCartBlocks\Controllers\Middleware\MissingPaymentMethodMiddleware; |
| 11 |
use SureCartBlocks\Controllers\Middleware\UpdateSubscriptionMiddleware; |
| 12 |
use SureCartBlocks\Controllers\Middleware\SubscriptionPermissionsControllerMiddleware; |
| 13 |
use SureCartBlocks\Controllers\Middleware\SubscriptionNonceVerificationMiddleware; |
| 14 |
/** |
| 15 |
* The subscription controller. |
| 16 |
*/ |
| 17 |
class SubscriptionController extends BaseController { |
| 18 |
/** |
| 19 |
* The middleware for this controller. |
| 20 |
* |
| 21 |
* @var array |
| 22 |
*/ |
| 23 |
protected $middleware = [ |
| 24 |
'confirm' => [ |
| 25 |
SubscriptionPermissionsControllerMiddleware::class, |
| 26 |
UpdateSubscriptionMiddleware::class, |
| 27 |
MissingPaymentMethodMiddleware::class, |
| 28 |
], |
| 29 |
'confirm_amount' => [ |
| 30 |
SubscriptionPermissionsControllerMiddleware::class, |
| 31 |
UpdateSubscriptionMiddleware::class, |
| 32 |
MissingPaymentMethodMiddleware::class, |
| 33 |
], |
| 34 |
'confirm_variation' => [ |
| 35 |
SubscriptionPermissionsControllerMiddleware::class, |
| 36 |
UpdateSubscriptionMiddleware::class, |
| 37 |
MissingPaymentMethodMiddleware::class, |
| 38 |
], |
| 39 |
'update_payment_method' => [ |
| 40 |
SubscriptionNonceVerificationMiddleware::class, |
| 41 |
SubscriptionPermissionsControllerMiddleware::class, |
| 42 |
UpdateSubscriptionMiddleware::class, |
| 43 |
MissingPaymentMethodMiddleware::class, |
| 44 |
], |
| 45 |
]; |
| 46 |
|
| 47 |
/** |
| 48 |
* Render the block |
| 49 |
* |
| 50 |
* @param array $attributes Block attributes. |
| 51 |
* @return function |
| 52 |
*/ |
| 53 |
public function preview( $attributes = [] ) { |
| 54 |
return wp_kses_post( |
| 55 |
Component::tag( 'sc-subscriptions-list' ) |
| 56 |
->id( 'customer-subscriptions-preview' ) |
| 57 |
->with( |
| 58 |
[ |
| 59 |
'heading' => $attributes['title'] ?? null, |
| 60 |
'isCustomer' => User::current()->isCustomer(), |
| 61 |
'allLink' => add_query_arg( |
| 62 |
[ |
| 63 |
'tab' => $this->getTab(), |
| 64 |
'model' => 'subscription', |
| 65 |
'action' => 'index', |
| 66 |
], |
| 67 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 68 |
), |
| 69 |
'query' => apply_filters( |
| 70 |
'surecart/dashboard/subscription_list/query', |
| 71 |
[ |
| 72 |
'customer_ids' => array_values( User::current()->customerIds() ), |
| 73 |
'status' => [ 'active', 'trialing', 'past_due', 'canceled' ], |
| 74 |
'page' => 1, |
| 75 |
'per_page' => 5, |
| 76 |
] |
| 77 |
), |
| 78 |
] |
| 79 |
)->render( $attributes['title'] ? "<span slot='heading'>" . $attributes['title'] . '</span>' : '' ) |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Render the block |
| 85 |
* |
| 86 |
* @return function |
| 87 |
*/ |
| 88 |
public function index() { |
| 89 |
\SureCart::assets()->addComponentData( |
| 90 |
'sc-subscriptions-list', |
| 91 |
'#customer-subscriptions-index', |
| 92 |
[ |
| 93 |
'heading' => $attributes['title'] ?? __( 'Plans', 'surecart' ), |
| 94 |
'isCustomer' => User::current()->isCustomer(), |
| 95 |
'query' => apply_filters( |
| 96 |
'surecart/dashboard/subscription_list/query', |
| 97 |
[ |
| 98 |
'customer_ids' => array_values( User::current()->customerIds() ), |
| 99 |
'status' => [ 'active', 'trialing', 'canceled', 'past_due' ], |
| 100 |
'page' => 1, |
| 101 |
'per_page' => 20, |
| 102 |
] |
| 103 |
), |
| 104 |
] |
| 105 |
); |
| 106 |
ob_start(); |
| 107 |
?> |
| 108 |
<sc-spacing style="--spacing: var(--sc-spacing-large)"> |
| 109 |
<sc-breadcrumbs> |
| 110 |
<sc-breadcrumb href="<?php echo esc_url( add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>"> |
| 111 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 112 |
</sc-breadcrumb> |
| 113 |
<sc-breadcrumb> |
| 114 |
<?php esc_html_e( 'Plans', 'surecart' ); ?> |
| 115 |
</sc-breadcrumb> |
| 116 |
</sc-breadcrumbs> |
| 117 |
<sc-subscriptions-list id="customer-subscriptions-index"></sc-subscriptions-list> |
| 118 |
</sc-spacing> |
| 119 |
<?php |
| 120 |
return ob_get_clean(); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Show and individual checkout session. |
| 125 |
* |
| 126 |
* @return function |
| 127 |
*/ |
| 128 |
public function edit() { |
| 129 |
$id = $this->getId(); |
| 130 |
|
| 131 |
if ( ! $id ) { |
| 132 |
return $this->notFound(); |
| 133 |
} |
| 134 |
|
| 135 |
// fetch subscription. |
| 136 |
$subscription = Subscription::with( |
| 137 |
[ |
| 138 |
'price', |
| 139 |
'periods', |
| 140 |
'price.product', |
| 141 |
'product.product_group', |
| 142 |
'current_period', |
| 143 |
'period.checkout', |
| 144 |
'purchase', |
| 145 |
'discount', |
| 146 |
'discount.coupon', |
| 147 |
'purchase.license', |
| 148 |
'license.activations', |
| 149 |
] |
| 150 |
)->find( $id ); |
| 151 |
|
| 152 |
$should_delay_cancellation = $subscription->shouldDelayCancellation(); |
| 153 |
ob_start(); |
| 154 |
?> |
| 155 |
<?php do_action( 'surecart/dashboard/subscription/before_current_plan', $subscription ); ?> |
| 156 |
<sc-spacing style="--spacing: var(--sc-spacing-large)"> |
| 157 |
<sc-breadcrumbs> |
| 158 |
<sc-breadcrumb href="<?php echo esc_url( add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>"> |
| 159 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 160 |
</sc-breadcrumb> |
| 161 |
<sc-breadcrumb href=" |
| 162 |
<?php |
| 163 |
echo esc_url( |
| 164 |
add_query_arg( |
| 165 |
[ |
| 166 |
'tab' => $this->getTab(), |
| 167 |
'action' => 'index', |
| 168 |
'model' => 'subscription', |
| 169 |
], |
| 170 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 171 |
) |
| 172 |
); |
| 173 |
?> |
| 174 |
"> |
| 175 |
<?php esc_html_e( 'Plans', 'surecart' ); ?> |
| 176 |
</sc-breadcrumb> |
| 177 |
<sc-breadcrumb> |
| 178 |
<?php esc_html_e( 'Plan', 'surecart' ); ?> |
| 179 |
</sc-breadcrumb> |
| 180 |
</sc-breadcrumbs> |
| 181 |
|
| 182 |
<?php |
| 183 |
echo wp_kses_post( |
| 184 |
Component::tag( 'sc-subscription' ) |
| 185 |
->id( 'customer-subscription-edit' ) |
| 186 |
->with( |
| 187 |
[ |
| 188 |
'heading' => __( 'Current Plan', 'surecart' ), |
| 189 |
'showCancel' => \SureCart::account()->customer_portal_protocol->subscription_cancellations_enabled && ! $subscription->remaining_period_count && ! $should_delay_cancellation, |
| 190 |
'protocol' => SubscriptionProtocol::with( [ 'preservation_coupon' ] )->find(), // \SureCart::account()->subscription_protocol, |
| 191 |
'subscription' => $subscription, |
| 192 |
'updatePaymentMethodUrl' => esc_url_raw( |
| 193 |
home_url( |
| 194 |
add_query_arg( |
| 195 |
[ |
| 196 |
'tab' => $this->getTab(), |
| 197 |
'action' => 'update_payment_method', |
| 198 |
'nonce' => wp_create_nonce( 'subscription-switch' ), |
| 199 |
] |
| 200 |
) |
| 201 |
) |
| 202 |
), |
| 203 |
] |
| 204 |
)->render() |
| 205 |
); |
| 206 |
?> |
| 207 |
<?php do_action( 'surecart/dashboard/subscription/after_current_plan', $subscription ); ?> |
| 208 |
<?php |
| 209 |
// show switch if we can change it. |
| 210 |
if ( $subscription->canBeSwitched() ) : |
| 211 |
echo wp_kses_post( |
| 212 |
Component::tag( 'sc-subscription-switch' ) |
| 213 |
->id( 'customer-subscription-switch' ) |
| 214 |
->with( |
| 215 |
[ |
| 216 |
'heading' => __( 'Update Plan', 'surecart' ), |
| 217 |
'productId' => $subscription->price->product->id, |
| 218 |
'productGroupId' => ( $subscription->price->product->product_group |
| 219 |
? ( $subscription->price->product->product_group->archived |
| 220 |
? null |
| 221 |
: $subscription->price->product->product_group->id ) |
| 222 |
: null ), |
| 223 |
'subscription' => $subscription, |
| 224 |
'successUrl' => home_url( |
| 225 |
add_query_arg( |
| 226 |
[ |
| 227 |
'tab' => $this->getTab(), |
| 228 |
'nonce' => wp_create_nonce( 'subscription-switch' ), |
| 229 |
] |
| 230 |
) |
| 231 |
), |
| 232 |
] |
| 233 |
)->render() |
| 234 |
); |
| 235 |
endif; |
| 236 |
?> |
| 237 |
|
| 238 |
</sc-spacing> |
| 239 |
|
| 240 |
<?php |
| 241 |
return ob_get_clean(); |
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* Update the subscription payment method |
| 246 |
* |
| 247 |
* @return string |
| 248 |
*/ |
| 249 |
public function update_payment_method() { |
| 250 |
$id = $this->getId(); |
| 251 |
|
| 252 |
if ( ! $id ) { |
| 253 |
return $this->notFound(); |
| 254 |
} |
| 255 |
|
| 256 |
// fetch subscription. |
| 257 |
$subscription = Subscription::with( |
| 258 |
[ |
| 259 |
'price', |
| 260 |
'price.product', |
| 261 |
'current_period', |
| 262 |
'period.checkout', |
| 263 |
'discount', |
| 264 |
'discount.coupon', |
| 265 |
] |
| 266 |
)->find( $id ); |
| 267 |
|
| 268 |
ob_start(); |
| 269 |
?> |
| 270 |
|
| 271 |
<sc-spacing style="--spacing: var(--sc-spacing-large)"> |
| 272 |
<sc-breadcrumbs> |
| 273 |
<sc-breadcrumb href="<?php echo esc_url( add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>"> |
| 274 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 275 |
</sc-breadcrumb> |
| 276 |
<sc-breadcrumb href=" |
| 277 |
<?php |
| 278 |
echo esc_url( |
| 279 |
add_query_arg( |
| 280 |
[ |
| 281 |
'tab' => $this->getTab(), |
| 282 |
'action' => 'index', |
| 283 |
'model' => 'subscription', |
| 284 |
], |
| 285 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 286 |
) |
| 287 |
); |
| 288 |
?> |
| 289 |
"> |
| 290 |
<?php esc_html_e( 'Plans', 'surecart' ); ?> |
| 291 |
</sc-breadcrumb> |
| 292 |
<sc-breadcrumb href=" |
| 293 |
<?php |
| 294 |
echo esc_url( |
| 295 |
add_query_arg( |
| 296 |
[ |
| 297 |
'tab' => $this->getTab(), |
| 298 |
'action' => 'edit', |
| 299 |
'model' => 'subscription', |
| 300 |
'id' => $this->getId(), |
| 301 |
], |
| 302 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 303 |
) |
| 304 |
); |
| 305 |
?> |
| 306 |
"> |
| 307 |
<?php esc_html_e( 'Plan', 'surecart' ); ?> |
| 308 |
</sc-breadcrumb> |
| 309 |
<sc-breadcrumb> |
| 310 |
<?php esc_html_e( 'Update Payment Method', 'surecart' ); ?> |
| 311 |
</sc-breadcrumb> |
| 312 |
</sc-breadcrumbs> |
| 313 |
|
| 314 |
<?php |
| 315 |
echo wp_kses_post( |
| 316 |
Component::tag( 'sc-subscription' ) |
| 317 |
->id( 'customer-subscription-edit' ) |
| 318 |
->with( |
| 319 |
[ |
| 320 |
'heading' => __( 'Current Plan', 'surecart' ), |
| 321 |
'showCancel' => false, |
| 322 |
'subscription' => $subscription, |
| 323 |
] |
| 324 |
)->render() |
| 325 |
); |
| 326 |
?> |
| 327 |
|
| 328 |
<?php |
| 329 |
echo wp_kses_post( |
| 330 |
Component::tag( 'sc-subscription-payment-method' ) |
| 331 |
->id( 'customer-subscription-payment-method' ) |
| 332 |
->with( |
| 333 |
[ |
| 334 |
'heading' => __( 'Change Payment Method', 'surecart' ), |
| 335 |
'subscription' => $subscription, |
| 336 |
] |
| 337 |
)->render() |
| 338 |
); |
| 339 |
?> |
| 340 |
|
| 341 |
</sc-spacing> |
| 342 |
|
| 343 |
<?php |
| 344 |
return ob_get_clean(); |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
/** |
| 349 |
* Get the terms text. |
| 350 |
*/ |
| 351 |
public function getTermsText() { |
| 352 |
$account = \SureCart::account(); |
| 353 |
$privacy_url = $account->customer_portal_protocol->privacy_url ?? \get_privacy_policy_url(); |
| 354 |
$terms_url = $account->customer_portal_protocol->terms_url ?? ''; |
| 355 |
|
| 356 |
if ( ! empty( $privacy_url ) && ! empty( $terms_url ) ) { |
| 357 |
// translators: %1$s is the terms URL, %2$s is the terms link text, %3$s is the privacy URL, %4$s is the privacy link text. |
| 358 |
return sprintf( __( 'By updating or canceling your plan, you agree to the <a href="%1$1s" target="_blank">%2$2s</a> and <a href="%3$3s" target="_blank">%4$4s</a>', 'surecart' ), esc_url( $terms_url ), __( 'Terms', 'surecart' ), esc_url( $privacy_url ), __( 'Privacy Policy', 'surecart' ) ); |
| 359 |
} |
| 360 |
|
| 361 |
if ( ! empty( $privacy_url ) ) { |
| 362 |
// translators: %1$s is the privacy policy URL, %2$s is the privacy policy link text. |
| 363 |
return sprintf( __( 'By updating or canceling your plan, you agree to the <a href="%1$1s" target="_blank">%2$2s</a>', 'surecart' ), esc_url( $privacy_url ), __( 'Privacy Policy', 'surecart' ) ); |
| 364 |
} |
| 365 |
|
| 366 |
if ( ! empty( $terms_url ) ) { |
| 367 |
// translators: %1$s is the terms URL, %2$s is the terms link text. |
| 368 |
return sprintf( __( 'By updating or canceling your plan, you agree to the <a href="%1$1s" target="_blank">%2$2s</a>', 'surecart' ), esc_url( $terms_url ), __( 'Terms', 'surecart' ) ); |
| 369 |
} |
| 370 |
|
| 371 |
return ''; |
| 372 |
} |
| 373 |
|
| 374 |
/** |
| 375 |
* Confirm the ad_hoc amount. |
| 376 |
* |
| 377 |
* @return void |
| 378 |
*/ |
| 379 |
public function confirm_amount() { |
| 380 |
$price = Price::find( $this->getParam( 'price_id' ) ); |
| 381 |
ob_start(); |
| 382 |
?> |
| 383 |
|
| 384 |
<sc-spacing style="--spacing: var(--sc-spacing-xx-large)"> |
| 385 |
<sc-breadcrumbs> |
| 386 |
<sc-breadcrumb href="<?php echo esc_url( add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>"> |
| 387 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 388 |
</sc-breadcrumb> |
| 389 |
<sc-breadcrumb href=" |
| 390 |
<?php |
| 391 |
echo esc_url( |
| 392 |
add_query_arg( |
| 393 |
[ |
| 394 |
'tab' => $this->getTab(), |
| 395 |
'action' => 'edit', |
| 396 |
'model' => 'subscription', |
| 397 |
'id' => $this->getId(), |
| 398 |
], |
| 399 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 400 |
) |
| 401 |
); |
| 402 |
?> |
| 403 |
"> |
| 404 |
<?php esc_html_e( 'Plan', 'surecart' ); ?> |
| 405 |
</sc-breadcrumb> |
| 406 |
<sc-breadcrumb> |
| 407 |
<?php esc_html_e( 'Enter Amount', 'surecart' ); ?> |
| 408 |
</sc-breadcrumb> |
| 409 |
</sc-breadcrumbs> |
| 410 |
|
| 411 |
<?php |
| 412 |
|
| 413 |
echo wp_kses_post( |
| 414 |
Component::tag( 'sc-subscription-ad-hoc-confirm' ) |
| 415 |
->id( 'subscription-ad-hoc-confirm' ) |
| 416 |
->with( |
| 417 |
[ |
| 418 |
'heading' => __( 'Enter An Amount', 'surecart' ), |
| 419 |
'price' => $price, |
| 420 |
'variant' => $this->getParam( 'variant' ), |
| 421 |
'currencyCode' => \SureCart::account()->currency, |
| 422 |
] |
| 423 |
)->render() |
| 424 |
); |
| 425 |
?> |
| 426 |
|
| 427 |
</sc-spacing> |
| 428 |
|
| 429 |
<?php |
| 430 |
return ob_get_clean(); |
| 431 |
} |
| 432 |
|
| 433 |
/** |
| 434 |
* Confirm the product variation. |
| 435 |
* |
| 436 |
* @return void |
| 437 |
*/ |
| 438 |
public function confirm_variation() { |
| 439 |
$price = Price::find( $this->getParam( 'price_id' ) ); |
| 440 |
$id = $this->getId(); |
| 441 |
|
| 442 |
if ( ! $id ) { |
| 443 |
return $this->notFound(); |
| 444 |
} |
| 445 |
|
| 446 |
// fetch subscription. |
| 447 |
$subscription = Subscription::with( |
| 448 |
[ |
| 449 |
'price', |
| 450 |
'price.product', |
| 451 |
] |
| 452 |
)->find( $id ); |
| 453 |
|
| 454 |
if ( ! $subscription ) { |
| 455 |
return $this->notFound(); |
| 456 |
} |
| 457 |
|
| 458 |
// fetch subscription product. |
| 459 |
$product = Product::with( |
| 460 |
[ |
| 461 |
'variants', |
| 462 |
'variant_options', |
| 463 |
'prices', |
| 464 |
] |
| 465 |
)->find( $price->product ); |
| 466 |
|
| 467 |
ob_start(); |
| 468 |
?> |
| 469 |
|
| 470 |
<sc-spacing style="--spacing: var(--sc-spacing-xx-large)"> |
| 471 |
<sc-breadcrumbs> |
| 472 |
<sc-breadcrumb href="<?php echo esc_url( add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>"> |
| 473 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 474 |
</sc-breadcrumb> |
| 475 |
<sc-breadcrumb href=" |
| 476 |
<?php |
| 477 |
echo esc_url( |
| 478 |
add_query_arg( |
| 479 |
[ |
| 480 |
'tab' => $this->getTab(), |
| 481 |
'action' => 'edit', |
| 482 |
'model' => 'subscription', |
| 483 |
'id' => $this->getId(), |
| 484 |
], |
| 485 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 486 |
) |
| 487 |
); |
| 488 |
?> |
| 489 |
"> |
| 490 |
<?php esc_html_e( 'Plan', 'surecart' ); ?> |
| 491 |
</sc-breadcrumb> |
| 492 |
<sc-breadcrumb> |
| 493 |
<?php esc_html_e( 'Choose Variation', 'surecart' ); ?> |
| 494 |
</sc-breadcrumb> |
| 495 |
</sc-breadcrumbs> |
| 496 |
|
| 497 |
<?php |
| 498 |
|
| 499 |
echo wp_kses_post( |
| 500 |
Component::tag( 'sc-subscription-variation-confirm' ) |
| 501 |
->id( 'subscription-ad-hoc-confirm' ) |
| 502 |
->with( |
| 503 |
[ |
| 504 |
'heading' => __( 'Choose a Variation', 'surecart' ), |
| 505 |
'product' => $product, |
| 506 |
'subscription' => $subscription, |
| 507 |
'price' => $price, |
| 508 |
] |
| 509 |
)->render() |
| 510 |
); |
| 511 |
?> |
| 512 |
|
| 513 |
</sc-spacing> |
| 514 |
|
| 515 |
<?php |
| 516 |
return ob_get_clean(); |
| 517 |
} |
| 518 |
|
| 519 |
/** |
| 520 |
* Confirm changing subscription |
| 521 |
* |
| 522 |
* @return function |
| 523 |
*/ |
| 524 |
public function confirm() { |
| 525 |
$back = add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 526 |
ob_start(); |
| 527 |
?> |
| 528 |
|
| 529 |
<sc-spacing style="--spacing: var(--sc-spacing-xx-large)"> |
| 530 |
<sc-breadcrumbs> |
| 531 |
<sc-breadcrumb href="<?php echo esc_url( add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>"> |
| 532 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 533 |
</sc-breadcrumb> |
| 534 |
<sc-breadcrumb href=" |
| 535 |
<?php |
| 536 |
echo esc_url( |
| 537 |
add_query_arg( |
| 538 |
[ |
| 539 |
'tab' => $this->getTab(), |
| 540 |
'action' => 'edit', |
| 541 |
'model' => 'subscription', |
| 542 |
'id' => $this->getId(), |
| 543 |
], |
| 544 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 545 |
) |
| 546 |
); |
| 547 |
?> |
| 548 |
"> |
| 549 |
<?php esc_html_e( 'Plan', 'surecart' ); ?> |
| 550 |
</sc-breadcrumb> |
| 551 |
<sc-breadcrumb> |
| 552 |
<?php esc_html_e( 'Confirm', 'surecart' ); ?> |
| 553 |
</sc-breadcrumb> |
| 554 |
</sc-breadcrumbs> |
| 555 |
|
| 556 |
<?php |
| 557 |
$terms = $this->getTermsText(); |
| 558 |
$quantity_enabled = (bool) \SureCart::account()->customer_portal_protocol->subscription_quantity_updates_enabled; |
| 559 |
if ( $this->getParam( 'ad_hoc_amount' ) ) { |
| 560 |
$quantity_enabled = false; |
| 561 |
} |
| 562 |
|
| 563 |
echo wp_kses_post( |
| 564 |
Component::tag( 'sc-upcoming-invoice' ) |
| 565 |
->id( 'customer-upcoming-invoice' ) |
| 566 |
->with( |
| 567 |
[ |
| 568 |
'heading' => __( 'New Plan', 'surecart' ), |
| 569 |
'subscriptionId' => $this->getId(), |
| 570 |
'priceId' => $this->getParam( 'price_id' ), |
| 571 |
'variantId' => $this->getParam( 'variant' ), |
| 572 |
'adHocAmount' => $this->getParam( 'ad_hoc_amount' ), |
| 573 |
'successUrl' => esc_url_raw( $back ), |
| 574 |
'quantityUpdatesEnabled' => (bool) $quantity_enabled, |
| 575 |
'quantity' => 1, |
| 576 |
] |
| 577 |
)->render( $terms ? '<span slot="terms">' . wp_kses_post( $terms ) . '</span>' : '' ) |
| 578 |
); |
| 579 |
?> |
| 580 |
|
| 581 |
|
| 582 |
</sc-spacing> |
| 583 |
|
| 584 |
<?php |
| 585 |
return ob_get_clean(); |
| 586 |
} |
| 587 |
|
| 588 |
/** |
| 589 |
* Confirm cancel subscription |
| 590 |
* |
| 591 |
* @return function |
| 592 |
*/ |
| 593 |
public function cancel() { |
| 594 |
$back_url = add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 595 |
$edit_subscription_url = add_query_arg( |
| 596 |
[ |
| 597 |
'tab' => $this->getTab(), |
| 598 |
'action' => 'edit', |
| 599 |
'model' => 'subscription', |
| 600 |
'id' => $this->getId(), |
| 601 |
], |
| 602 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 603 |
); |
| 604 |
ob_start(); |
| 605 |
?> |
| 606 |
<sc-spacing style="--spacing: var(--sc-spacing-xx-large)"> |
| 607 |
<sc-breadcrumbs> |
| 608 |
<sc-breadcrumb href="<?php echo esc_url( $back_url ); ?>"> |
| 609 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 610 |
</sc-breadcrumb> |
| 611 |
<sc-breadcrumb href="<?php echo esc_url( $edit_subscription_url ); ?>" > |
| 612 |
<?php esc_html_e( 'Plan', 'surecart' ); ?> |
| 613 |
</sc-breadcrumb> |
| 614 |
<sc-breadcrumb> |
| 615 |
<?php esc_html_e( 'Cancel', 'surecart' ); ?> |
| 616 |
</sc-breadcrumb> |
| 617 |
</sc-breadcrumbs> |
| 618 |
|
| 619 |
<?php |
| 620 |
echo wp_kses_post( |
| 621 |
Component::tag( 'sc-subscription-cancel' ) |
| 622 |
->id( 'customer-subscription-cancel' ) |
| 623 |
->with( |
| 624 |
[ |
| 625 |
'subscriptionId' => $this->getId(), |
| 626 |
'backUrl' => esc_url_raw( $edit_subscription_url ), |
| 627 |
'successUrl' => esc_url_raw( $back_url ), |
| 628 |
] |
| 629 |
)->render() |
| 630 |
); |
| 631 |
?> |
| 632 |
|
| 633 |
</sc-spacing> |
| 634 |
<?php |
| 635 |
return ob_get_clean(); |
| 636 |
} |
| 637 |
|
| 638 |
/** |
| 639 |
* Update payment |
| 640 |
* |
| 641 |
* @return function |
| 642 |
*/ |
| 643 |
public function payment() { |
| 644 |
$back_url = add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 645 |
|
| 646 |
$edit_subscription_url = add_query_arg( |
| 647 |
[ |
| 648 |
'tab' => $this->getTab(), |
| 649 |
'action' => 'edit', |
| 650 |
'model' => 'subscription', |
| 651 |
'id' => $this->getId(), |
| 652 |
], |
| 653 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 654 |
); |
| 655 |
|
| 656 |
$confirm_subscription_url = add_query_arg( |
| 657 |
[ |
| 658 |
'tab' => $this->getTab(), |
| 659 |
'action' => 'confirm', |
| 660 |
'model' => 'subscription', |
| 661 |
'ad_hoc_amount' => $this->getParam( 'ad_hoc_amount' ), |
| 662 |
'id' => $this->getId(), |
| 663 |
'price_id' => $this->getParam( 'price_id' ), |
| 664 |
'nonce' => wp_create_nonce( 'subscription-switch' ), |
| 665 |
], |
| 666 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 667 |
); |
| 668 |
|
| 669 |
$subscription = Subscription::find( $this->getId() ); |
| 670 |
ob_start(); |
| 671 |
?> |
| 672 |
|
| 673 |
<sc-spacing style="--spacing: var(--sc-spacing-xx-large)"> |
| 674 |
<sc-breadcrumbs> |
| 675 |
<sc-breadcrumb href="<?php echo esc_url( $back_url ); ?>"> |
| 676 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 677 |
</sc-breadcrumb> |
| 678 |
<sc-breadcrumb href="<?php echo esc_url( $edit_subscription_url ); ?>"> |
| 679 |
<?php esc_html_e( 'Plan', 'surecart' ); ?> |
| 680 |
</sc-breadcrumb> |
| 681 |
<sc-breadcrumb href="<?php echo esc_url( $confirm_subscription_url ); ?>"> |
| 682 |
<?php esc_html_e( 'Confirm', 'surecart' ); ?> |
| 683 |
</sc-breadcrumb> |
| 684 |
<sc-breadcrumb> |
| 685 |
<?php esc_html_e( 'Payment Method', 'surecart' ); ?> |
| 686 |
</sc-breadcrumb> |
| 687 |
</sc-breadcrumbs> |
| 688 |
|
| 689 |
<?php |
| 690 |
echo wp_kses_post( |
| 691 |
Component::tag( 'sc-subscription-payment' ) |
| 692 |
->id( 'customer-subscription-payment' ) |
| 693 |
->with( |
| 694 |
[ |
| 695 |
'customerIds' => $this->customerIds(), |
| 696 |
'subscription' => $subscription, |
| 697 |
'backUrl' => esc_url_raw( $confirm_subscription_url ), |
| 698 |
'successUrl' => esc_url_raw( $confirm_subscription_url ), |
| 699 |
'quantity' => 1, |
| 700 |
] |
| 701 |
)->render() |
| 702 |
); |
| 703 |
?> |
| 704 |
</sc-spacing> |
| 705 |
|
| 706 |
<?php |
| 707 |
return ob_get_clean(); |
| 708 |
} |
| 709 |
} |
| 710 |
|