Description
Allows users to filter the payment information of the payment element before calling elements.update(). This is useful when altering payment details like currency and amount. For property details, see Stripe documentation for elements.update(options).
NOTE: This filter only applies to the form front-end javascript. You must also implement PHP filters to change values upon submission of the form.
Usage
gform.addFilter( 'gform_stripe_payment_element_updated_payment_information', function( paymentInformation,feedId,formId ){
// do something with the information
return paymentInformation;
} );
Parameters
- $paymentInformation javascript object
The object that contains the updated payment information. - $feedId string
The ID of the feed being processed. - $formId string
The ID of the form being processed.
Example
This example shows how the currency can be changed for Form ID 5.
add_filter( 'gform_currency_pre_save_entry', function ( $currency, $form ) {
if ( rgar( $form, 'id' ) == 5 ) {
return 'EUR';
}
return $currency;
}, 10, 2);
add_filter( 'gform_stripe_charge_pre_create', function ( $charge, $feed, $submission_data, $form, $entry ) {
if ( rgar( $form, 'id' ) == 5 ) {
$charge['currency'] = 'eur';
}
return $charge;
}, 10, 5);
add_action( 'wp_footer', function () {
?>
<script type="text/javascript">
jQuery( document ).ready( function() {
gform.addFilter( 'gform_stripe_payment_element_updated_payment_information', function( paymentInformation, feedId, formId ) {
if ( formID == 5 ) {
paymentInformation.currency = 'eur';
}
return paymentInformation;
} );
});
</script>
<?php
});
Since
This hook was added in Stripe Add-On 5.5.2.
Placement
Reference the article Adding JavaScript Code to the Frontend of Your Site.
Source Code
This action hook is located in js/src/payment-element/stripe-payments-handler.js.