简体   繁体   English

Stripe V3 RedirectToCheckout 定义

[英]Stripe V3 RedirectToCheckout Definition

I am trying to execute a client side only Stripe checkout in my Angular 8 project.我正在尝试在我的 Angular 8 项目中执行仅客户端的 Stripe 结帐。 I've installed the @type/stripe-v3 file, but the definition for StripeClientCheckoutOptions is different compared to all of the documentation on Stripe's site ( https://stripe.com/docs/js/checkout/redirect_to_checkout ).我已经安装了 @type/stripe-v3 文件,但是 StripeClientCheckoutOptions 的定义与 Stripe 网站上的所有文档( https://stripe.com/docs/js/checkout/redirect_to_checkout )不同。 Specifically the typed library is missing "lineItems" and "mode" which is causing errors in my Angular project on build when I take the generated checkout snippet.具体来说,类型库缺少“lineItems”和“mode”,当我使用生成的结帐片段时,这会导致我的 Angular 项目在构建时出现错误。 Is this just a case of not up to date type library?这只是类型库不是最新的情况吗?

在此处输入图像描述

在此处输入图像描述

Is this just a case of not up to date type library?这只是类型库不是最新的情况吗?

Yes, the DefinitelyTyped type definitions for Stripe.js do look to be out of date, as you can see here:是的,Stripe.js 的 DefinitiveTyped 类型定义看起来确实已经过时了,你可以在这里看到:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/stripe-v3/index.d.ts#L124-L132 https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/stripe-v3/index.d.ts#L124-L132

As a temporary measure you can use @ts-ignore and the code should compile and run fine.作为临时措施,您可以使用@ts-ignore并且代码应该可以正常编译和运行。 But, a better longer-term solution would be to use Stripe's new npm module for loading Stripe.js which includes type definitions of its own:但是,更好的长期解决方案是使用 Stripe 的新 npm 模块来加载 Stripe.js,其中包括自己的类型定义:

https://github.com/stripe/stripe-js https://github.com/stripe/stripe-js

The type definitions for redirectToCheckout in @stripe/stripe-js are up to date, and will continue to be since the library is maintained by Stripe: @stripe/stripe-jsredirectToCheckout的类型定义是最新的,并且将继续保持,因为该库由 Stripe 维护:

https://github.com/stripe/stripe-js/blob/master/types/stripe-js/checkout.d.ts https://github.com/stripe/stripe-js/blob/master/types/stripe-js/checkout.d.ts

If you use @stripe/stripe-js you don't have to include the Stripe.js <script> tag in your HTML anymore.如果您使用@stripe/stripe-js ,则不必再在 HTML 中包含 Stripe.js <script>标签。 All you need to do is import the module, and call the loadStripe function:您需要做的就是导入模块,然后调用loadStripe function:

import {loadStripe} from '@stripe/stripe-js';

const stripe = await loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx');

This will include Stripe.js, and produce a stripe instance with all the latest types.这将包括 Stripe.js,并生成一个包含所有最新类型的stripe实例。 The library also handles server side rendering environments gracefully without any additional configuration.该库还可以优雅地处理服务器端渲染环境,无需任何额外配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM