在开始之前,我将使用以下版本:
"laravel/framework": "5.4.*"
"laravel/cashier": "~7.0"
我在我的Vue.js前端上重新获得了Stripe测试令牌,然后将其发送回Laravel API。它正在Stripe中创建一个客户并将stripe_id
保存在我的User表中。但出现以下错误:
message: "Received unknown parameters: object, card, client_ip, created, livemode, type, used"
我将整个令牌发回:
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
这是我到目前为止用来测试其功能的代码:
public function processSubscription(Request $request)
{
$sub = Auth::user()
->newSubscription('main', 'plan_E2xs2LcXXXXXX')
->create($request->token);
return $sub;
}
这是我的前端代码,我认为在创建客户时就可以了:
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
}
)
}
}
答案 0 :(得分:1)
在其他Stripe API方法中使用该令牌时,您只希望传递其id
(在示例代码中为"tok_1E6gkZ2eZvKYlo2CyVJV9hXm"
)而不是整个对象。
您可以看到在the API docs中创建客户时将令牌作为source
传递的示例。