PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / mcp-core / Support / ProGateResolver.php

ProGateResolver.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/mcp-core/Support/ProGateResolver.php

55 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Resolves a `required_pro_templately` import failure into a purchase
4 * reference (FR-010), reusing the existing `Templately\API\Checkout` logic
5 * — the same checkout flow the browser dashboard already uses.
6 *
7 * @package Templately\Modules\McpCore\Support
8 */
9
10 namespace Templately\Modules\McpCore\Support;
11
12 use WP_Error;
13
14 class ProGateResolver {
15
16 /**
17 * If $error is the Pro-entitlement gate, re-wrap it with a live checkout
18 * URL attached. Any other error is passed through unchanged.
19 *
20 * @param WP_Error $error
21 * @param int $template_id
22 * @return WP_Error
23 */
24 public static function to_purchase_error( WP_Error $error, int $template_id ): WP_Error {
25 if ( $error->get_error_code() !== 'required_pro_templately' ) {
26 return $error;
27 }
28
29 return new WP_Error(
30 'required_pro_templately',
31 $error->get_error_message(),
32 [ 'purchase' => [ 'checkout_url' => self::resolve_checkout_url( $template_id ) ] ]
33 );
34 }
35
36 /**
37 * @param int $template_id
38 * @return string|null
39 */
40 private static function resolve_checkout_url( int $template_id ) {
41 $response = RestDispatcher::dispatch( 'POST', '/templately/v1/checkout', [
42 'purchase_type' => 'template',
43 'id' => $template_id,
44 ] );
45
46 if ( is_wp_error( $response ) ) {
47 return null;
48 }
49
50 $data = $response->get_data();
51
52 return $data['url'] ?? null;
53 }
54 }
55