Skip to content

Commit

Permalink
Add setting for order ID template.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Aug 30, 2023
1 parent 7d250b9 commit c49948b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
41 changes: 41 additions & 0 deletions src/FormidableFormsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
45 changes: 27 additions & 18 deletions views/payment-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<input type="text" name="%s" value="%s" class="large-text frm_help" title="" data-original-title="%s" />',
esc_attr( $this->get_field_name( $id ) ),
esc_attr( $current ),
esc_attr( $field['description'] )
);
};

$fields = [
[
'id' => 'pronamic_pay_amount_field',
Expand Down Expand Up @@ -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(
'<input type="text" name="%s" value="%s" class="large-text frm_help" title="" data-original-title="%s" />',
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',
Expand Down

0 comments on commit c49948b

Please sign in to comment.