Before we start I'm using these versions:
"laravel/framework": "5.4.*"
"laravel/cashier": "~7.0"
I'm getting the Stripe test token back in on my Vue.js front-end fine then sending it back to the Laravel API. It's creating a customer in Stripe and saving the stripe_id
on my User table. But I'm getting the following error:
message: "Received unknown parameters: object, card, client_ip, created, livemode, type, used"
I'm sending the whole token back:
card: {id: "card_1E6gkZ2eZvKYlo2CkU7Xebko", object: "card", address_city: null, address_country: null, address_line1: null, …}
client_ip: "5.64.000.00"
created: 1550852387
id: "tok_1E6gkZ2eZvKYlo2CyVJV9hXm"
livemode: false
object: "token"
type: "card"
used: false
This is the code I'm using so far to test it's working:
public function processSubscription(Request $request)
{
$sub = Auth::user()
->newSubscription('main', 'plan_E2xs2LcXXXXXX')
->create($request->token);
return $sub;
}
This is my front-end code, which I presume is OK as it's creating a customer:
methods: {
getToken() {
this.processing = true
createToken().then(data => {
console.log(data.token)
this.processSubscription(data.token)
})
},
processSubscription(token) {
this.$axios.put('account/subscribe', {
token: token
}).then(response => {
console.log(response)
this.processing = false
}, error => {
console.log(error)
this.processing = false
}
)
}
}
When using that token in other Stripe API methods, you want to just pass its id
(in your example code, that's "tok_1E6gkZ2eZvKYlo2CyVJV9hXm"
) rather than the entire object.
You can see an example of passing the token as source
when creating a customer in the API docs.