Вот код компонента:
< pre class="lang-php Prettyprint-override">
Код: Выделить всё
namespace App\Http\Livewire;
use Livewire\Component;
class PaymentMethod extends Component
{
public function addPaymentMethod($paymentMethod){
auth()->user()->addPaymentMethod($paymentMethod);
}
public function render()
{
return view('livewire.payment-method', [
'intent' => auth()->user()->createSetupIntent()
]);
}
}
Код: Выделить всё
const cardHolderName = document.getElementById('card-holder-name');
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;
cardButton.addEventListener('click', async (e) => {
const {
setupIntent,
error
} = await stripe.confirmCardSetup(
clientSecret, {
payment_method: {
card: cardElement,
billing_details: {
name: cardHolderName.value
}
}
}
);
if (error) {
// Handle error
} else {
console.log(setupIntent.payment_method);
@this.addPaymentMethod(setupIntent.payment_method);
}
});
Код: Выделить всё
@this.addPaymentMethod(setupIntent.payment_method);
billings:187 Uncaught (в обещании) TypeError: Cannot читать свойства
неопределенного объекта (читая «найти») в HTMLButtonElement.
(billings:187:33)
Когда я проверяю детали, это показывает мне это. Я проверил: свойство setupIntent.pay_method возвращает правильное значение. Я изучал это, но мне нужна помощь в поиске источника моей ошибки. Кто-нибудь может помочь?
Подробнее здесь: https://stackoverflow.com/questions/783 ... -component
Мобильная версия