package main import ( "context" "fmt" "os" "github.com/VictorAvelar/mollie-api-go/v3/mollie" ) func createMolliePayment(preOrder PreOrder, shippingCost int) (*mollie.Response, *mollie.Payment, error) { amount := preOrder.CalcTotal() + shippingCost return mollieClient.Payments.Create(context.Background(), mollie.Payment{ Amount: &mollie.Amount{ Currency: "EUR", Value: fmt.Sprintf("%.2f", float64(amount)/float64(100)), }, Description: fmt.Sprintf("Thomas Pol Shop"), Metadata: map[string]interface{}{ "preorderID": preOrder.ID, }, RedirectURL: fmt.Sprintf("%s/%v", config.MollieRedirectURL, preOrder.ID), WebhookURL: config.MollieWebhook, }, nil) } func initMollie() (*mollie.Client, error) { os.Setenv("MOLLIE_API_TOKEN", config.MollieToken) apiTokenClient, err := mollie.NewClient(nil, mollie.NewConfig( false, mollie.APITokenEnv, )) if err != nil { return nil, err } return apiTokenClient, nil }