-
Notifications
You must be signed in to change notification settings - Fork 35
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 temporary saving for form submissions #1769
Conversation
Bundle Size Diff
|
Plugin build for 4227cac is ready 🛎️!
|
E2E SummaryTyping
Values above 60ms"4 - 156.98, 12 - 62.45" |
/** | ||
* In this function we add a script that will activate the temporary save mode. | ||
* This will be for the Pro users. This will be removed in the future and moved to the Pro plugin. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this, can't we just do it based on if Stripe block exists in the form content area?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can. This is a placeholder for testing.
inc/server/class-form-server.php
Outdated
register_rest_route( | ||
$namespace, | ||
'/form/confirm', | ||
array( | ||
array( | ||
'methods' => WP_REST_Server::READABLE, | ||
'callback' => array( $this, 'confirm_form' ), | ||
'permission_callback' => function ( $request ) { | ||
return __return_true(); | ||
}, | ||
'args' => array( | ||
'record_id' => array( | ||
'validate_callback' => function( $param, $request, $key ) { | ||
return is_numeric( $param ); | ||
}, | ||
), | ||
), | ||
), | ||
) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is to confirm the submission, why is it a GET request with an open permission callback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For fast testing. I was thinking of adding a license check; what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Soare-Robert-Daniel I'm not sure it's a good idea to send the license from frontend for validation, we expose the license that way to visitors. Maybe we can create a nonce for that particular form submission and send it with Stripe request, along side checkout ID, and validate it with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By license verification, I meant at the server level. To be a PRO-only feature. I will add a dynamic nonce generation.
'permission_callback' => function ( $request ) { | ||
$session = $request->get_param( 'session' ); | ||
|
||
if ( apply_filters( 'otter_form_session_confirmation', $session ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this step, we can verify the session id. The session can be a Stripe ID or something custom.
*/ | ||
public function verify_confirmation_session( $session ) { | ||
// TODO: Add verification for Stripe session when adding the stripe field. | ||
return 'test_123' === $session; // Test ONLY. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here will add the Stripe verification process when we check if the given session is still valid.
$form_data->metadata['frontend_external_confirmation_url'] = add_query_arg( | ||
array( | ||
'record_id' => $form_data->metadata['record_id'], // TODO: Test ONLY. This will will be extracted from Stripe payment intent metadata. | ||
'session' => 'test_123', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this step, we will create the session and save the record_id
in its metadata.
Closes #1766 .
This will serve as infrastructure for #1778
Summary
Now we can temporarily save a Form submission. When temporary save means:
ℹ️ A form request that needs to be saved temporarily is marked by a special HTTP header called
O-Form-Save-Mode
which values must betemporary
.ℹ️ Temporary saving is done via a special flag. It is opt-in, which means when someone implements a filter for Form need to consider this case via
is_temporary_data
function of$form_data
.The state of this temporary save is shown as
draft
in Form Submissions.Another API route has been implemented, whose job is to confirm the submission. When confirmed, the form data will be pulled from the database and sent to the processing.
ℹ️ When sent to re-reprocessing, a flag to mark this behavior is set via
is_duplicated
function of$form_data
. This is also an opt-in.For Stripe addon, we want the following workflow:
Screenshots
Loading state when confirming the submission.
Test instructions
WP_DEBUG
set totrue
and Otter Pro activated.This test will be done via Console since it is a work of an infrastructure for a future feature.
activateTempSave()
, then press Enter. With this, the form will save the data as temporary.?record_id=123
. Also, you will see a confirmation message likeSuccess
.With temporary saving, the final confirmation will be done on the page with the enhanced URL, which means you reached the last step.
Checklist before the final review