self::SCHEMA_VERSION, 'code' => $code, 'message' => $message, ), $extra ); $response = new WP_REST_Response( $body, $status ); if ( isset( $extra['retry_after'] ) ) { $response->header( 'Retry-After', (string) (int) $extra['retry_after'] ); } return $response; } /** * Build an order create success response. * * @param int $wc_order_id Order id. * @param string $number Order number. A string, because a store plugin * can make the number non numeric. * @param bool $duplicate True when the order already existed. * @return WP_REST_Response */ public static function order_created( $wc_order_id, $number, $duplicate ) { return new WP_REST_Response( array( 'schema_version' => self::SCHEMA_VERSION, 'wc_order_id' => (int) $wc_order_id, 'wc_order_number' => (string) $number, 'duplicate' => (bool) $duplicate, ), $duplicate ? 200 : 201 ); } /** * The 401 answer. It is the same for every signature failure, so the caller * learns nothing about which check failed. * * @return WP_REST_Response */ public static function invalid_signature() { return self::error( 'invalid_signature', 'Signature verification failed.', 401 ); } /** * The 409 answer for a store that is a clone or that moved. * * @param string $reason Reason, for the log and for the operator. * @return WP_REST_Response */ public static function site_identity_mismatch( $reason ) { return self::error( 'site_identity_mismatch', 'This store is in safe mode (' . $reason . '). It cannot accept Aha orders.', 409 ); } }