Hi I try to make a test payment with a test key of Mollie in Go
This the code based on their github
"fmt"
"net/http"
"github.com/VictorAvelar/mollie-api-go/v3/mollie"
)
func main() {
apiKey := "test_key"
client := http.DefaultClient
mollieClient := mollie.NewClient(apiKey, client)
payment, err := mollieClient.Payments.Create(&mollie.Payment{
Amount: &mollie.Amount{
Currency: "EUR",
Value: "10.00",
},
Description: "Testpayment with GO",
RedirectURL: "https://mollie.com",
})
if err != nil {
fmt.Println("Fout bij het creëren van de betaling:", err)
return
}
fmt.Println("Betaling aangemaakt. Ga naar deze URL om de betaling te voltooien:")
fmt.Println(payment.Links.Checkout.Href)
}
Everything is fine, but when I run the "go run" command I get this error
# command-line-arguments
.\mollie_example.go:14:18: assignment mismatch: 1 variable but mollie.NewClient returns 2 values
.\mollie_example.go:14:35: cannot use apiKey (variable of type string) as *http.Client value in argument to mollie.NewClient
.\mollie_example.go:14:43: cannot use client (variable of type *http.Client) as *mollie.Config value in argument to mollie.NewClient
I tried to fix it by adding err to this line
mollieClient := mollie.NewClient(apiKey, client)
by making it
mollieClient, err := mollie.NewClient(apiKey, client)
But it makes it worse because the error will be assignment mismatch: 2 variables but mollie.NewClient returns 3 values
You are not using the methods properly. That's the reason you are having these issues.
See the NewClient function syntax
It is expecting 2 arguments as type
*http.Clientand*Config, but you provided the first argument as string. This function is returning 2 values, thus we have to use 2 variablesSo you have to use
assignment mismatch: 1 variable but mollie.NewClient returns 2 valueswill be resolved with this change.mollieClient.Payments.Create expecting 3 inputs and returning 3 values.
See the doc for more.
Note : Read through the package, see the function/method syntax, also check the _test.go files to see how they are working with the functionalities. Happy coding :).