如何按键分组条纹费用

问题描述 投票:0回答:1

我正在寻找创建捐赠网站,其中金额将按团队分组。我试图通过Stripe获得所有费用,然后将它们分组。我怎样才能获得每个团队捐赠的总金额?

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
                }

            }
        }


    }
}
php multidimensional-array stripe-payments
1个回答
0
投票

我发现了怎么样!

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']){
                $oldvalue = $v['amount'];
                $newvalue = $oldvalue+$charge->amount;
                unset($teams[$k]);
                array_push($teams, array( 'team'=> $charge->metadata['team'], 'amount' => $newvalue) );
            }

        }
    }


}

}

© www.soinside.com 2019 - 2024. All rights reserved.