2016-08-31 111 views
2

我對整體Ionic很感興趣,現在我正在使用Ionic 2。我做了:帶條紋集成的離子2

npm install stripe 

我把條紋模塊放到了node_modules文件夾中。這是我在我的付款頁面代碼訪問條紋:

'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集成的方式不同(正確)?謝謝!!

回答

2

首先,需要在客戶端側(離子應用程序)和服務器側(其中付款處理和驗證卡之間進行區分)。例如,this template contains the full source code for Ionic2 with Stripe

正如我從文檔中讀到的,您只需在您的Ionic應用程序中向服務器發送HTTP 調用。

您可以將它發送到已集成Stripe的已託管服務器(如Stripe Payments Kit/NoodlioPay)或設置您自己的(如您試圖這樣做)。查看我發送的link的文檔以瞭解如何執行此操作。