package backend.configuration

import backend.services.ConfigurationService
import com.braintreegateway.BraintreeGateway
import com.braintreegateway.Environment
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
open class BraintreeConfiguration {

    private val configurationService: ConfigurationService
    private val environment: String
    private val merchantID: String
    private val publicKey: String
    private val privateKey: String

    @Autowired
    constructor(configurationService: ConfigurationService) {
        this.configurationService = configurationService
        this.environment = configurationService.get("org.breakout.payment.braintree.environment") ?: "sandbox"
        this.merchantID = configurationService.getRequired("org.breakout.payment.braintree.merchantid")
        this.publicKey = configurationService.getRequired("org.breakout.payment.braintree.publickey")
        this.privateKey = configurationService.getRequired("org.breakout.payment.braintree.privatekey")
    }

    @Bean
    open fun BraintreeGateway(): BraintreeGateway {
        val env = Environment.parseEnvironment(environment)
        return com.braintreegateway.BraintreeGateway(env, merchantID, publicKey, privateKey)
    }
}

Add Configuration and Bean for Braintree Payments
Add Configuration and Bean for Braintree Payments

BreakOutEvent/breakout-backend,BreakOutEvent/breakout-backend,BreakOutEvent/breakout-backend