Today, I want to integrate Cashier/Stripe into Laravel.
I have created to plans: basic and premium.
Basic with trail period and premium with no trail period.
The request of the basic package is successful but the premium is unsuccessful. I get the following error.
InvalidRequest in ApiRequestor.php line 98:
This customer has no attached payment source
at ApiRequestor->handleApiError('{ "error": { "type": "invalid_request_error", "message": "This customer has no attached payment source" } } ', '400', array('Server' => 'nginx', 'Date' => 'Mon, 17 Aug 2015 20:06:43 GMT', 'Content-Type' => 'application/json', 'Content-Length' => '120', 'Connection' => 'keep-alive', 'Access-Control-Allow-Credentials' => 'true', 'Access-Control-Allow-Methods' => 'GET, POST, HEAD, OPTIONS, DELETE', 'Access-Control-Allow-Origin' => '*', 'Access-Control-Max-Age' => '300', 'Cache-Control' => 'no-cache, no-store', 'Request-Id' => 'req_6oWwzseRdGbsQW', 'Stripe-Version' => '2015-08-07'), array('error' => array('type' => 'invalid_request_error', 'message' => 'This customer has no attached payment source'))) in ApiRequestor.php line 210
After some searching on the internet I see a post what says that the customer first need to have a creditcard. When I check the customer in stripe the customer didn't have any creditcards attached. That is the reason why it doesn't work.
In the view I add the following code:
<form action="/payment" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_o9JyNbaftcr3ueztXphHXDR9"
data-amount="2000"
data-name="Demo Site"
data-description="2 widgets ($20.00)"
data-image="/128x128.png">
</script>
</form>
But when I enter the form I supply the test creditcard information (4242 4242 4242 4242). Does somebody know why the Stripe form doesn't create the card information?
Controller:
public function handle(PostPayment $payment)
{
$user = User::find(Auth::user()->id);
$user->subscription('premium')->create($payment->get('creditCardToken'));
return 'done';
}
Does somebody has a idea why it doesn't work?
Thank you already if you take a look at this.