2017-01-02 5 views
1

私はLashvel 5.3をキャッシャーと共に使用しています。お客様がカードの詳細を更新した場合、保留中の請求書があるかどうかを確認し、Stripeに新しいカードの請求を再試行するように頼むことができますか?現時点では、ストライプダッシュボードで試行の設定を行っています。しかし、私が理解するところでは、Stripeはカードの詳細を更新した場合に自動的に顧客に請求することはしませんし、次回の試行日をもう一度試すのを待っています。それで、私はカードを更新するとすぐに保留中の請求書に顧客に請求することを手動で試みたいのです。私はキャッシャーの文書とGithubのページを読んだが、このケースはそこでは扱われていない。Laravel Cashierカードの更新後に保留中の請求書を再試行します

$user->updateCard($token); 
// Next charge customer if there is a pending invoice 

誰かが私を助けてくれますか?

答えて

0

ストライプサポートをテストして話した後、Laravel Cashierで使用されている現在のupdateCard()メソッドの問題を発見しました。

現在のupdateCard()メソッドでは、カードが送信元リストに追加され、新しいカードがdefault_sourceとして設定されます。この方法の結果は、2つの成果ました:このメソッドを使用してカードを更新するときに未払いの請求書がある場合は、最近の一つは、default_source

  • として設定されているが、

    1. 複数のカードがリストに追加されます(すなわち、past_due状態の請求書)、自動的に請求されることはありません。

    past_due状態にあるすべての請求書の再試行充電顧客にストライプのためには、sourceパラメータが渡される必要があります。私は、この追加のためのPull requestを作成している

    public function replaceCard($token) 
        { 
         $customer = $this->asStripeCustomer(); 
         $token = StripeToken::retrieve($token, ['api_key' => $this->getStripeKey()]); 
         // If the given token already has the card as their default source, we can just 
         // bail out of the method now. We don't need to keep adding the same card to 
         // a model's account every time we go through this particular method call. 
         if ($token->card->id === $customer->default_source) { 
          return; 
         } 
         // Just pass `source: tok_xxx` in order for the previous default source 
         // to be deleted and any unpaid invoices to be retried 
         $customer->source = $token; 
         $customer->save(); 
         // Next we will get the default source for this model so we can update the last 
         // four digits and the card brand on the record in the database. This allows 
         // us to display the information on the front-end when updating the cards. 
         $source = $customer->default_source 
            ? $customer->sources->retrieve($customer->default_source) 
            : null; 
         $this->fillCardDetails($source); 
         $this->save(); 
        } 
    

    :だから私は、新しい方法にこのようなものを作成しました。 Billableファイルを直接変更することはお勧めできません。キャッシャーに追加してもらえない場合は、コントローラーファイルで次のように使用してください。

    ​​
  • 関連する問題