首页 > 解决方案 > VUE (Cli) 和带 Node js 的 Stripe

问题描述

VUE 中的 Stripe 存在以下问题:

(Stripe 是通过“npm Install Stripe”(stripe-node)安装的)

在我的组件中,我使用以下命令初始化 Stripe:

import Stripe from 'stripe

在方法中我有一个测试功能:

<template>
 <v-btn 
      type="submit" 
      class="mt-3 success"
      @click="test"
    >
      Test
  </v-btn>
</template>

<script>
import  { db } from "@/plugins/firebase"
import store from '@/store';
import Stripe from 'stripe'

export default {
name: "MMKonfiguration",

data(){
/* some other vars....*/
}

methods:{
async test(){
        const stripe = new Stripe('SecretStripeKey_here')
        const customer = await stripe.customers.create({
            email: 'customer@example.com'
        });

        console.log(customer.id);
}
}
</script>
console.log(stripe)

给我一个成功的对象

然而,任何 Stripe 函数都不会被执行(在这种情况下是 stripe.customers.create),而且例如 stripe.products.retrieve 也不起作用

有谁知道任何建议?非常感谢

标签: vue.jsstripe-payments

解决方案


stripe-node库是一个服务器端库,它并不打算在这样的客户端应用程序中运行。如果您在客户端应用程序中包含您的密钥,它可以被记录并且不再安全。您应该立即删除它并滚动您的密钥

与支付详细信息收集相关的客户端方面应使用Stripe.js。您可以使用包中的loadStripe帮助程序@stripe/stripe-js以对模块友好的方式包含 Stripe.js。


推荐阅读