首页 > 解决方案 > 从 Gatsby React 中的脚本通过 Stripe API 创建新的 SKU

问题描述

我想通过条带 API 创建一个新的 SKU。但是,Stripe API 似乎不支持 Gatsby:https ://stripe.com/docs/api/skus/create?lang=node - “最接近”的东西是 Node.js --- 这不是甚至接近盖茨比。

我尝试过处理和粘贴代码的 Node.js 版本,但我相信它会破坏 Gatsby 编译过程,因为它使用的是 Node.js 语法——这在我的 React/Gatsby 语法中是不允许的。

        var stripe = require("stripe")("sk_secret_key");

        stripe.skus.create({
          product: '200',
          attributes: {size: 'Medium', gender: 'Unisex'},
          price: 1500,
          currency: 'usd',
          inventory: {type: 'finite', quantity: 500}
        }, function(err, sku) {
          // asynchronously called
        });     

这根本不编译。

在 Stripe 中创建 SKU 是否与 Gatsby 100% 不兼容?还是有更好的方法来解决这个问题?

标签: reactjsstripe-paymentsgatsby

解决方案


推荐阅读