2017-06-12 6 views
1

Braintree Drop-in v3をパッケージ npm i -save braintree-web-drop-inの角型アプリに統合しました。braintree.dropin v3の入力タイプ

は、それから私は、私はドロップイン機能のサポートが含まれていないようですが例がhereを述べ、次れたパッケージ@types/braintree-webを見つけました。明らかに、これは正しいパッケージではありません。

braintree.dropin.create({ 
    authorization: environment.braintreeKey, 
    selector: '#dropin-container' 
}, function (err, dropinInstance) { 
    if (err) { 
    // Handle any errors that might've occurred when creating Drop-in 
    console.error(err); 
    return; 
    } 
    submitButton.addEventListener('click', function() { 
    dropinInstance.requestPaymentMethod(function (err, payload) { 
     if (err) { 
     // Handle errors in requesting payment method 
     } 

     // Send payload.nonce to your server 
    }); 
    }); 
}); 

は、しかし私は、braintree.dropinまだ私に問題を引き起こしている、そして、braintreeはグローバル名前空間として認識されますimport * as braintree from "@types/braintree-web";

import文 を持っています。

活字体のコンパイラは、DROPINオブジェクトについて不平を言っている:

Property 'dropin' does not exist on type 'typeof braintree'.

質問:

それはそれですべての罰金とロールだ活字体伝えるためにいくつかの簡単な方法はありますか?それとも自分でタイピングをしなければならないのですか?あるいは、彼らはすでにどこかに存在していますか?または、braintree-web-packageを使用する方が良いでしょうか?

答えて

0

私はブレーントリーはっきりnode_modules

その活字体の基礎にインストールモジュールが、私は知っていたしませんでした弱い何かを持っているので、私はimport * as dropin from 'braintree-web-drop-in';その可能性を使用して、それを解決しました。

この質問は、UIにおけるブレーントリードロップについてですので、ここに私のコードは、活字体と結合されていて、活字体の内側functionキーワードを使うべきではありませんので、角度2. Javascriptが、活字体とは異なるthisを扱います。

braintreeIsReady: boolean; 
    dropIninstance: any; 

    ngOnInit() { 
    dropin.create({ 
     authorization: environment.braintreeKey, 
     selector: '#dropin-container' 
    }, (err, dropinInstance) => { 
     if (err) { 
     // Handle any errors that might've occurred when creating Drop-in 
     console.error(err); 
     return; 
     } 
     this.dropIninstance = dropinInstance; 
     this.braintreeIsReady = true; 
    }); 
    } 

    pay() { 
    this.dropIninstance.requestPaymentMethod((err, payload) => { 
     if (err) { 
     // deal with error 
     } 
     else { 
     //send nonce to the server 

     } 
    }); 
    }