我对布伦特里感到困惑。当客户在现场订购某些物品时,他用他的信用卡向BT收取费用,我需要通过Java客户端检查此付款。我找到了以下代码:
Transaction transaction = gateway.transaction().find("the_transaction_id");
但我需要按orderId搜索,这是我的系统在每个订单事件上发出的特殊ID。如何在BT中使用Java API?
答案 0 :(得分:2)
虽然你可能能够在Braintree一侧持有orderId,但我还是没有办法直接对它进行查找。
以下是我们处理它的方式:
使用您从Braintree获得的交易ID保留您的orderId。当您需要进行检查时,请使用orderId查找您的表格,找到transactionId,然后使用相同的find()
方法查找付款。
我想你会做类似的事情:
//some paymentService
public Result<Transaction> sale(BigDecimal amount,
String nonce,
String firstName,
String lastName,
String postalCode) {
TransactionRequest request = new TransactionRequest()
.customer()
.firstName(firstName)
.lastName(lastName)
.done()
.billingAddress()
.firstName(firstName)
.lastName(lastName)
.postalCode(postalCode)
.done()
.type(Type.SALE)
.amount(amount)
.paymentMethodNonce(nonce)
.options()
.submitForSettlement(true)
.done();
return gateway.transaction().sale(request);
}
//and then...
Result<Transaction> result = paymentService.sale(amount, nonce, firstName, lastName, postalCode);
if (result.isSuccess()) {
Transaction transaction = result.getTarget();
String transactionId = transaction.getId(); //persist this ID and your orderId together in your DB
...
}
//when you need to find payment details, it'd be like:
Order order = someService.find(orderId);
PaymentHistory paymentHistory = order.getPaymentHistory();
String transactionId = paymentHistory.getTransactionId();
Transaction transaction = gateway.transaction().find(transactionId);