找不到条带功能 [英] Stripe function cannot be found

查看:89
本文介绍了找不到条带功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的angular7应用程序中使用Stripe通过Firebase云功能处理付款.我目前正在尝试创建订阅付款.但是,当我尝试调用以下函数时(作为整个订阅设置的先决条件);

I am using Stripe in my angular7 application to handle payments via firebase cloud functions. I am currently trying to create a subscription payment. However, when I try and call the following function (as a sort of pre-req to the whole subscription setup);

import * as Stripe from 'stripe';
const stripe = new Stripe('pk_test_....');

//Create payment method for customer
const {paymentMethod, createPaymentMethodError} = await stripe.createPaymentMethod({
    type: 'card',
    card: cardElementObj.card,
    billing_details: {
      name: userName,
      email: firebaseUserEmail
    },
  });

错误:

Property 'createPaymentMethod' does not exist on type 'Stripe'.

我在我的node_modules(版本7.14.0)中安装了stripe软件包.

I have the stripe package installed in my node_modules (version 7.14.0).

package.json配置:

package.json config:

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tslint -p tslint.json && tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@types/stripe": "^7.13.11",
    "firebase": "^7.4.0",
    "firebase-admin": "^8.6.0",
    "firebase-functions": "^3.3.0",
    "moment": "^2.24.0",
    "stripe": "^7.14.0"
  },
  "devDependencies": {
    "@types/stripe-checkout": "^1.0.3",
    "@types/stripe-v3": "^3.1.9",
    "firebase-functions-test": "^0.1.6",
    "tslint": "^5.12.0",
    "typescript": "^3.2.2"
  },
  "private": true
}

感谢您的帮助!预先感谢.

Any help is appreciated! Thanks in advance.

推荐答案

Stripe不提供Typescript程序包,因此您不需要package.json中的那些依赖项即可使其正常工作.相反:

Stripe doesn't provide a Typescript package, so you don't need those dependencies in your package.json to get it working. Instead:

首先,确保页面上包含脚本.请注意,根据其文档,必须始终从 https://js.stripe.com/v3/.

First, make sure you have the script included on the page. Note that according to their documentation, it must always be loaded from https://js.stripe.com/v3/.

然后,Typescript代码的结构应类似于这样,以获取要使用的Stripe实例.

Then, the Typescript code should be structured like so to get an instance of Stripe to use.

declare var Stripe : any;

@Component({
  selector    : 'payment-form',
  templateUrl : 'payment-form.component.html',
})
export class PaymentFormComponent implements OnInit {
  stripe: any;

  ngOnInit() {
    this.stripe = new Stripe(environment.stripeApiKey);
  }

  mySubmitFunction() {
    this.stripe.createPaymentMethod(...);
  }
}

在Typescript中使用Javascript库时,这种在组件定义之外声明变量的常规结构很常见.例如,在使用Facebook或Google OAuth库时,您必须遵循类似的步骤.

This general structure of declaring the variable outside of the component definition is common when using Javascript libraries in Typescript. You'll have to follow similar steps when using the Facebook or Google OAuth libraries, for example.

这篇关于找不到条带功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆