diff --git a/src/Extension.php b/src/Extension.php index c6a1c3a..5ced06e 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -371,7 +371,7 @@ public function redirect_for_payment( $entry_id, $form_id ) { $payment->source = 'formidable-forms'; $payment->source_id = $entry_id; - $payment->order_id = $entry_id; + $payment->order_id = FormidableFormsHelper::get_order_id( $this->action, $form_id, $entry, $entry_id ); $description = FormidableFormsHelper::get_description( $this->action, $form_id, $entry, $entry_id ); diff --git a/src/FormidableFormsHelper.php b/src/FormidableFormsHelper.php index 34432c1..395e751 100644 --- a/src/FormidableFormsHelper.php +++ b/src/FormidableFormsHelper.php @@ -48,6 +48,47 @@ public static function get_currency_from_settings() { return $currency; } + /** + * Get order ID. + * + * @param unknown $action Action. + * @param int $form_id Form ID. + * @param unknown $entry Entry. + * @param int $entry_id Entry ID. + * @return string + */ + public static function get_order_id( $action, $form_id, $entry, $entry_id ) { + if ( ! \array_key_exists( 'pronamic_pay_order_id', $action->post_content ) ) { + return $entry_id; + } + + // Order ID template. + $order_id_template = $action->post_content['pronamic_pay_order_id']; + + /** + * Find shortcode. + * + * @link https://github.com/wp-premium/formidable/blob/2.0.22/classes/helpers/FrmFieldsHelper.php#L684-L696 + */ + $shortcodes = FrmFieldsHelper::get_shortcodes( $order_id_template, $form_id ); + + /** + * Replace shortcodes. + * + * @link https://github.com/wp-premium/formidable/blob/2.0.22/classes/helpers/FrmFieldsHelper.php#L715-L821 + */ + $order_id = FrmFieldsHelper::replace_content_shortcodes( $order_id_template, $entry, $shortcodes ); + + /** + * Fallback to entry ID. + */ + if ( '' === $order_id ) { + $order_id = (string) $entry_id; + } + + return $order_id; + } + /** * Get description. * diff --git a/views/payment-settings.php b/views/payment-settings.php index bcd6f53..d3f67ff 100644 --- a/views/payment-settings.php +++ b/views/payment-settings.php @@ -16,6 +16,23 @@ * @since 1.0.0 */ +$callback_text_field = function ( $field ) use ( $instance ) { + $id = $field['id']; + + $current = ''; + + if ( \array_key_exists( $id, $instance->post_content ) ) { + $current = $instance->post_content[ $id ]; + } + + printf( + '', + esc_attr( $this->get_field_name( $id ) ), + esc_attr( $current ), + esc_attr( $field['description'] ) + ); +}; + $fields = [ [ 'id' => 'pronamic_pay_amount_field', @@ -129,24 +146,16 @@ }, ], [ - 'id' => 'pronamic_pay_transaction_description', - 'label' => __( 'Transaction Description', 'pronamic_ideal' ), - 'callback' => function ( $field ) use ( $instance ) { - $id = $field['id']; - - $current = ''; - - if ( \array_key_exists( $id, $instance->post_content ) ) { - $current = $instance->post_content[ $id ]; - } - - printf( - '', - esc_attr( $this->get_field_name( $id ) ), - esc_attr( $current ), - esc_attr__( 'Enter a transaction description, you can use Formidable Forms shortcodes.', 'pronamic_ideal' ) - ); - }, + 'id' => 'pronamic_pay_order_id', + 'label' => __( 'Order ID', 'pronamic_ideal' ), + 'description' => __( 'Enter an order ID, you can use Formidable Forms shortcodes.', 'pronamic_ideal' ), + 'callback' => $callback_text_field, + ], + [ + 'id' => 'pronamic_pay_transaction_description', + 'label' => __( 'Transaction Description', 'pronamic_ideal' ), + 'description' => __( 'Enter a transaction description, you can use Formidable Forms shortcodes.', 'pronamic_ideal' ), + 'callback' => $callback_text_field, ], [ 'id' => 'pronamic_pay_delay_notifications',