duanhao8540 2019-06-18 10:27
浏览 9
已采纳

如何从条带Api获取和存储最近两个月的余额交易

I am trying to fetch last 2 months transaction lists which has more than 2000 records from stripe API.

I used following code which only fetch 3 days records.

    $balance = $this->stripelib->getBalanceTransaction()->all(
        array(
                'limit'   => 100,
                'created' => array(
                    'gte' => strtotime('-2 month'), 
                    'lte' => strtotime('1 day') 
                )
            )
        );


    foreach ($balance->data as $bl){}
    $this->addStripeRecord($balance->data);

    while ($balance->has_more){

        $balance = $this->stripelib->getBalanceTransaction()->all(
        array(
            "limit" => 100,
            "created" => array(
                "gte" => strtotime('-2 month'),
                'lte' => strtotime('1 day')
                ), 
            "starting_after" => $bl->id)
        );

        foreach ($balance->data as $bl){}

please help me to solve this issue

  • 写回答

1条回答 默认 最新

  • douba1498 2019-06-18 10:56
    关注

    I'd recommend using Stripe's official PHP library and its support for auto-pagination. [0]

    $transactions = \Stripe\BalanceTransaction::all([
      "created" => [
        "gte" => strtotime('-2 month'),
        "lte" => strtotime('1 day')
      ]
    ]);
    foreach ($transactions->autoPagingIterator() as $transaction) {
      // Do something with $transaction
      print_r($transaction->id . " : " . date("Y-m-d\TH:i:s\Z", $transaction->created) . "
    ");
    }
    

    https://stripe.com/docs/api/pagination/auto?lang=php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 双目摄像头标定后的校准文件
  • ¥15 从键盘输入不管多少字符或者数组 输出的时候先提示输出再显示结果 输出的时候字符间间隔一个空格符
  • ¥15 powerbi举证增加度量值后出现对应关系错乱
  • ¥30 频率分析法分析绘制奈奎斯特图、波特图
  • ¥15 弹出来一万个系统找不到指定的文件框框,怎么解决
  • ¥15 ADS生成的微带线为什么是蓝色空心的
  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位