-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathPolicyComplianceCheckController.php
143 lines (129 loc) · 4.55 KB
/
PolicyComplianceCheckController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\MerchantCenter;
use Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\BaseController;
use Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\CountryCodeTrait;
use Automattic\WooCommerce\GoogleListingsAndAds\API\TransportMethods;
use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\RESTServer;
use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\PolicyComplianceCheck;
use Exception;
use WP_REST_Response as Response;
defined( 'ABSPATH' ) || exit;
/**
* Class PolicyComplianceCheckController
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\API\Site\Controllers\MerchantCenter
*/
class PolicyComplianceCheckController extends BaseController {
use CountryCodeTrait;
/**
* The PolicyComplianceCheck object.
*
* @var PolicyComplianceCheck
*/
protected $policy_compliance_check;
/**
* BaseController constructor.
*
* @param RESTServer $server
* @param PolicyComplianceCheck $policy_compliance_check
*/
public function __construct( RESTServer $server, PolicyComplianceCheck $policy_compliance_check ) {
parent::__construct( $server );
$this->policy_compliance_check = $policy_compliance_check;
}
/**
* Register rest routes with WordPress.
*/
public function register_routes(): void {
$this->register_route(
'mc/policy_check',
[
[
'methods' => TransportMethods::READABLE,
'callback' => $this->get_policy_check_callback(),
'permission_callback' => $this->get_permission_callback(),
],
]
);
}
/**
* Get the allowed countries, payment gateways info, store ssl and refund return policy page for the controller.
*
* @return callable
*/
protected function get_policy_check_callback(): callable {
return function () {
try {
return new Response(
[
'allowed_countries' => $this->policy_compliance_check->is_accessible(),
'robots_restriction' => $this->policy_compliance_check->has_restriction(),
'page_not_found_error' => $this->policy_compliance_check->has_page_not_found_error(),
'page_redirects' => $this->policy_compliance_check->has_redirects(),
'payment_gateways' => $this->policy_compliance_check->has_payment_gateways(),
'store_ssl' => $this->policy_compliance_check->get_is_store_ssl(),
'refund_returns' => $this->policy_compliance_check->has_refund_return_policy_page(),
]
);
} catch ( Exception $e ) {
return $this->response_from_exception( $e );
}
};
}
/**
* Get the schema for policy compliance check endpoints.
*
* @return array
*/
protected function get_schema_properties(): array {
return [
'allowed_countries' => [
'type' => 'boolean',
'description' => __( 'The store website could be accessed or not by all users.', 'google-listings-and-ads' ),
'context' => [ 'view' ],
],
'robots_restriction' => [
'type' => 'boolean',
'description' => __( 'The merchant set the restrictions in robots.txt or not in the store.', 'google-listings-and-ads' ),
'context' => [ 'view' ],
],
'page_not_found_error' => [
'type' => 'boolean',
'description' => __( 'The sample of product landing pages leads to a 404 error.', 'google-listings-and-ads' ),
'context' => [ 'view' ],
],
'page_redirects' => [
'type' => 'boolean',
'description' => __( 'The sample of product landing pages have redirects through 3P domains.', 'google-listings-and-ads' ),
'context' => [ 'view' ],
],
'payment_gateways' => [
'type' => 'boolean',
'description' => __( 'The payment gateways associated with onboarding policy checking.', 'google-listings-and-ads' ),
'context' => [ 'view' ],
],
'store_ssl' => [
'type' => 'boolean',
'description' => __( 'The store ssl associated with onboarding policy checking.', 'google-listings-and-ads' ),
'context' => [ 'view' ],
],
'refund_returns' => [
'type' => 'boolean',
'description' => __( 'The refund returns policy associated with onboarding policy checking.', 'google-listings-and-ads' ),
'context' => [ 'view' ],
],
'schema' => $this->get_api_response_schema_callback(),
];
}
/**
* Get the item schema name for the controller.
*
* Used for building the API response schema.
*
* @return string
*/
protected function get_schema_title(): string {
return 'policy_check';
}
}