Get Stripe payment amount from webform field value

Created on 5 April 2025, about 1 month ago

Problem/Motivation

Set custom amount from webform field value

Steps to reproduce

I want to set the custom payment amount in the Stripe Payment Options to the value of a webform field.

Is there a way to do this?

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Active

Version

1.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States akramer603

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @akramer603
  • πŸ‡ΈπŸ‡ΎSyria hodba Dubai

    You can set the amount as a token from the field that you need to set the value from. For this to work, you need to put the stripe payment field in a separate page. Otherwise, you need to using the webform hook_alter to trigger an ajax callback to update the amount value on the Stripe element.

  • πŸ‡ΊπŸ‡ΈUnited States akramer603

    I put the stripe payment option on a separate page.
    I tried putting a token in the Amount field in the stripe payment options. I used [webform:element:donation_amount:title], this may not be correct but it is the field I want. Upon saving I got the error "The price amount or currency is not defined, please correct this and try again." When I test the form I get "Oops, something went wrong. Check your browser's developer console for more details." The developer console says there was an ajax error.

    Is there documentation or examples for setting this up? Thanks

  • πŸ‡ΊπŸ‡ΈUnited States akramer603

    I got it to pass the webform field for the transaction amount by using the correct token :)

    This works: [webform_submission:values:donation_amount] (it does still product the error when saving the field but it does work)

    I feel like there should be a way to get the contact fields for the billing information from form fields that are already filled out.

  • πŸ‡ΈπŸ‡ΎSyria hodba Dubai

    Can you please share the error that you see.

  • πŸ‡ΊπŸ‡ΈUnited States imrodmartin

    Hi,
    I'm working on the same kind of project and I'm getting an error (not sure if it's the same)

    I have the Stripe Payment field on the 2nd page.
    The field token I'm passing is from a computed twig field that combines two numbers from the 1st page. (confirm_amount)

    I've tried 2 things:
    Just the one amount from the first page: [webform_submission:values:amount]
    and the computed amount :[webform_submission:values:confirm_amount]

    both fail with the following error
    TypeError: Drupal\stripe_webform_payment\Plugin\WebformElement\StripeWebformPayment::updateNestedValues(): Argument #3 ($paymentIntentId) must be of type string, null given, called in ✱✱✱/modules/contrib/stripe_webform_payment/src/Plugin/WebformElement/StripeWebformPayment.php on line 233 in Drupal\stripe_webform_payment\Plugin\WebformElement\StripeWebformPayment->updateNestedValues() (line 478 of modules/contrib/stripe_webform_payment/src/Plugin/WebformElement/StripeWebformPayment.php).

    Also - I'm seeing the same behavior - whenever I save the form I get the error message when using Custom Payments:
    Error message
    Error fetching Stripe products: -

    any help would be so much appreciated. (I'll be happy to do a video on it on my channel once I get it working!)

Production build 0.71.5 2024