backdrop-contrib / stripe

This module provides a simple abstraction to use the Stripe PHP SDK.
GNU General Public License v2.0
2 stars 2 forks source link

Allow a zero payment to skip Stripe checkout #29

Open laryn opened 7 months ago

laryn commented 7 months ago

It would be nice to allow a zero payment to skip the visible aspects of the Stripe checkout (the popup credit card window primarily). This would allow a "pay what you can" model, or custom hook_stripe_checkout_settings_alter code, or probably even webform conditionals, to specify a price OR zero and use the same form for registration.

laryn commented 7 months ago

Related issue: https://www.drupal.org/project/webform_stripe/issues/2711977

laryn commented 7 months ago

@jenlampton I am thinking about merging this and making a new release. Are you okay with that, or do you want to review or test?

yorkshire-pudding commented 3 months ago

@laryn - I gave this patch a test but it seems to result in page not found at this address. /webform/<confirmation> unless I add a redirect to a node.

I also don't get any feedback message, even though the webform now appears in the results table.

laryn commented 3 months ago

@yorkshire-pudding Are you saying it works if you have the confirmation set up as a separate page, but not otherwise?

yorkshire-pudding commented 3 months ago

@laryn - Yes, with custom URL it works, with the other two it goes to that address and gets page not found.

laryn commented 3 months ago

@yorkshire-pudding Clearly I didn't provide enough flexibility on this PR -- are you able to help make it more broadly useful?

yorkshire-pudding commented 3 months ago

I'll have a look tomorrow

yorkshire-pudding commented 3 months ago

Mmm. Been experimenting but I'm not sure on the right approach.

webform uses $form_state['redirect'] which looks like:

$query = array('sid' => $sid);
if ((int) $user->uid === 0) {
  $query['token'] = webform_get_submission_access_token($submission);
}
$redirect = array('node/' . $node->nid . '/done', array('query' => $query));
);

for confirmation

I'm not sure which Backdrop or webform function processes that and NULL for none

This hacky approach appears to work but I don't think it is very elegant and may be quite brittle.

replace:

  // Otherwise, submit the form without getting Stripe involved.
      else {
        webform_client_form_submit($form, $form_state);
        $commands[] = array(
          'command' => 'redirect',
          'url' => $form['#node']->webform['redirect_url'],
        );
      }

with:

    // Otherwise, submit the form without getting Stripe involved.
    else {
      webform_client_form_submit($form, $form_state);

      $redirect_url = $form['#node']->webform['redirect_url'];
      switch ($redirect_url) {
        case '<confirmation>':
          $redirect = $form_state['redirect'];
          $redirect_url = '/' . $redirect[0] . '?sid=' . $redirect[1]['query']['sid'];
          break;
        case '<none>':
          $redirect_url = '/' . $form['#node']->path['alias'];
          break;
        default:
          break;
      }
      $commands[] = array(
        'command' => 'redirect',
        'url' => $redirect_url,
      );
    }

I couldn't figure out how to get the node alias. I also don't know if this will work if webform is in a block.

Hopefully this gives you a bit of inspiration on this. I've ran out of time for now.