@@ -26,4 +26,163 @@ class WC_REST_Dev_Payment_Gateways_Controller extends WC_REST_Payment_Gateways_C
2626 */
2727 protected $ namespace = 'wc/v3 ' ;
2828
29+ /**
30+ * Prepare a payment gateway for response.
31+ *
32+ * @param WC_Payment_Gateway $gateway Payment gateway object.
33+ * @param WP_REST_Request $request Request object.
34+ * @return WP_REST_Response $response Response data.
35+ */
36+ public function prepare_item_for_response ( $ gateway , $ request ) {
37+ $ order = (array ) get_option ( 'woocommerce_gateway_order ' );
38+ $ item = array (
39+ 'id ' => $ gateway ->id ,
40+ 'title ' => $ gateway ->title ,
41+ 'description ' => $ gateway ->description ,
42+ 'order ' => isset ( $ order [ $ gateway ->id ] ) ? $ order [ $ gateway ->id ] : '' ,
43+ 'enabled ' => ( 'yes ' === $ gateway ->enabled ),
44+ 'method_title ' => $ gateway ->get_method_title (),
45+ 'method_description ' => $ gateway ->get_method_description (),
46+ 'method_supports ' => $ gateway ->supports ,
47+ 'settings ' => $ this ->get_settings ( $ gateway ),
48+ );
49+
50+ $ context = ! empty ( $ request ['context ' ] ) ? $ request ['context ' ] : 'view ' ;
51+ $ data = $ this ->add_additional_fields_to_object ( $ item , $ request );
52+ $ data = $ this ->filter_response_by_context ( $ data , $ context );
53+
54+ $ response = rest_ensure_response ( $ data );
55+ $ response ->add_links ( $ this ->prepare_links ( $ gateway , $ request ) );
56+
57+ /**
58+ * Filter payment gateway objects returned from the REST API.
59+ *
60+ * @param WP_REST_Response $response The response object.
61+ * @param WC_Payment_Gateway $gateway Payment gateway object.
62+ * @param WP_REST_Request $request Request object.
63+ */
64+ return apply_filters ( 'woocommerce_rest_prepare_payment_gateway ' , $ response , $ gateway , $ request );
65+ }
66+
67+ /**
68+ * Get the payment gateway schema, conforming to JSON Schema.
69+ *
70+ * @return array
71+ */
72+ public function get_item_schema () {
73+ $ schema = array (
74+ '$schema ' => 'http://json-schema.org/draft-04/schema# ' ,
75+ 'title ' => 'payment_gateway ' ,
76+ 'type ' => 'object ' ,
77+ 'properties ' => array (
78+ 'id ' => array (
79+ 'description ' => __ ( 'Payment gateway ID. ' , 'woocommerce ' ),
80+ 'type ' => 'string ' ,
81+ 'context ' => array ( 'view ' , 'edit ' ),
82+ 'readonly ' => true ,
83+ ),
84+ 'title ' => array (
85+ 'description ' => __ ( 'Payment gateway title on checkout. ' , 'woocommerce ' ),
86+ 'type ' => 'string ' ,
87+ 'context ' => array ( 'view ' , 'edit ' ),
88+ ),
89+ 'description ' => array (
90+ 'description ' => __ ( 'Payment gateway description on checkout. ' , 'woocommerce ' ),
91+ 'type ' => 'string ' ,
92+ 'context ' => array ( 'view ' , 'edit ' ),
93+ ),
94+ 'order ' => array (
95+ 'description ' => __ ( 'Payment gateway sort order. ' , 'woocommerce ' ),
96+ 'type ' => 'integer ' ,
97+ 'context ' => array ( 'view ' , 'edit ' ),
98+ 'arg_options ' => array (
99+ 'sanitize_callback ' => 'absint ' ,
100+ ),
101+ ),
102+ 'enabled ' => array (
103+ 'description ' => __ ( 'Payment gateway enabled status. ' , 'woocommerce ' ),
104+ 'type ' => 'boolean ' ,
105+ 'context ' => array ( 'view ' , 'edit ' ),
106+ ),
107+ 'method_title ' => array (
108+ 'description ' => __ ( 'Payment gateway method title. ' , 'woocommerce ' ),
109+ 'type ' => 'string ' ,
110+ 'context ' => array ( 'view ' , 'edit ' ),
111+ 'readonly ' => true ,
112+ ),
113+ 'method_description ' => array (
114+ 'description ' => __ ( 'Payment gateway method description. ' , 'woocommerce ' ),
115+ 'type ' => 'string ' ,
116+ 'context ' => array ( 'view ' , 'edit ' ),
117+ 'readonly ' => true ,
118+ ),
119+ 'method_supports ' => array (
120+ 'description ' => __ ( 'Supported features for this payment gateway. ' , 'woocommerce ' ),
121+ 'type ' => 'array ' ,
122+ 'context ' => array ( 'view ' , 'edit ' ),
123+ 'readonly ' => true ,
124+ 'items ' => array (
125+ 'type ' => 'string ' ,
126+ ),
127+ ),
128+ 'settings ' => array (
129+ 'description ' => __ ( 'Payment gateway settings. ' , 'woocommerce ' ),
130+ 'type ' => 'object ' ,
131+ 'context ' => array ( 'view ' , 'edit ' ),
132+ 'properties ' => array (
133+ 'id ' => array (
134+ 'description ' => __ ( 'A unique identifier for the setting. ' , 'woocommerce ' ),
135+ 'type ' => 'string ' ,
136+ 'context ' => array ( 'view ' , 'edit ' ),
137+ 'readonly ' => true ,
138+ ),
139+ 'label ' => array (
140+ 'description ' => __ ( 'A human readable label for the setting used in interfaces. ' , 'woocommerce ' ),
141+ 'type ' => 'string ' ,
142+ 'context ' => array ( 'view ' , 'edit ' ),
143+ 'readonly ' => true ,
144+ ),
145+ 'description ' => array (
146+ 'description ' => __ ( 'A human readable description for the setting used in interfaces. ' , 'woocommerce ' ),
147+ 'type ' => 'string ' ,
148+ 'context ' => array ( 'view ' , 'edit ' ),
149+ 'readonly ' => true ,
150+ ),
151+ 'type ' => array (
152+ 'description ' => __ ( 'Type of setting. ' , 'woocommerce ' ),
153+ 'type ' => 'string ' ,
154+ 'context ' => array ( 'view ' , 'edit ' ),
155+ 'enum ' => array ( 'text ' , 'email ' , 'number ' , 'color ' , 'password ' , 'textarea ' , 'select ' , 'multiselect ' , 'radio ' , 'image_width ' , 'checkbox ' ),
156+ 'readonly ' => true ,
157+ ),
158+ 'value ' => array (
159+ 'description ' => __ ( 'Setting value. ' , 'woocommerce ' ),
160+ 'type ' => 'string ' ,
161+ 'context ' => array ( 'view ' , 'edit ' ),
162+ ),
163+ 'default ' => array (
164+ 'description ' => __ ( 'Default value for the setting. ' , 'woocommerce ' ),
165+ 'type ' => 'string ' ,
166+ 'context ' => array ( 'view ' , 'edit ' ),
167+ 'readonly ' => true ,
168+ ),
169+ 'tip ' => array (
170+ 'description ' => __ ( 'Additional help text shown to the user about the setting. ' , 'woocommerce ' ),
171+ 'type ' => 'string ' ,
172+ 'context ' => array ( 'view ' , 'edit ' ),
173+ 'readonly ' => true ,
174+ ),
175+ 'placeholder ' => array (
176+ 'description ' => __ ( 'Placeholder text to be displayed in text inputs. ' , 'woocommerce ' ),
177+ 'type ' => 'string ' ,
178+ 'context ' => array ( 'view ' , 'edit ' ),
179+ 'readonly ' => true ,
180+ ),
181+ ),
182+ ),
183+ ),
184+ );
185+
186+ return $ this ->add_additional_fields_schema ( $ schema );
187+ }
29188}
0 commit comments