2017-11-15 10 views
0

これは私の問題です。私はアプリエンジンユーザー用のgithub readmeに従っていますが、私のアプリにストライプを実装するには問題はありませんApp Engineではhttp.DefaultTransportとhttp.DefaultClientを使用できないようです。アプリエンジンでストライプ充電を行うことができませんGolang

私はreadmeで、アプリエンジンでStripeクライアントを初期化する方法を示していますが、チャージカードのサンプルを見つけることができないので、これが私がこの実装に来た理由です。

私は長い時間のためのApp Engineで作業されていますが、何らかの理由で、私はまだこのakwardエラーが出るので、私は、この問題に使用しています:

:コードです。ここ

cannot use stripe.BackendConfiguration literal (type stripe.BackendConfiguration) as type stripe.Backend in assignment: stripe.BackendConfiguration does not implement stripe.Backend (Call method has pointer receiver)

をこの例では、すべての動作しているようですなぜ

func setStripeChargeClient(context context.Context, key string) *charge.Client { 
    c := &charge.Client{} 

    var b stripe.Backend 
    b = stripe.BackendConfiguration{ 
     stripe.APIBackend, 
     "https://api.stripe.com/v1", 
     urlfetch.Client(context), 
    } 

    c.Key = key 
    c.B = b 

    return c 
} 

そのBの逢引のエラーを取得 ...

何私はそれを把握することはできませんですウェブの周りに、あなたはこの1つで私を啓発してもらえば、私はあなたの借金になり、私のアプリでは動作しません笑

、その後、このよう

stripeClient := setStripeChargeClient(context, "sk_live_key »)

答えて

0

エラーメッセージがそれを呼び出します問題を教えてくれます。 stripe.BackendConfigurationタイプは、stripe.Backendインターフェースを実装していません。エラーメッセージはまた、欠落しているCallメソッドがポインタ受信側にあるという有用なヒントを提供します。

b = &stripe.BackendConfiguration{ // note the & 
    stripe.APIBackend, 
    "https://api.stripe.com/v1", 
    urlfetch.Client(context), 
} 

specification regarding method setsを参照してください:

修正は、ポインタ値を使用することです。値受信側のメソッドセットには、ポインタ受信メソッドは含まれません。

+0

[OK]を感謝し、この修正プログラムは私がコンパイルするアプリを作るために許可がたくさんこのエラーが発生しました '投稿https://api.stripe.com/v1/customers:http.DefaultTransportと http.DefaultClientはApp Engineでは利用できません。 https://cloud.google.com/appengine/docs/go/urlfetch/ を参照してください。setStripeClientメソッドでurlfetchを使用しているため意味がありません –

0

OK]をクリックして、最後にそうすることによって、溶液を得た:

func setStripeChargeClient(context context.Context, key string) *charge.Client { 
     c := &charge.Client{} 

     //SETTING THE CLIENT WITH URL FETCH PROPERLY 
     fetch := &http.Client{ 
       Transport: &urlfetch.Transport{ 
       Context: context, 
     }, 
     } 

    //USE SetHTTPClient method to switch httpClient 
    stripe.SetHTTPClient(fetch) 

    var b stripe.Backend 
    b = &stripe.BackendConfiguration{stripe.APIBackend, 
    "https://api.stripe.com/v1",fetch} 

    c.Key = key 
    c.B = b 

    return c 
} 
0

このストライプのGAEの推奨どおり私の解決策だった:

func myHandler(w http.ResponseWriter, r *http.Request) { 
    c := appengine.NewContext(r) 
    myStripeKey := "pk_test_ABCDEF..." 
    httpClient := urlfetch.Client(c) 
    stripeClient := client.New(myStripeKey, stripe.NewBackends(httpClient)) 
    chargeParams := &stripe.ChargeParams{ 
     Amount: uint64(totalCents), 
     Currency: "usd", 
     Desc:  description, 
     Email:  email, 
     Statement: "MyCompany", 
    } 
    chargeParams.SetSource(token) 
    charge, chargeErr := stripeClient.Charges.New(chargeParams) 
関連する問題