2017-01-02 6 views
1

나는 Cashier와 Laravel 5.3을 사용하고 있습니다. 고객이 카드 세부 정보를 업데이트 한 경우 보류중인 인보이스가 있는지 확인하고 Stripe에게 새 카드의 요금을 다시 청구하도록 요청할 수 있습니까? 현재 스트라이프 대시 보드에서 시도에 대한 설정을 지정했습니다. 그러나 내가 이해하는 바에 따르면 스트라이프는 카드 세부 정보를 업데이트하고 다시 시도 할 다음 시도 날짜를 기다리는 고객에게 자동으로 요금을 청구하지 않습니다. 그래서 카드를 업데이트하자마자 보류중인 인보이스에 수동으로 고객에게 청구하려고합니다. 나는 Cashier 문서와 Github 페이지를 읽었으나이 사례는 여기에서 다루지 않습니다.Laravel Cashier 카드 업데이트 후 송장 보류 중 재 처리 시도

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

누군가 나를 도와 줄 수 있습니까?

답변

0

스트라이프 지원을 테스트하고 이야기 한 후, Laravel Cashier에서 사용 된 현재 updateCard() 방법의 문제점을 발견했습니다.

현재 updateCard() 방법을 사용하면 소스 목록에 카드가 추가 된 후 새 카드가 default_source으로 설정됩니다. 이 방법을 사용하여 카드를 업데이트 할 때 미납 송장이있는 경우 최근 하나, default_source

  • 로 설정되어 있지만 목록에 추가

    1. 여러 카드를 가져옵니다이 방법의 결과는이 개 결과를 가지고 (예 : past_due 상태의 인보이스) 자동 청구되지 않습니다. 스트라이프 다시 시도 할 past_due 상태에있는 모든 청구서에 고객의 충전을 위해

  • source 매개 변수를 전달해야합니다.

    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(); 
        } 
    

    나는 Pull request 만든이 첨가 : 그래서 이런 새로운 방법 뭔가를 만들었습니다. Billable 파일을 직접 변경하면 변경 사항을 적용하지 않는 것이 좋지 않으므로 계산원에 추가하지 않으면 컨트롤러 파일에서 다음과 같이 직접 사용할 수 있습니다.

    $user = Auth::User(); 
    
    $customer = $user->asStripeCustomer(); 
    $token = StripeToken::retrieve($token, ['api_key' => config('services.stripe.secret')]); 
    
    if (!($token->card->id === $customer->default_source)) { 
        $customer->source = $token; 
        $customer->save(); 
        // Next synchronise user's card details and update the database 
        $user->updateCardFromStripe(); 
    }