2017-06-03 69 views
0

在Meteor/React應用程序中,我需要從mrgalaxy:stripe導入條紋。我想:流星 - 反應 - 條紋:如何導入條紋

import { Stripe } from 'meteor/mrgalaxy:stripe'; 

但它返回:

TypeError: Cannot read property 'setPublishableKey' of undefined 

在我創建其中添加了以下stripe.js文件服務器的文件夾:

import { Meteor } from 'meteor/meteor'; 
import { Stripe } from 'meteor/mrgalaxy:stripe'; 

Meteor.startup(function(){ 
    Stripe.setPublishableKey(Meteor.settings.public.StripePub); 
}); 
+0

這個軟件包使用API​​和一個過時版本npm包。由於您現在可以直接使用npm包並將腳本聲明添加到您的''模板中。 – MasterAM

回答

1

基於這個測試是在github倉庫裏沒有進口聲明

Tinytest.add('Stripe client is available', function(test){ 
    test.isTrue(Stripe != null); 
}); 

我猜測包括包只是添加一個條帶變量到全局範圍。

stripe_client.html頁面似乎是包中唯一的客戶端代碼,只包含以下html代碼片段。

<head> 
    <script type="text/javascript" src="https://js.stripe.com/v2/"></script> 
    <script type="text/javascript" src="https://checkout.stripe.com/checkout.js"></script> 
</head> 

因此,我認爲您的導入只是覆蓋了全局變量。您是否嘗試刪除您的導入聲明? (請原諒我對流星幾乎完全無知 - 我可能會在這裏找到基地)。

+0

當我刪除導入,然後它給了我「ReferenceError:條紋未定義」 – Art

+0

我一直假設https://github.com/tyler-johnson/stripe-meteor/是你的包的github存儲庫試圖使用。經過一番探索後,它看起來像這個文件https://github.com/tyler-johnson/stripe-meteor/blob/master/package.js告訴流星如何處理這個軟件包。它看起來像它可能會調用'api.export('STRIPEMETEOR')',所以...也許嘗試使用導入{STRIPEMETEOR}? – speckledcarp

0

什麼幫助我加入了這個包「條紋」:「^ 4.9.0」成的package.json除了mrgalaxy:在.meteor條/包