【问题标题】:Ionic 2 with Stripe Integration带条纹集成的 Ionic 2
【发布时间】:2016-08-31 19:25:57
【问题描述】:

我对 Ionic 整体有点陌生,我现在正在使用 Ionic 2。我做到了:

npm install stripe

然后我将条带模块放入 node_modules 文件夹。这是我在支付页面中访问 Stripe 的代码:

'use strict';
declare var require: any;
var Stripe = require('stripe')('API_KEY');

当我调用如下函数时:

Stripe.tokens.create({
  card: {
    "number": '4242424242424242',
    "exp_month": 12,
    "exp_year": 2017,
    "cvc": '123'
  }
}, function(err, token) {
  // asynchronously called
  console.log("error: " + err);
  console.log("token: " + token);
});

我得到这个错误:

TypeError: exec is not a function

exec 在这一行的 stripe.js 中:

var exec = require('child_process').exec;

我不知道如何解决它,任何人有任何指针或可能有不同(正确)的方式将 Stripe 与 Ionic 2 集成?谢谢!!

【问题讨论】:

    标签: typescript ionic-framework stripe-payments ionic2


    【解决方案1】:

    首先,您需要区分客户端(离子应用)和服务器端(处理付款和验证卡的位置)。

    例如,this template contains the full source code for Ionic2 with Stripe

    正如我从文档中看到的,您只需要将 Ionic 应用中的 HTTP post 调用发送到服务器。

    您可以将其发送到集成了 Stripe 的已托管服务器(例如 Stripe Payments Kit / NoodlioPay),也可以设置您自己的服务器(如您所愿)。查看我发送的 link 的文档以了解如何操作。

    【讨论】:

      【解决方案2】:

      无论如何,我都不是 Ionic 专家,但我猜您正在尝试使用 Stripe.js [1](客户端库)来执行服务器端请求。如果您要进行标记化,您应该尝试按照 Stripe.js 文档中概述的说明进行操作,或者完全删除 Stripe.js 并仅使用 Node.js [2] 绑定来实现您的代码。

      [1]https://stripe.com/docs/stripe.js

      [2]https://github.com/stripe/stripe-node

      【讨论】:

        猜你喜欢
        • 2019-02-15
        • 2017-10-26
        • 2018-11-26
        • 2019-01-02
        • 2017-10-13
        • 2021-04-16
        • 2020-05-23
        • 2016-12-31
        • 2020-12-13
        相关资源
        最近更新 更多