Created
June 23, 2023 20:42
-
-
Save rickalday/b2999d2214b5e6a7dbddf7498d107a9a to your computer and use it in GitHub Desktop.
Include fund in Stripe payment metadata
This file contains 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