@Override
public void onTransactionCompleted(TransactionContext ctx) {
try {
TransactionData data = TransactionData.from(ctx);
// UI にデータを表示します。
} finally {
ctx.wipe();
}
}
@Override
public void onError(
TransactionContext ctx,
PaymentServiceErrorCode errorCode,
String message) {
if (ctx == null) {
// トランザクション コンテキストが利用できない場合のエラーを処理します。
return;
}
try {
TransactionData data = TransactionData.from(ctx);
// UI にデータとエラーの詳細を表示します。
} finally {
ctx.wipe();
}
}
/**
* トランザクション表示用の便利なデータクラス。
*/
public class TransactionData {
private final String currencyCode;
private final double amount;
private final String transactionDate;
private final String transactionType;
private final String transactionId;
private TransactionData(
String currencyCode,
double amount,
String transactionDate,
String transactionType,
String transactionId) {
this.currencyCode = currencyCode;
this.amount = amount;
this.transactionDate = transactionDate;
this.transactionType = transactionType;
this.transactionId = transactionId;
}
public static TransactionData from(TransactionContext ctx) {
String currencyCode = TransactionDisplayUtils.bcdToString(ctx.getCurrencyCode());
String transactionDate = TransactionDisplayUtils.bcdToString(ctx.getTrxDate());
String transactionType = TransactionDisplayUtils.getTransactionType(ctx.getTrxType());
return new TransactionData(
currencyCode,
ctx.getAmount(),
transactionDate,
transactionType,
ctx.getTrxId());
}
public String getCurrencyCode() {
return currencyCode;
}
public double getAmount() {
return amount;
}
public String getTransactionDate() {
return transactionDate;
}
public String getTransactionType() {
return transactionType;
}
public String getTransactionId() {
return transactionId;
}
}