#pastyghost_code

1 messages ยท Page 1 of 1 (latest)

open ploverBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1255000806021927025

๐Ÿ“ Have more to share? Add details, code, screenshots, videos, etc. below.

ionic dove
#

nvm

#

I'm an idiot.

#

I didn't pass my API key to my function.

vestal lotus
ionic dove
#

Okay, I passed in my API key, but I'm still not getting a client_secret back.

vestal lotus
#

What are you getting in the response?

ionic dove
#
"body": "{\"after_expiration\":null,\"allow_promotion_codes\":false,\"amount_subtotal\":0,\"amount_total\":0,\"automatic_tax\":null,\"billing_address_collection\":\"\",\"cancel_url\":\"\",\"client_reference_id\":\"\",\"client_secret\":\"\",\"consent\":null,\"consent_collection\":null,\"created\":0,\"currency\":\"\",\"currency_conversion\":null,\"customer\":null,\"customer_creation\":\"\",\"customer_details\":null,\"customer_email\":\"\",\"custom_fields\":null,\"custom_text\":null,\"expires_at\":0,\"id\":\"\",\"invoice\":null,\"invoice_creation\":null,\"line_items\":null,\"livemode\":false,\"locale\":\"\",\"metadata\":null,\"mode\":\"\",\"object\":\"\",\"payment_intent\":null,\"payment_link\":null,\"payment_method_collection\":\"\",\"payment_method_configuration_details\":null,\"payment_method_options\":null,\"payment_method_types\":null,\"payment_status\":\"\",\"phone_number_collection\":null,\"recovered_from\":\"\",\"redirect_on_completion\":\"\",\"return_url\":\"\",\"saved_payment_method_options\":null,\"setup_intent\":null,\"shipping_address_collection\":null,\"shipping_cost\":null,\"shipping_details\":null,\"shipping_options\":null,\"status\":\"\",\"submit_type\":\"\",\"subscription\":null,\"success_url\":\"\",\"tax_id_collection\":null,\"total_details\":null,\"ui_mode\":\"\",\"url\":\"\"}"
}
vestal lotus
#

Can you share your server side code?

#

You need pass ui_mode: 'embedded',

ionic dove
#

Yep, one second.

vestal lotus
ionic dove
#
package main

import (
    "context"
    "encoding/json"
    "log"
    "os"

    "github.com/aws/aws-lambda-go/events"
    "github.com/aws/aws-lambda-go/lambda"
    "github.com/stripe/stripe-go/v78"
    "github.com/stripe/stripe-go/v78/checkout/session"
)

type ClientSecret struct {
    Value string `json:"value"`
}

func CreateCheckoutSession (ctx context.Context, request events.APIGatewayProxyRequest) (response events.APIGatewayProxyResponse, err error) {
    stripe.Key = os.Getenv("STRIPE_API_KEY")
    domain := os.Getenv("FRONTEND_URL")
    params := &stripe.CheckoutSessionParams{
        UIMode: stripe.String("embedded"),
        ReturnURL: stripe.String(domain + "/success.html?session_id={CHECKOUT_SESSION_ID}"),
        LineItems: []*stripe.CheckoutSessionLineItemParams{
            {
                Price: stripe.String(("price_1MwGfXGVt95r9kfacC10ZCX1")),
                Quantity: stripe.Int64(1),
            },
        },
        Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
        AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)},
    }
    s, sessionErr := session.New(params)
    if sessionErr != nil {
        log.Printf("session error: %v", sessionErr)
    }

    session, marshalErr := json.Marshal(s)
    if marshalErr != nil {
        log.Printf("marshalling error: %v", marshalErr)
    }
    return events.APIGatewayProxyResponse{
        StatusCode: 200,
        Headers: map[string]string{
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods" : "GET, OPTIONS, POST",
            "Access-Control-Allow-Headers" : "*",
        },
        Body: string(session),
    }, err
}

func main() {
    lambda.Start(CreateCheckoutSession)
}
vestal lotus
#

Can you share the reques id please?

ionic dove
#

req_ICeEOLQqKhuEdT

#

OH

#

I need to pass a return URL.

vestal lotus
#

Yes!

ionic dove
#

Fixing that!

#

I didn't realize I had to pass one.

vestal lotus
#

You did pass one, return_url, it is just not valid

ionic dove
#

I think that mostly got me going. I will reach back out if I have further questions. ๐Ÿ™‚

#

Thanks so much!

vestal lotus
#

Happy to help!

ionic dove
#

I did have another quick question if you don't mind: is it standard practice to POST price IDs to handle multiple products?

vestal lotus
#

Are you asking if you need separate price id for each product id?

#

Or, something else?

#

Each product would have prices

ionic dove
#

No - so let's say I had Product X and Product Y - could I POST a JSON with a price_id string to handle X or Y depending on what was POSTed?

vestal lotus
#

I do not understand, can you reword this please?

#

After re-reading this, I think you're asking if you can add a condition to use one product over the other.

#

No there is not, you would need to code this on your end and then pass the product information on the CheckoutSession.

ionic dove
#

That second bit is actually what I was asking - thanks for confirming! ๐Ÿ™‚

vestal lotus
#

Sure!