Created
April 17, 2018 18:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.clouddemo.kjoshi.restep.service; | |
import com.braintreegateway.*; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.stereotype.Service; | |
import org.springframework.util.StringUtils; | |
import javax.validation.ValidationException; | |
import java.math.BigDecimal; | |
@Service | |
public class BrainTreeService { | |
private static String MERCHANT_ID = System.getenv("MERCHANT_ID"); | |
private static String PRIVATE_KEY = System.getenv("PRIVATE_KEY"); | |
private static String PUBLIC_KEY = System.getenv("PUBLIC_KEY"); | |
private static final Logger logger = LoggerFactory.getLogger(BrainTreeService.class); | |
private static BraintreeGateway gateway = new BraintreeGateway(Environment.SANDBOX,MERCHANT_ID,PUBLIC_KEY,PRIVATE_KEY); | |
public String getClientTocken(){ | |
if(StringUtils.isEmpty(MERCHANT_ID)||StringUtils.isEmpty(PRIVATE_KEY)||StringUtils.isEmpty(PUBLIC_KEY)){ | |
logger.error("Setup issue.."); | |
throw new ValidationException("Setup not correct"); | |
}else{ | |
String clientToken = gateway.clientToken().generate(); | |
logger.info("Client token generated:{}",clientToken); | |
return clientToken; | |
} | |
} | |
public Result performTransaction(Double amt,String nonce){ | |
logger.info("Submitting transaction"); | |
TransactionRequest req = new TransactionRequest(); | |
req.amount(new BigDecimal(amt)).paymentMethodNonce(nonce).options().submitForSettlement(true).done(); | |
Result<Transaction> txn = gateway.transaction().sale(req); | |
return txn; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment