generated from pricelees/issue-pr-template
40 lines
1.6 KiB
Kotlin
40 lines
1.6 KiB
Kotlin
package roomescape.payment.infrastructure.client
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
|
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder
|
|
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings
|
|
import org.springframework.context.annotation.Bean
|
|
import org.springframework.context.annotation.Configuration
|
|
import org.springframework.web.client.RestClient
|
|
import java.nio.charset.StandardCharsets
|
|
import java.time.Duration
|
|
import java.util.*
|
|
|
|
@Configuration
|
|
@EnableConfigurationProperties(PaymentProperties::class)
|
|
class PaymentConfig {
|
|
|
|
@Bean
|
|
fun tossPaymentClientBuilder(
|
|
paymentProperties: PaymentProperties,
|
|
): RestClient.Builder {
|
|
val settings: ClientHttpRequestFactorySettings = ClientHttpRequestFactorySettings.defaults().also {
|
|
it.withReadTimeout(Duration.ofSeconds(paymentProperties.readTimeout.toLong()))
|
|
it.withConnectTimeout(Duration.ofSeconds(paymentProperties.connectTimeout.toLong()))
|
|
}
|
|
val requestFactory = ClientHttpRequestFactoryBuilder.jdk().build(settings)
|
|
|
|
return RestClient.builder()
|
|
.baseUrl(paymentProperties.apiBaseUrl)
|
|
.defaultHeader("Authorization", getAuthorizations(paymentProperties.confirmSecretKey))
|
|
.requestFactory(requestFactory)
|
|
}
|
|
|
|
private fun getAuthorizations(secretKey: String): String {
|
|
val encodedSecretKey = Base64.getEncoder()
|
|
.encodeToString("$secretKey:".toByteArray(StandardCharsets.UTF_8))
|
|
|
|
return "Basic $encodedSecretKey"
|
|
}
|
|
}
|