Nest.js Stripe 設定

created 2021/10/03updated 2021/10/03
js
import { Injectable } from '@nestjs/common'; import Stripe from 'stripe'; import { ConfigService } from '@nestjs/config'; @Injectable() export class StripeService { private stripe: Stripe; constructor(private readonly configService: ConfigService) { this.stripe = new Stripe(configService.get('STRIPE_SECRET_KEY'), { apiVersion: '2020-08-27', }); } async createCustomer(email: string): Promise<string | null> { const customer = await this.stripe.customers.create({ email: email, }); return customer?.id; } }