Forked from rickalday/give_include_fund_payment_meta.php
Created
June 5, 2025 00:47
-
-
Save gspice/dc3ebb2d3d3426b3d797f83714ad1db0 to your computer and use it in GitHub Desktop.
Include fund in Stripe payment metadata - Option-based forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use GiveFunds\Models\Fund; | |
use GiveFunds\Repositories\Funds; | |
use GiveFunds\Repositories\Revenue; | |
function give_include_fund_payment_meta( $charge_args ) { | |
if ( ! defined( 'GIVE_FUNDS_ADDON_VERSION' )) { | |
return; | |
} | |
/* @var Funds $fundRepository */ | |
$fundRepository = give( Funds::class ); | |
$revenueRepository = give( Revenue::class ); | |
// Sanitize the input posted data to the form. | |
$posted_data = give_clean( filter_input_array( INPUT_POST ) ); | |
$fundId = $posted_data['give-selected-fund']; | |
$fund = ( $fundId ) ? $fundRepository->getFund( $fundId ) : $fundRepository->getDefaultFund(); | |
$fundTitle = $fund->getTitle(); | |
// Prepare metadata fields list. | |
$custom_meta_fields = array( | |
'Fund' => $fundTitle, | |
); | |
$charge_args['metadata'] = array_merge( $charge_args['metadata'], $custom_meta_fields ); | |
return $charge_args; | |
} | |
add_filter( 'give_stripe_create_intent_args', 'give_include_fund_payment_meta', 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment