Ingenico-ePayments / connect-sdk-go

Ingenico Connect Go Server SDK
https://docs.connect.worldline-solutions.com/documentation/sdk/server/go/
Other
8 stars 6 forks source link

CreatePayment timeout #3

Closed ja-cast closed 3 years ago

ja-cast commented 3 years ago

I am trying to post a create payment request using the GO SDK in sandbox environment. I already created my sandbox account, and my merchantID is: 1095. The payment method I'm trying to use is WechatPay, QRCode integration. however I'm getting a timeout when I post the payment request. The exact message I'm getting is:

There was an error in the communication with the Ingenico ePayments platform Post "https://world.preprod.api-ingenico.com/v1/1095/payments": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

I already checked network block, but I don't seem to have any blocking rule on my side.

Here is my code:

`package main

import ( "fmt"

"github.com/BurntSushi/toml"

connectsdk "github.com/Ingenico-ePayments/connect-sdk-go"
"github.com/Ingenico-ePayments/connect-sdk-go/domain/definitions"
"github.com/Ingenico-ePayments/connect-sdk-go/domain/payment"

)

func main() {

conf, _ := connectsdk.CreateConfiguration("3ceafe4f45172802", "iZEVVw538LC3Tqt2NcOdwWS4MSejPV0cFR9aYlgIiMw=", "integrator")
tomlData := `
ConnectTimeout = 5000
SocketTimeout = 3000
MaxConnections = 10
AuthorizationType = "v1HMAC"
[APIEndpoint]
    host = "eu.sandbox.api-ingenico.com"
`
toml.Decode(tomlData, conf)
client, clientErr := connectsdk.CreateClientFromConfiguration(conf)
if clientErr != nil {
    panic(clientErr)
}

client, _ = client.WithClientMetaInfo(`{"platformIdentifier":"Android/4.4","appIdentifier":"Examplemobileapp/1.1","sdkIdentifier":"AndroidClientSDK/v1.2","screenSize":"800x600","deviceBrand":"Samsung","deviceType":"GT9300","ipAddress":"123.123.123.123"}`)

defer client.Close()

var payment863SpecificInput payment.RedirectPaymentProduct863SpecificInput
payment863SpecificInput.IntegrationType = newString("desktopQRCode")

var paymentSpecificInput payment.RedirectPaymentMethodSpecificInput
paymentSpecificInput.PaymentProduct863SpecificInput = &payment863SpecificInput

var fraudFields definitions.FraudFields
fraudFields.CustomerIPAddress = newString("190.57.88.226")

var amountOfMoney definitions.AmountOfMoney
amountOfMoney.Amount = newInt64(234)
amountOfMoney.CurrencyCode = newString("USD")

var billingAddress definitions.Address
billingAddress.CountryCode = newString("US")
billingAddress.StateCode = newString("TX")
billingAddress.City = newString("Grapevine")

var customer payment.Customer
customer.BillingAddress = &billingAddress
customer.MerchantCustomerID = newString("134183783095")

var order payment.Order
order.AmountOfMoney = &amountOfMoney
order.Customer = &customer

var body payment.CreateRequest
body.RedirectPaymentMethodSpecificInput = &paymentSpecificInput
body.FraudFields = &fraudFields
body.Order = &order

response, err := client.Merchant("1095").Payments().Create(body, nil)

fmt.Println(response, err)

}

func newBool(value bool) *bool { return &value }

func newInt32(value int32) *int32 { return &value }

func newInt64(value int64) *int64 { return &value }

func newString(value string) *string { return &value } `

rob-spoor commented 3 years ago

A socket timeout (read timeout) of 3 seconds (3000) is not enough for operations like create payment. Try increasing it to at least 30000 (30 seconds).

ja-cast commented 3 years ago

I increased the read timeout to 60 seconds, but still got the same timeout error

rob-spoor commented 3 years ago

Do you also get a timeout error if you try calling TestConnection?

ja-cast commented 3 years ago

Yes, I get the same result:

image

rob-spoor commented 3 years ago

Since that call should succeed within 60 seconds, the issue may lie somewhere else.

From the same machine, can you try to do a cURL request to the same URL?

curl https://eu.sandbox.api-ingenico.com/v1/1095/services/testconnection

This should return a 403 response, since obviously the authentication part is missing, but if there is an issue in the network this command should fail as well. For reference, if I try it I get a 403 error almost immediately.

ja-cast commented 3 years ago

Executing the curl, I get the 403 as expected

image

rob-spoor commented 3 years ago

I tried it locally (using Testconnection), and I got the same result. Printing the configuration showed that the issue lies in the unit of time and the conversion used by time.Duration. Without an explicit unit, the value is considered to be nanoseconds. By specifying 5000 you don't get 5 seconds, but 5 microseconds.

Ideally the solution would be to change the 3000 into 3000ms or 3s, which is how you would define it when using time.ParseDuration. However, toml isn't able to use this. Therefore, the solution is to specify the timeouts in nanoseconds, by appending 000000 (6 zeroes) to the current values.

I will make sure that the documentation at https://epayments.developer-ingenico.com/documentation/sdk/server/go/ will be updated.

ja-cast commented 3 years ago

Thanks, adding the zeros to the timeouts solved the problem.

rob-spoor commented 3 years ago

You're welcome.