无法使用App Engine Golang进行条纹充电

So here is my problem, i have been following the github readme for app engine users in order to implement stripe into my app but the thing is that i can’t make it work as it seems that the http.DefaultTransport and http.DefaultClient are not available in App Engine.

I have seen that in the readme you show us how to initialize the Stripe client with app engine but i cannot find any charge card example so this is why i have come to this implementation.

I am used to this problem, since i have been working with app engine for a long time but for some reason i still get this akward error :

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)

Here is the code :

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
}

Getting the error on that b assignation …

What i can’t figure it out is why this example seems to work all around the web and does not work in my app, if you could please enlighten me on this one, i would be in your debt hahaha

and then calling it this way

stripeClient := setStripeChargeClient(context, "sk_live_key »)

The error message tells you the problem. The stripe.BackendConfiguration type does not implement stripe.Backend interface. The error message also gives the helpful hint that the missing Call method is on the pointer receiver.

The fix is to use a pointer value:

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

See the specification regarding method sets. The method set of a value receiver does not include the pointer receiver methods.

Ok finally got the solution by doing so :

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
}

This was my solution as per Stripe's GAE recommendations:

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)