PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.19.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.19.2
4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / packages / blocks / Controllers / SubscriptionController.php
surecart / packages / blocks / Controllers Last commit date
Middleware 2 years ago BaseController.php 2 years ago ChargeController.php 4 years ago CustomerController.php 2 years ago DownloadController.php 2 years ago InvoiceController.php 4 years ago LicenseController.php 2 years ago OrderController.php 2 years ago PaymentMethodController.php 2 years ago SubscriptionController.php 2 years ago UserController.php 3 years ago
SubscriptionController.php
708 lines
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 SubscriptionNonceVerificationMiddleware::class,
26 SubscriptionPermissionsControllerMiddleware::class,
27 UpdateSubscriptionMiddleware::class,
28 MissingPaymentMethodMiddleware::class,
29 ],
30 'confirm_amount' => [
31 SubscriptionNonceVerificationMiddleware::class,
32 SubscriptionPermissionsControllerMiddleware::class,
33 UpdateSubscriptionMiddleware::class,
34 MissingPaymentMethodMiddleware::class,
35 ],
36 'confirm_variation' => [
37 SubscriptionNonceVerificationMiddleware::class,
38 SubscriptionPermissionsControllerMiddleware::class,
39 UpdateSubscriptionMiddleware::class,
40 MissingPaymentMethodMiddleware::class,
41 ],
42 'update_payment_method' => [
43 SubscriptionNonceVerificationMiddleware::class,
44 SubscriptionPermissionsControllerMiddleware::class,
45 UpdateSubscriptionMiddleware::class,
46 MissingPaymentMethodMiddleware::class,
47 ],
48 ];
49
50 /**
51 * Render the block
52 *
53 * @param array $attributes Block attributes.
54 * @return function
55 */
56 public function preview( $attributes = [] ) {
57 return wp_kses_post(
58 Component::tag( 'sc-subscriptions-list' )
59 ->id( 'customer-subscriptions-preview' )
60 ->with(
61 [
62 'heading' => $attributes['title'] ?? null,
63 'isCustomer' => User::current()->isCustomer(),
64 'allLink' => add_query_arg(
65 [
66 'tab' => $this->getTab(),
67 'model' => 'subscription',
68 'action' => 'index',
69 ],
70 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
71 ),
72 'query' => apply_filters(
73 'surecart/dashboard/subscription_list/query',
74 [
75 'customer_ids' => array_values( User::current()->customerIds() ),
76 'status' => [ 'active', 'trialing', 'past_due', 'canceled' ],
77 'page' => 1,
78 'per_page' => 5,
79 ]
80 ),
81 ]
82 )->render( $attributes['title'] ? "<span slot='heading'>" . $attributes['title'] . '</span>' : '' )
83 );
84 }
85
86 /**
87 * Render the block
88 *
89 * @return function
90 */
91 public function index() {
92 \SureCart::assets()->addComponentData(
93 'sc-subscriptions-list',
94 '#customer-subscriptions-index',
95 [
96 'heading' => $attributes['title'] ?? __( 'Plans', 'surecart' ),
97 'isCustomer' => User::current()->isCustomer(),
98 'query' => apply_filters(
99 'surecart/dashboard/subscription_list/query',
100 [
101 'customer_ids' => array_values( User::current()->customerIds() ),
102 'status' => [ 'active', 'trialing', 'canceled' ],
103 'page' => 1,
104 'per_page' => 20,
105 ]
106 ),
107 ]
108 );
109 ob_start();
110 ?>
111 <sc-spacing style="--spacing: var(--sc-spacing-large)">
112 <sc-breadcrumbs>
113 <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 ?>">
114 <?php esc_html_e( 'Dashboard', 'surecart' ); ?>
115 </sc-breadcrumb>
116 <sc-breadcrumb>
117 <?php esc_html_e( 'Plans', 'surecart' ); ?>
118 </sc-breadcrumb>
119 </sc-breadcrumbs>
120 <sc-subscriptions-list id="customer-subscriptions-index"></sc-subscriptions-list>
121 </sc-spacing>
122 <?php
123 return ob_get_clean();
124 }
125
126 /**
127 * Show and individual checkout session.
128 *
129 * @return function
130 */
131 public function edit() {
132 $id = $this->getId();
133
134 if ( ! $id ) {
135 return $this->notFound();
136 }
137
138 // fetch subscription.
139 $subscription = Subscription::with(
140 [
141 'price',
142 'price.product',
143 'product.product_group',
144 'current_period',
145 'period.checkout',
146 'purchase',
147 'discount',
148 'discount.coupon',
149 'purchase.license',
150 'license.activations',
151 ]
152 )->find( $id );
153
154 $should_delay_cancellation = $subscription->shouldDelayCancellation();
155 ob_start();
156 ?>
157
158 <sc-spacing style="--spacing: var(--sc-spacing-large)">
159 <sc-breadcrumbs>
160 <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 ?>">
161 <?php esc_html_e( 'Dashboard', 'surecart' ); ?>
162 </sc-breadcrumb>
163 <sc-breadcrumb href="
164 <?php
165 echo esc_url(
166 add_query_arg(
167 [
168 'tab' => $this->getTab(),
169 'action' => 'index',
170 'model' => 'subscription',
171 ],
172 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
173 )
174 );
175 ?>
176 ">
177 <?php esc_html_e( 'Plans', 'surecart' ); ?>
178 </sc-breadcrumb>
179 <sc-breadcrumb>
180 <?php esc_html_e( 'Plan', 'surecart' ); ?>
181 </sc-breadcrumb>
182 </sc-breadcrumbs>
183
184 <?php
185 echo wp_kses_post(
186 Component::tag( 'sc-subscription' )
187 ->id( 'customer-subscription-edit' )
188 ->with(
189 [
190 'heading' => __( 'Current Plan', 'surecart' ),
191 'showCancel' => \SureCart::account()->portal_protocol->subscription_cancellations_enabled && ! $subscription->remaining_period_count && ! $should_delay_cancellation,
192 'protocol' => SubscriptionProtocol::with( [ 'preservation_coupon' ] )->find(), // \SureCart::account()->subscription_protocol,
193 'subscription' => $subscription,
194 'updatePaymentMethodUrl' => esc_url_raw(
195 home_url(
196 add_query_arg(
197 [
198 'tab' => $this->getTab(),
199 'action' => 'update_payment_method',
200 'nonce' => wp_create_nonce( 'subscription-switch' ),
201 ]
202 )
203 )
204 ),
205 ]
206 )->render()
207 );
208 ?>
209
210 <?php
211 // show switch if we can change it.
212 if ( $subscription->canBeSwitched() ) :
213 echo wp_kses_post(
214 Component::tag( 'sc-subscription-switch' )
215 ->id( 'customer-subscription-switch' )
216 ->with(
217 [
218 'heading' => __( 'Update Plan', 'surecart' ),
219 'productId' => $subscription->price->product->id,
220 'productGroupId' => ( $subscription->price->product->product_group
221 ? ( $subscription->price->product->product_group->archived
222 ? null
223 : $subscription->price->product->product_group->id )
224 : null ),
225 'subscription' => $subscription,
226 'successUrl' => home_url(
227 add_query_arg(
228 [
229 'tab' => $this->getTab(),
230 'nonce' => wp_create_nonce( 'subscription-switch' ),
231 ]
232 )
233 ),
234 ]
235 )->render()
236 );
237 endif;
238 ?>
239
240 </sc-spacing>
241
242 <?php
243 return ob_get_clean();
244 }
245
246 /**
247 * Update the subscription payment method
248 *
249 * @return string
250 */
251 public function update_payment_method() {
252 $id = $this->getId();
253
254 if ( ! $id ) {
255 return $this->notFound();
256 }
257
258 // fetch subscription.
259 $subscription = Subscription::with(
260 [
261 'price',
262 'price.product',
263 'current_period',
264 'period.checkout',
265 'discount',
266 'discount.coupon',
267 ]
268 )->find( $id );
269
270 ob_start();
271 ?>
272
273 <sc-spacing style="--spacing: var(--sc-spacing-large)">
274 <sc-breadcrumbs>
275 <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 ?>">
276 <?php esc_html_e( 'Dashboard', 'surecart' ); ?>
277 </sc-breadcrumb>
278 <sc-breadcrumb href="
279 <?php
280 echo esc_url(
281 add_query_arg(
282 [
283 'tab' => $this->getTab(),
284 'action' => 'index',
285 'model' => 'subscription',
286 ],
287 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
288 )
289 );
290 ?>
291 ">
292 <?php esc_html_e( 'Plans', 'surecart' ); ?>
293 </sc-breadcrumb>
294 <sc-breadcrumb href="
295 <?php
296 echo esc_url(
297 add_query_arg(
298 [
299 'tab' => $this->getTab(),
300 'action' => 'edit',
301 'model' => 'subscription',
302 'id' => $this->getId(),
303 ],
304 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
305 )
306 );
307 ?>
308 ">
309 <?php esc_html_e( 'Plan', 'surecart' ); ?>
310 </sc-breadcrumb>
311 <sc-breadcrumb>
312 <?php esc_html_e( 'Update Payment Method', 'surecart' ); ?>
313 </sc-breadcrumb>
314 </sc-breadcrumbs>
315
316 <?php
317 echo wp_kses_post(
318 Component::tag( 'sc-subscription' )
319 ->id( 'customer-subscription-edit' )
320 ->with(
321 [
322 'heading' => __( 'Current Plan', 'surecart' ),
323 'showCancel' => false,
324 'subscription' => $subscription,
325 ]
326 )->render()
327 );
328 ?>
329
330 <?php
331 echo wp_kses_post(
332 Component::tag( 'sc-subscription-payment-method' )
333 ->id( 'customer-subscription-payment-method' )
334 ->with(
335 [
336 'heading' => __( 'Change Payment Method', 'surecart' ),
337 'subscription' => $subscription,
338 ]
339 )->render()
340 );
341 ?>
342
343 </sc-spacing>
344
345 <?php
346 return ob_get_clean();
347 }
348
349
350 /**
351 * Get the terms text.
352 */
353 public function getTermsText() {
354 $account = \SureCart::account();
355 $privacy_url = $account->portal_protocol->privacy_url ?? \get_privacy_policy_url();
356 $terms_url = $account->portal_protocol->terms_url ?? '';
357
358 if ( ! empty( $privacy_url ) && ! empty( $terms_url ) ) {
359 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' ) );
360 }
361
362 if ( ! empty( $privacy_url ) ) {
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 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' ) );
368 }
369
370 return '';
371 }
372
373 /**
374 * Confirm the ad_hoc amount.
375 *
376 * @return void
377 */
378 public function confirm_amount() {
379 $price = Price::find( $this->getParam( 'price_id' ) );
380 ob_start();
381 ?>
382
383 <sc-spacing style="--spacing: var(--sc-spacing-xx-large)">
384 <sc-breadcrumbs>
385 <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 ?>">
386 <?php esc_html_e( 'Dashboard', 'surecart' ); ?>
387 </sc-breadcrumb>
388 <sc-breadcrumb href="
389 <?php
390 echo esc_url(
391 add_query_arg(
392 [
393 'tab' => $this->getTab(),
394 'action' => 'edit',
395 'model' => 'subscription',
396 'id' => $this->getId(),
397 ],
398 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
399 )
400 );
401 ?>
402 ">
403 <?php esc_html_e( 'Plan', 'surecart' ); ?>
404 </sc-breadcrumb>
405 <sc-breadcrumb>
406 <?php esc_html_e( 'Enter Amount', 'surecart' ); ?>
407 </sc-breadcrumb>
408 </sc-breadcrumbs>
409
410 <?php
411
412 echo wp_kses_post(
413 Component::tag( 'sc-subscription-ad-hoc-confirm' )
414 ->id( 'subscription-ad-hoc-confirm' )
415 ->with(
416 [
417 'heading' => __( 'Enter An Amount', 'surecart' ),
418 'price' => $price,
419 'variant' => $this->getParam( 'variant' ),
420 ]
421 )->render()
422 );
423 ?>
424
425 </sc-spacing>
426
427 <?php
428 return ob_get_clean();
429 }
430
431 /**
432 * Confirm the product variation.
433 *
434 * @return void
435 */
436 public function confirm_variation() {
437 $price = Price::find( $this->getParam( 'price_id' ) );
438 $id = $this->getId();
439
440 if ( ! $id ) {
441 return $this->notFound();
442 }
443
444 // fetch subscription.
445 $subscription = Subscription::with(
446 [
447 'price',
448 'price.product',
449 ]
450 )->find( $id );
451
452 if ( ! $subscription ) {
453 return $this->notFound();
454 }
455
456 // fetch subscription product.
457 $product = Product::with(
458 [
459 'variants',
460 'variant_options',
461 'prices',
462 ]
463 )->find( $price->product );
464
465 ob_start();
466 ?>
467
468 <sc-spacing style="--spacing: var(--sc-spacing-xx-large)">
469 <sc-breadcrumbs>
470 <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 ?>">
471 <?php esc_html_e( 'Dashboard', 'surecart' ); ?>
472 </sc-breadcrumb>
473 <sc-breadcrumb href="
474 <?php
475 echo esc_url(
476 add_query_arg(
477 [
478 'tab' => $this->getTab(),
479 'action' => 'edit',
480 'model' => 'subscription',
481 'id' => $this->getId(),
482 ],
483 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
484 )
485 );
486 ?>
487 ">
488 <?php esc_html_e( 'Plan', 'surecart' ); ?>
489 </sc-breadcrumb>
490 <sc-breadcrumb>
491 <?php esc_html_e( 'Choose Variation', 'surecart' ); ?>
492 </sc-breadcrumb>
493 </sc-breadcrumbs>
494
495 <?php
496
497 echo wp_kses_post(
498 Component::tag( 'sc-subscription-variation-confirm' )
499 ->id( 'subscription-ad-hoc-confirm' )
500 ->with(
501 [
502 'heading' => __( 'Choose a Variation', 'surecart' ),
503 'product' => $product,
504 'subscription' => $subscription,
505 'price' => $price,
506 ]
507 )->render()
508 );
509 ?>
510
511 </sc-spacing>
512
513 <?php
514 return ob_get_clean();
515 }
516
517 /**
518 * Confirm changing subscription
519 *
520 * @return function
521 */
522 public function confirm() {
523 $back = add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
524 ob_start();
525 ?>
526
527 <sc-spacing style="--spacing: var(--sc-spacing-xx-large)">
528 <sc-breadcrumbs>
529 <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 ?>">
530 <?php esc_html_e( 'Dashboard', 'surecart' ); ?>
531 </sc-breadcrumb>
532 <sc-breadcrumb href="
533 <?php
534 echo esc_url(
535 add_query_arg(
536 [
537 'tab' => $this->getTab(),
538 'action' => 'edit',
539 'model' => 'subscription',
540 'id' => $this->getId(),
541 ],
542 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
543 )
544 );
545 ?>
546 ">
547 <?php esc_html_e( 'Plan', 'surecart' ); ?>
548 </sc-breadcrumb>
549 <sc-breadcrumb>
550 <?php esc_html_e( 'Confirm', 'surecart' ); ?>
551 </sc-breadcrumb>
552 </sc-breadcrumbs>
553
554 <?php
555 $terms = $this->getTermsText();
556 $quantity_enabled = (bool) \SureCart::account()->portal_protocol->subscription_quantity_updates_enabled;
557 if ( $this->getParam( 'ad_hoc_amount' ) ) {
558 $quantity_enabled = false;
559 }
560
561 echo wp_kses_post(
562 Component::tag( 'sc-upcoming-invoice' )
563 ->id( 'customer-upcoming-invoice' )
564 ->with(
565 [
566 'heading' => __( 'New Plan', 'surecart' ),
567 'subscriptionId' => $this->getId(),
568 'priceId' => $this->getParam( 'price_id' ),
569 'variantId' => $this->getParam( 'variant' ),
570 'adHocAmount' => $this->getParam( 'ad_hoc_amount' ),
571 'successUrl' => esc_url_raw( $back ),
572 'quantityUpdatesEnabled' => (bool) $quantity_enabled,
573 'quantity' => 1,
574 ]
575 )->render( $terms ? '<span slot="terms">' . wp_kses_post( $terms ) . '</span>' : '' )
576 );
577 ?>
578
579
580 </sc-spacing>
581
582 <?php
583 return ob_get_clean();
584
585 }
586
587 /**
588 * Confirm cancel subscription
589 *
590 * @return function
591 */
592 public function cancel() {
593 $back_url = add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
594 $edit_subscription_url = add_query_arg(
595 [
596 'tab' => $this->getTab(),
597 'action' => 'edit',
598 'model' => 'subscription',
599 'id' => $this->getId(),
600 ],
601 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
602 );
603 ob_start();
604 ?>
605 <sc-spacing style="--spacing: var(--sc-spacing-xx-large)">
606 <sc-breadcrumbs>
607 <sc-breadcrumb href="<?php echo esc_url( $back_url ); ?>">
608 <?php esc_html_e( 'Dashboard', 'surecart' ); ?>
609 </sc-breadcrumb>
610 <sc-breadcrumb href="<?php echo esc_url( $edit_subscription_url ); ?>" >
611 <?php esc_html_e( 'Plan', 'surecart' ); ?>
612 </sc-breadcrumb>
613 <sc-breadcrumb>
614 <?php esc_html_e( 'Cancel', 'surecart' ); ?>
615 </sc-breadcrumb>
616 </sc-breadcrumbs>
617
618 <?php
619 echo wp_kses_post(
620 Component::tag( 'sc-subscription-cancel' )
621 ->id( 'customer-subscription-cancel' )
622 ->with(
623 [
624 'subscriptionId' => $this->getId(),
625 'backUrl' => esc_url_raw( $edit_subscription_url ),
626 'successUrl' => esc_url_raw( $back_url ),
627 ]
628 )->render()
629 );
630 ?>
631
632 </sc-spacing>
633 <?php
634 return ob_get_clean();
635 }
636
637 /**
638 * Update payment
639 *
640 * @return function
641 */
642 public function payment() {
643 $back_url = add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
644
645 $edit_subscription_url = add_query_arg(
646 [
647 'tab' => $this->getTab(),
648 'action' => 'edit',
649 'model' => 'subscription',
650 'id' => $this->getId(),
651 ],
652 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
653 );
654
655 $confirm_subscription_url = add_query_arg(
656 [
657 'tab' => $this->getTab(),
658 'action' => 'confirm',
659 'model' => 'subscription',
660 'ad_hoc_amount' => $this->getParam( 'ad_hoc_amount' ),
661 'id' => $this->getId(),
662 'price_id' => $this->getParam( 'price_id' ),
663 ],
664 remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
665 );
666
667 $subscription = Subscription::find( $this->getId() );
668 ob_start();
669 ?>
670
671 <sc-spacing style="--spacing: var(--sc-spacing-xx-large)">
672 <sc-breadcrumbs>
673 <sc-breadcrumb href="<?php echo esc_url( $back_url ); ?>">
674 <?php esc_html_e( 'Dashboard', 'surecart' ); ?>
675 </sc-breadcrumb>
676 <sc-breadcrumb href="<?php echo esc_url( $edit_subscription_url ); ?>">
677 <?php esc_html_e( 'Plan', 'surecart' ); ?>
678 </sc-breadcrumb>
679 <sc-breadcrumb href="<?php echo esc_url( $confirm_subscription_url ); ?>">
680 <?php esc_html_e( 'Confirm', 'surecart' ); ?>
681 </sc-breadcrumb>
682 <sc-breadcrumb>
683 <?php esc_html_e( 'Payment Method', 'surecart' ); ?>
684 </sc-breadcrumb>
685 </sc-breadcrumbs>
686
687 <?php
688 echo wp_kses_post(
689 Component::tag( 'sc-subscription-payment' )
690 ->id( 'customer-subscription-payment' )
691 ->with(
692 [
693 'customerIds' => $this->customerIds(),
694 'subscription' => $subscription,
695 'backUrl' => esc_url_raw( $confirm_subscription_url ),
696 'successUrl' => esc_url_raw( $confirm_subscription_url ),
697 'quantity' => 1,
698 ]
699 )->render()
700 );
701 ?>
702 </sc-spacing>
703
704 <?php
705 return ob_get_clean();
706 }
707 }
708