@gerulisss I imagine the issue is with your $plan->stripePlan property given you don’t show us how or where that’s defined.
Sep 5, 2021
9
Level 1
Laravel cashier The resource ID cannot be null or whitespace
Hello, I wanted to ask, when integrating stripe, when entering card data, an error is received: The resource ID cannot be null or whitespace?
public function create(Request $request, Plan $plan) { $plan = Plan::findOrFail($request->get('plan'));
$user = $request->user();
$paymentMethod = $request->paymentMethod;
$user->createOrGetStripeCustomer();
$user->updateDefaultPaymentMethod($paymentMethod);
$user->newSubscription('default', $plan->stripe_plan)
->create($paymentMethod, [
'email' => $user->email,
]);
return redirect()->route('home')->with('success', 'Your plan subscribed successfully');
}
blade: @extends('layouts.app') @section('content')
You will be charged ${{ number_format($plan->cost, 2) }} for {{ $plan->name }} Plan
@csrf Enter your credit card information Pay @endsection @section('scripts') // Custom styling can be passed to options when creating an Element. // (Note that this demo uses a wider set of styles than the guide below.) var style = { base: { color: '#32325d', lineHeight: '18px', fontFamily: '"Helvetica Neue", Helvetica, sans-serif', fontSmoothing: 'antialiased', fontSize: '16px', '::placeholder': { color: '#aab7c4' } }, invalid: { color: '#fa755a', iconColor: '#fa755a' } }; const stripe = Stripe('{{ env("STRIPE_KEY") }}', { locale: 'en' }); // Create a Stripe client.
const elements = stripe.elements(); // Create an instance of Elements.
const cardElement = elements.create('card', { style: style }); // Create an instance of the card Element.
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;
cardElement.mount('#card-element'); // Add an instance of the card Element into the `card-element` <div>.
// Handle real-time validation errors from the card Element.
cardElement.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
// Handle form submission.
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
stripe
.handleCardSetup(clientSecret, cardElement, {
payment_method_data: {
//billing_details: { name: cardHolderName.value }
}
})
.then(function(result) {
console.log(result);
if (result.error) {
// Inform the user if there was an error.
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
console.log(result);
// Send the token to your server.
stripeTokenHandler(result.setupIntent.payment_method);
}
});
});
// Submit the form with the token ID.
function stripeTokenHandler(paymentMethod) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'paymentMethod');
hiddenInput.setAttribute('value', paymentMethod);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
</script>
Please or to participate in this conversation.