Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stripe Field #1778

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
"form-hidden-field": {
"block": "blocks/blocks/form/hidden-field/block.json"
},
"form-stripe-field": {
"block": "blocks/blocks/form/stripe-field/block.json"
},
"google-map": {
"block": "blocks/blocks/google-map/block.json",
"assets": {
Expand Down
18 changes: 9 additions & 9 deletions inc/integrations/api/form-request-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Form_Data_Request {
/**
* Form fields options.
*
* @var array
* @var array<Form_Field_WP_Option_Data>
* @since 2.2.3
*/
protected $form_fields_options = array();
Expand Down Expand Up @@ -325,7 +325,7 @@ public function get_form_inputs() {
* @return Form_Settings_Data|null
* @since 2.0.0
*/
public function get_form_options() {
public function get_form_wp_options() {
return $this->form_options;
}

Expand Down Expand Up @@ -475,11 +475,11 @@ public function get_email_from_form_input() {
/**
* Add a field option.
*
* @param Form_Field_Option_Data $field_option The field option.
* @param Form_Field_WP_Option_Data $field_option The field option.
* @return void
*/
public function add_field_option( $field_option ) {
if ( $field_option instanceof Form_Field_Option_Data ) {
public function add_field_wp_option( $field_option ) {
if ( $field_option instanceof Form_Field_WP_Option_Data ) {
if ( empty( $this->form_fields_options ) ) {
$this->form_fields_options = array();
}
Expand All @@ -494,7 +494,7 @@ public function add_field_option( $field_option ) {
* @param string $field_option_name The field option name.
* @return void
*/
public function remove_field_option( $field_option_name ) {
public function remove_field_wp_option( $field_option_name ) {
if ( isset( $this->form_fields_options[ $field_option_name ] ) ) {
unset( $this->form_fields_options[ $field_option_name ] );
}
Expand All @@ -503,17 +503,17 @@ public function remove_field_option( $field_option_name ) {
/**
* Get the field options.
*
* @return array
* @return array<Form_Field_WP_Option_Data>
*/
public function get_field_options() {
public function get_wp_fields_options() {
return $this->form_fields_options;
}

/**
* Get the field option.
*
* @param string $field_option_name The field option name.
* @return Form_Field_Option_Data|null
* @return Form_Field_WP_Option_Data|null
*/
public function get_field_option( $field_option_name ) {
if ( isset( $this->form_fields_options[ $field_option_name ] ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @package ThemeIsle\GutenbergBlocks\Integration
* @since 2.2.3
*/
class Form_Field_Option_Data {
class Form_Field_WP_Option_Data {

/**
* The name of the field option.
Expand All @@ -36,17 +36,22 @@ class Form_Field_Option_Data {
*/
protected $options = array();

/**
* The stripe data of the field option.
*
* @var array
*/
protected $stripe_product_info = array();

/**
* Form_Field_Option_Data constructor.
*
* @param string $field_option_name The name of the field option.
* @param string $field_option_type The type of the field option.
* @param array $options The options of the field option.
*/
public function __construct( $field_option_name = '', $field_option_type = '', $options = array() ) {
public function __construct( $field_option_name = '', $field_option_type = '' ) {
$this->field_option_name = $field_option_name;
$this->field_option_type = $field_option_type;
$this->options = $options;
}

/**
Expand Down Expand Up @@ -91,6 +96,15 @@ public function get_option( $option_name ) {
return $this->options[ $option_name ];
}

/**
* Get the stripe data of the field option.
*
* @return array The stripe data of the field option.
*/
public function get_stripe_product_info() {
return $this->stripe_product_info;
}

/**
* Set the option of the field option.
*
Expand Down Expand Up @@ -128,6 +142,24 @@ public function set_name( $field_option_name ) {
$this->field_option_name = $field_option_name;
}

/**
* Set the stripe product data of the field option.
*
* @param array $stripe_product_info The stripe product data of the field option.
* @return void
*/
public function set_stripe_product_info( $stripe_product_info ) {
if ( ! is_array( $stripe_product_info ) ) {
return;
}

if ( ! isset( $stripe_product_info['product'] ) || ! isset( $stripe_product_info['price'] ) ) {
return;
}

$this->stripe_product_info = $stripe_product_info;
}

/**
* Check if the field option has the option.
*
Expand All @@ -147,6 +179,8 @@ public function has_options() {
return ! empty( $this->options );
}



/**
* Check if the field option has type.
*
Expand All @@ -164,4 +198,13 @@ public function has_type() {
public function has_name() {
return ! empty( $this->field_option_name );
}

/**
* Check if the field option has stripe product data.
*
* @return bool
*/
public function has_stripe_product_info() {
return ! empty( $this->stripe_product_info );
}
}
2 changes: 1 addition & 1 deletion inc/integrations/class-form-providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function register_providers( $new_providers ) {
* @since 2.0.3
*/
public function select_provider_from_form_options( $form_request ) {
$form_options = $form_request->get_form_options();
$form_options = $form_request->get_form_wp_options();
if ( $form_options->has_provider() && $form_options->has_credentials() ) {
return $this->get_provider_handlers( $form_options->get_provider() );
}
Expand Down
40 changes: 40 additions & 0 deletions inc/integrations/class-form-settings-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ class Form_Settings_Data {
*/
private $webhook_id = '';

/**
* The required fields.
*
* @var array
*/
private $required_fields = array();

/**
* The default constructor.
*
Expand Down Expand Up @@ -251,6 +258,9 @@ public static function get_form_setting_from_wordpress_options( $form_option ) {
if ( isset( $form['webhookId'] ) ) {
$integration->set_webhook_id( $form['webhookId'] );
}
if ( isset( $form['requiredFields'] ) && is_array( $form['requiredFields'] ) ) {
$integration->set_required_fields( $form['requiredFields'] );
}
}
}
return $integration;
Expand Down Expand Up @@ -707,4 +717,34 @@ private function set_webhook_id( $webhook_id ) {
}
return $this;
}

/**
* Set the required fields.
*
* @param array $required_fields The required fields.
* @return $this
*/
public function set_required_fields( $required_fields ) {

$this->required_fields = $required_fields;
return $this;
}

/**
* Get the required fields.
*
* @return array
*/
public function get_required_fields() {
return $this->required_fields;
}

/**
* Check if the form has required fields.
*
* @return bool
*/
public function has_required_fields() {
return ! empty( $this->required_fields );
}
}
54 changes: 54 additions & 0 deletions inc/plugins/class-options-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ public function register_settings() {
)
);

register_setting(
'themeisle_blocks_settings',
'themeisle_stripe_public_api_key',
array(
'type' => 'string',
'description' => __( 'Stripe Public API key for the Stripe Field Block.', 'otter-blocks' ),
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'default' => '',
)
);

register_setting(
'themeisle_blocks_settings',
'themeisle_google_captcha_api_site_key',
Expand Down Expand Up @@ -322,6 +334,14 @@ function ( $item ) {
$item['submissionsSaveLocation'] = sanitize_text_field( $item['submissionsSaveLocation'] );
}

if ( isset( $item['requiredFields'] ) ) {
if ( is_array( $item['requiredFields'] ) ) {
$item['requiredFields'] = array_map( 'sanitize_text_field', $item['requiredFields'] );
} else {
$item['requiredFields'] = array();
}
}

return $item;
},
$array
Expand Down Expand Up @@ -397,6 +417,12 @@ function ( $item ) {
'webhookId' => array(
'type' => 'string',
),
'requiredFields' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
),
),
),
),
),
Expand Down Expand Up @@ -436,6 +462,18 @@ function ( $item ) {
$item['options']['maxFilesNumber'] = sanitize_text_field( $item['options']['maxFilesNumber'] );
}

if ( isset( $item['stripe']['product'] ) ) {
$item['stripe']['product'] = sanitize_text_field( $item['stripe']['product'] );
}

if ( isset( $item['stripe']['price'] ) ) {
$item['stripe']['price'] = sanitize_text_field( $item['stripe']['price'] );
}

if ( isset( $item['stripe']['quantity'] ) && ! is_int( $item['stripe']['quantity'] ) ) {
$item['stripe']['quantity'] = sanitize_text_field( $item['stripe']['quantity'] );
}

return $item;
},
$array
Expand Down Expand Up @@ -474,6 +512,22 @@ function ( $item ) {
),
'default' => array(),
),
'stripe' => array(
'type' => 'object',
'properties' => array(
'product' => array(
'type' => 'string',
),
'price' => array(
'type' => 'string',
),
'quantity' => array(
'type' => 'number',
'default' => 1,
),
),

),
),
),
),
Expand Down
Loading