I'm looking to create a Donation Website where the amounts would be grouped by team. I'm trying to get all charges via Stripe and then group them. How could I get the total amount donated for each team ?
function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
function TheMainFunction(){
\Stripe\Stripe::setApiKey("KEY");
$charges = \Stripe\Charge::all();
$teams = array();
foreach($charges->data as $charge) if(isset($charge->metadata['team']) ){
if( !in_array_r($charge->metadata['team'], $teams ) ){
array_push($teams, array( 'team'=> $charge->metadata['team'], 'amount' => $charge->amount) );
}
else{
foreach( $teams as $k => $v ){
if( $v['team'] == $charge->metadata['team']){
// The action should be done here
}
}
}
}
}