$process Process class instance. */ do_action( 'wpforms_square_process_update_entry_meta', $fields, $form_data, $entry_id, $resource, $this ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName } /** * Add details to payment data. * * @since 1.9.5 * * @param array $payment_data Payment data args. * @param array $fields Final/sanitized submitted field data. * @param array $form_data Form data and settings. * * @return array */ public function prepare_payment_data( $payment_data, array $fields, array $form_data ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed $payment_data = (array) $payment_data; // If there are errors or API is not initialized, return the original payment data. if ( $this->errors || ! $this->api ) { return $payment_data; } $resource = $this->api->get_response_resource(); // If the resource is empty, return the original payment meta. if ( empty( $resource ) ) { return $payment_data; } $type = Helpers::array_key_first( $resource ); $payment = $resource[ $type ]; $is_subscription = $type === 'subscription'; $payment_data['status'] = 'processed'; $payment_data['gateway'] = 'square'; $payment_data['mode'] = Helpers::is_sandbox_mode() ? 'test' : 'live'; $payment_data['customer_id'] = sanitize_text_field( $payment->getCustomerId() ); $payment_data['title'] = $this->get_payment_title( $payment ); if ( $is_subscription ) { $payment_data['subscription_id'] = sanitize_text_field( $payment->getId() ); $payment_data['subscription_status'] = 'not-synced'; return $payment_data; } $payment_data['transaction_id'] = sanitize_text_field( $payment->getId() ); return $payment_data; } /** * Get Payment title. * * @since 1.9.5 * * @param object $payment Payment object. * * @return string Payment title. */ private function get_payment_title( $payment ): string { // Look for the cardholder name. $card = $this->get_card(); $customer_name = $card ? $this->get_card_holder( $card ) : ''; if ( $customer_name ) { return sanitize_text_field( $customer_name ); } $customer_name = $this->get_customer_name(); if ( $customer_name ) { return sanitize_text_field( implode( ' ', array_values( $customer_name ) ) ); } $customer_email = $this->get_customer_email(); if ( $customer_email ) { return sanitize_email( $customer_email ); } return ''; } /** * Add payment meta for a successful one-time or subscription payment. * * @since 1.9.5 * * @param array $payment_meta Payment meta. * @param array $fields Final/sanitized submitted field data. * @param array $form_data Form data and settings. * * @return array */ public function prepare_payment_meta( $payment_meta, array $fields, array $form_data ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed $payment_meta = (array) $payment_meta; // If there are errors or API is not initialized, return the original payment meta. if ( $this->errors || ! $this->api ) { return $payment_meta; } $resource = $this->api->get_response_resource(); // If the resource is empty, return the original payment meta. if ( empty( $resource ) ) { return $payment_meta; } $type = Helpers::array_key_first( $resource ); $credit_card_details = $this->get_card(); $is_subscription = $type === 'subscription'; if ( $is_subscription ) { $payment_meta['subscription_period'] = $this->subscription_settings['phase_cadence']['slug']; } $payment_meta['method_type'] = 'card'; if ( ! empty( $credit_card_details ) ) { $payment_meta['credit_card_last4'] = $credit_card_details->getLast4(); $payment_meta['credit_card_expires'] = $credit_card_details->getExpMonth() . '/' . $credit_card_details->getExpYear(); $payment_meta['credit_card_method'] = strtolower( $credit_card_details->getCardBrand() ); $payment_meta['credit_card_name'] = $this->get_card_holder( $credit_card_details ); } // Add a log indicating that the charge was successful. $payment_meta['log'] = $this->format_payment_log( 'Square payment was created.' ); return $payment_meta; } /** * Add payment info for successful payment. * * @since 1.9.5 * * @param string $payment_id Payment ID. * @param array $fields Final/sanitized submitted field data. * @param array $form_data Form data and settings. */ public function process_payment_saved( $payment_id, array $fields, array $form_data ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed $payment_id = (string) $payment_id; // If there are errors or API is not initialized, return the original payment meta. if ( $this->errors || ! $this->api ) { return; } $resource = $this->api->get_response_resource(); // If the resource is empty, return the original payment meta. if ( empty( $resource ) ) { return; } $type = Helpers::array_key_first( $resource ); if ( $type === 'subscription' ) { $this->api->update_subscription( [ 'id' => $resource[ $type ]->getId(), 'payment_id' => $payment_id, ] ); return; } wpforms()->obj( 'payment_meta' )->add_log( $payment_id, sprintf( 'Square payment was processed. (Receipt ID: %s)', $resource[ $type ]->getReceiptNumber() ) ); } /** * Return payment log value. * * @since 1.9.5 * * @param string $value Log value. * * @return string */ private function format_payment_log( string $value ): string { return wp_json_encode( [ 'value' => sanitize_text_field( $value ), 'date' => gmdate( 'Y-m-d H:i:s' ), ] ); } /** * Get Customer name. * * @since 1.9.5 * * @return array */ private function get_customer_name(): array { $customer_name = []; // Billing first name. if ( ! empty( $this->fields[ $this->settings['billing_name'] ]['first'] ) ) { $customer_name['first_name'] = $this->fields[ $this->settings['billing_name'] ]['first']; } // Billing last name. if ( ! empty( $this->fields[ $this->settings['billing_name'] ]['last'] ) ) { $customer_name['last_name'] = $this->fields[ $this->settings['billing_name'] ]['last']; } // If a Name field has the `Simple` format. if ( empty( $customer_name['first_name'] ) && empty( $customer_name['last_name'] ) && ! empty( $this->fields[ $this->settings['billing_name'] ]['value'] ) ) { $customer_name['first_name'] = $this->fields[ $this->settings['billing_name'] ]['value']; } return $customer_name; } /** * Get Customer email. * * @since 1.9.5 * * @return string */ private function get_customer_email(): string { return ! empty( $this->fields[ $this->settings['buyer_email'] ]['value'] ) ? $this->fields[ $this->settings['buyer_email'] ]['value'] : ''; } /** * Retrieve a Cardholder Name. * * @since 1.9.5 * * @param Card $card Card object. * * @return string */ private function get_card_holder( $card ): string { $holder = ''; if ( $card instanceof Card ) { $holder = $card->getCardholderName(); } if ( empty( $holder ) && isset( $this->cc_field['cardname'] ) ) { $holder = $this->cc_field['cardname']; } return $holder; } }
Fatal error: Uncaught Error: Class 'WPForms\Integrations\Square\Process' not found in /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Integrations/Square/Square.php:199 Stack trace: #0 /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Integrations/Square/Square.php(84): WPForms\Integrations\Square\Square->load_processing() #1 /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Integrations/Loader.php(88): WPForms\Integrations\Square\Square->load() #2 /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Integrations/Loader.php(73): WPForms\Integrations\Loader->load_integration(Object(WPForms\Integrations\Square\Square)) #3 /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Integrations/Loader.php(22): WPForms\Integrations\Loader->__construct() #4 /home/yoldasm2/public_html/wp-includes/class-wp-hook.php(324): WPForms\Integrations\Loader::get_instance('') #5 /home/yoldasm2/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(Object(WPForms\Provide in /home/yoldasm2/public_html/wp-content/plugins/wpforms-lite/src/Integrations/Square/Square.php on line 199