.4 * * @param string $where After the WHERE clause in the database query. * @param array $args Query arguments. * * @return string */ $query[] = apply_filters( 'wpforms_db_payments_queries_count_if_exists_after_where', '', $args ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared return (bool) $wpdb->get_var( implode( ' ', $query ) ); } /** * Get next payment. * * @since 1.8.2 * * @param int $payment_id Payment ID. * @param array $args Where conditions. * * @return object|null Object from DB values or null. */ public function get_next( $payment_id, $args = [] ) { global $wpdb; if ( empty( $payment_id ) ) { return null; } $query[] = "SELECT * FROM {$this->table_name}"; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $query[] = $wpdb->prepare( "WHERE $this->primary_key > %d", $payment_id ); $query[] = $this->add_secondary_where_conditions( $args ); $query[] = "ORDER BY $this->primary_key LIMIT 1"; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching return $wpdb->get_row( implode( ' ', $query ) ); } /** * Get previous payment. * * @since 1.8.2 * * @param int $payment_id Payment ID. * @param array $args Where conditions. * * @return object|null Object from DB values or null. */ public function get_prev( $payment_id, $args = [] ) { global $wpdb; if ( empty( $payment_id ) ) { return null; } $query[] = "SELECT * FROM $this->table_name"; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $query[] = $wpdb->prepare( "WHERE $this->primary_key < %d", $payment_id ); $query[] = $this->add_secondary_where_conditions( $args ); $query[] = "ORDER BY $this->primary_key DESC LIMIT 1"; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching return $wpdb->get_row( implode( ' ', $query ) ); } /** * Get previous payments count. * * @since 1.8.2 * * @param int $payment_id Payment ID. * @param array $args Where conditions. * * @return int */ public function get_prev_count( $payment_id, $args = [] ) { global $wpdb; if ( empty( $payment_id ) ) { return 0; } $query[] = "SELECT COUNT( $this->primary_key ) FROM $this->table_name"; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $query[] = $wpdb->prepare( "WHERE $this->primary_key < %d", $payment_id ); $query[] = $this->add_secondary_where_conditions( $args ); $query[] = "ORDER BY $this->primary_key ASC"; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching return (int) $wpdb->get_var( implode( ' ', $query ) ); } /** * Get subscription payment history for the given subscription ID. * This function returns an array of subscription payment object and renewal payments associated with the subscription. * * @global wpdb $wpdb Instantiation of the wpdb class. * * @since 1.8.4 * * @param string $subscription_id Subscription ID. * @param string $currency Currency that the payment was made in. * * @return array Array of payment objects. */ public function get_subscription_payment_history( $subscription_id, $currency = '' ) { $subscription = null; $renewals = []; // Bail early if the subscription ID is empty. if ( empty( $subscription_id ) ) { return [ $subscription, $renewals ]; } // Get the currency, if not provided. if ( empty( $currency ) ) { $currency = wpforms_get_currency(); } // Get the database instance. global $wpdb; // Get the general where clause. $where_clause = $this->add_secondary_where_conditions( [ 'currency' => $currency ] ); // Construct the query using a prepared statement. // Execute the query and fetch the results. // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE subscription_id = %s AND (type = 'subscription' OR type = 'renewal') {$where_clause} ORDER BY type ASC, date_created_gmt DESC", $subscription_id ) ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared // Search for the subscription object in the "$results" array. foreach ( $results as $key => $result ) { if ( $result->type === 'subscription' ) { $subscription = $result; unset( $results[ $key ] ); break; // Exit the loop after finding the subscription object. } } // Assign the remaining results to renewals. $renewals = $results; return [ $subscription, $renewals ]; } /** * Determine if given subscription has a renewal payment. * * @global wpdb $wpdb Instantiation of the wpdb class. * * @since 1.8.4 * * @param string $subscription_id Subscription ID. * * @return bool True if the subscription has a renewal payment, false otherwise. */ public function if_subscription_has_renewal( $subscription_id ) { // Bail early if the subscription ID is empty. if ( empty( $subscription_id ) ) { return false; } // Get the database instance. global $wpdb; $query[] = "SELECT 1 FROM {$this->table_name} AS s"; $query[] = 'WHERE s.subscription_id = %s'; $query[] = "AND s.type = 'subscription'"; $query[] = 'AND EXISTS('; $query[] = "SELECT 1 FROM {$this->table_name} AS r"; $query[] = 'WHERE s.subscription_id = r.subscription_id'; $query[] = "AND r.type = 'renewal'"; $query[] = ')'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare return (bool) $wpdb->get_var( $wpdb->prepare( implode( ' ', $query ), $subscription_id ) ); } /** * Get subscription payment for given subscription ID. * * @since 1.8.4 * * @param string $subscription_id Subscription ID. * * @return object|null */ public function get_subscription( $subscription_id ) { global $wpdb; $query[] = "SELECT * FROM {$this->table_name}"; $query[] = "WHERE subscription_id = %s AND type = 'subscription'"; $query[] = 'ORDER BY id DESC LIMIT 1'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare return $wpdb->get_row( $wpdb->prepare( implode( ' ', $query ), $subscription_id ) ); } /** * Get renewal payment for given invoice ID. * * @since 1.8.4 * * @param string $invoice_id Invoice ID. * * @return object|null */ public function get_renewal_by_invoice_id( $invoice_id ) { global $wpdb; $meta_table_name = wpforms()->obj( 'payment_meta' )->table_name; $query[] = "SELECT p.* FROM {$this->table_name} as p"; $query[] = "INNER JOIN {$meta_table_name} as pm ON p.id = pm.payment_id"; $query[] = "WHERE pm.meta_key = 'invoice_id' AND pm.meta_value = %s"; $query[] = 'ORDER BY p.id DESC LIMIT 1'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare return $wpdb->get_row( $wpdb->prepare( implode( ' ', $query ), $invoice_id ) ); } }
Warning: Cannot modify header information - headers already sent by (output started at /htdocs/wp-content/plugins/wpforms-lite/src/Db/Payments/Queries.php:1) in /htdocs/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/wp-content/plugins/wpforms-lite/src/Db/Payments/Queries.php:1) in /htdocs/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/wp-content/plugins/wpforms-lite/src/Db/Payments/Queries.php:1) in /htdocs/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/wp-content/plugins/wpforms-lite/src/Db/Payments/Queries.php:1) in /htdocs/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/wp-content/plugins/wpforms-lite/src/Db/Payments/Queries.php:1) in /htdocs/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/wp-content/plugins/wpforms-lite/src/Db/Payments/Queries.php:1) in /htdocs/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /htdocs/wp-content/plugins/wpforms-lite/src/Db/Payments/Queries.php:1) in /htdocs/wp-includes/rest-api/class-wp-rest-server.php on line 1775
{"code":"itsec_rest_api_access_restricted","message":"Vous n\u2019avez pas suffisamment de droits pour acc\u00e9der \u00e0 ce point de terminaison. L\u2019acc\u00e8s aux requ\u00eates API REST est limit\u00e9 par les r\u00e9glages de Solid Security.","data":{"status":401}}