스트라이프 지원을 테스트하고 이야기 한 후, Laravel Cashier에서 사용 된 현재 updateCard()
방법의 문제점을 발견했습니다.
현재 updateCard()
방법을 사용하면 소스 목록에 카드가 추가 된 후 새 카드가 default_source
으로 설정됩니다. 이 방법을 사용하여 카드를 업데이트 할 때 미납 송장이있는 경우 최근 하나, default_source
로 설정되어 있지만 목록에 추가
여러 카드를 가져옵니다이 방법의 결과는이 개 결과를 가지고 (예 : 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();
}