2016-10-11 14 views
0

私は、Angular2とカスタムフォームを使用してストライプトークンを作成しています。以下のコードはconsole.log(token.id)を正しく実行しますが、this.http.post...は呼び出されません。例えばthis.sayHello()のような別の関数を呼び出そうとしても、それはまだ呼び出されません。角2 - コードがトークンコールバック(ストライプ)で実行されていません

export class SubscriptionComponent{ 

    constructor(public http: Http){} 

    openCheckout() { 

    var handler = (<any>window).StripeCheckout.configure({ 
     key: 'pk_test_mykey', 
     locale: 'auto', 
     token: function(token, args){ 
     console.log(token.id); 

     this.http.post("/stripe/customer", token.id).subscribe(
      res => { 
      console.log(res); 
      }, 
      error => console.log(error) 
     ); 
     }  
    }); 
    handler.open({ 
     name: 'Demo', 
     description: '', 
     amount: 990, 
     currency: 'GBP', 
     email: '[email protected]' 
    }); 
    } 
} 

何か助けてください。

+0

HTTPリクエストがネットワークトラッカー経由で送信されているかどうかを確認しましたか? put console.log(this); 「this」が何であるかを見るためにtoken.idを記録した後 –

答えて

0

この問題を抱えている人は誰でも。私はhttp.postを処理するためにcheckoutServiceサービスを注入し、この

token: token => { 
     console.log(token.id); 
     this.checkoutService.postToken(token); 
     } 

にトークンのコールバックを変更することでこれを解決しました。この方法がなぜ機能するのか、もう一方はなぜそこに行かなかったのか分かりません。

関連する問題