Passing the payment amount to one-time payment forms

What is the use case?

Imagine a one-time payment form where the payment amount can be entered by the client.

If you’d like to set the initial payment amount by passing an URL parameter, like on the screenshot below, then this article is for you:



How to implement it?

If you’d like to set the initial payment amount of your one-time payment form via an URL parameter, then you have to do the following:

  1. Set the “Payment Type” option to “Custom Amount” on the “Payment” tab of the form.
  2. Enable "Allow setting form fields via URL parameters" on Full Pay -> Settings -> Forms
  3. Pass the payment amount in the wpfsAmount URL parameter.
  4. Implement a Wordpress filter that processes the URL parameter. 

    (Default implementation provided below)

The following subsections explain these steps in detail.

1) Set the “Payment Type” option to “Custom Amount”

You can set the “Payment Type” option to “User defined amount” on the “Payment” tab of the form:

2) Pass amount in the wpfsAmount URL parameter

You have to pass the payment amount in the wpfsAmount parameter:

https://ExampleDomain.local/one-time-payment-form/?wpfsAmount=7040

The payment amount must be specified the smallest unit for the currency. 

For $10.00 enter 1000, for ¥10 enter 10.

3) Implement a Wordpress filter to process the URL parameter

For the sake of security, the plugin doesn’t let anyone set the payment amount without your consent.

You can give consent by implementing a short piece of code to approve the amount in the form of a WordPress filter. The code needs to be added to the functions.php file of your active Wordpress theme.

This is the default implementation:

<?php 
/**
 * Default implementation of the 'fullstripe_set_custom_amount' Wordpress filter 
 * for WP Full Stripe.
 *
 * @param $customAmount Payment amount set by a previous filter instance
 * @param $formName Name of the form that triggered the filter
 * @param $customAmountParamValue The value of the wpfsAmount 
 *
 * @return integer The initial payment amount to be set on form $formName
 */

function set_custom_amount($customAmount, $formName, $customAmountParamValue) {
 	return $customAmountParamValue;
}

add_action('fullstripe_set_custom_amount', 'set_custom_amount', 10, 3);

You can customize the code depending on your needs. For example, you can limit the payment amount based on form name and amount range:


/**
 * Custom implementation of the 'fullstripe_set_custom_amount' Wordpress filter
 * for WP Full Stripe.
 * Sets the initial payment amount if the form name is 'paymentCustom' and the 
 * passed amount is in the [$10.00 .. $50.00] range.
 *
 * @param $customAmount Payment amount set by a previous filter instance
 * @param $formName Name of the form that triggered the filter
 * @param $customAmountParamValue The value of the wpfsAmount 
 *
 * @return integer The initial payment amount to be set on form $formName
 */

function set_custom_amount($customAmount, $formName, $customAmountParamValue) {
    $customAmount = 0;

    if ( $formName === 'paymentCustom' &&
         ( 1000 <= $customAmountParamValue && $customAmountParamValue < 5000 ) ) {
        $customAmount = $customAmountParamValue;
    }
    
    return $customAmount;
}

add_action('fullstripe_set_custom_amount', 'set_custom_amount', 10, 3);
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us