添加3.3和3.4查询与请款功能
This commit is contained in:
@@ -75,6 +75,12 @@ public class TradeQueryResp extends BaseResult {
|
||||
@JSONField(name = "PromoCode")
|
||||
private String promoCode;
|
||||
|
||||
/**
|
||||
* MyCard 交易序號
|
||||
*/
|
||||
@JSONField(name = "TradeSeq")
|
||||
private String tradeSeq;
|
||||
|
||||
/**
|
||||
* 訂閱代碼
|
||||
*/
|
||||
|
@@ -50,6 +50,11 @@ public class MyCardService {
|
||||
*/
|
||||
private static final String PAY_ITEM_QUERY = "/MyBillingPay/v1.2/PayItemQuery";
|
||||
|
||||
/**
|
||||
* 確認 MyCard 交易,並進行請款
|
||||
*/
|
||||
private static final String PAYMENT_CONFIRM = "/MyBillingPay/v1.2/PaymentConfirm";
|
||||
|
||||
@Autowired
|
||||
private MyCardConfig myCardConfig;
|
||||
|
||||
@@ -118,6 +123,21 @@ public class MyCardService {
|
||||
}
|
||||
}
|
||||
|
||||
public TradeQueryResp paymentConfirm(String authCode) {
|
||||
try {
|
||||
AuthCodeParam param = new AuthCodeParam();
|
||||
param.setAuthCode(authCode);
|
||||
List<HttpForm> params = buildParams(param);
|
||||
String result = OkHttpUtils.postWithForm(myCardConfig.getDomain() + TRADE_QUERY, params);
|
||||
log.info("authCode : {}, result : {}", authCode, result);
|
||||
TradeQueryResp response = JSONObject.parseObject(result, TradeQueryResp.class);
|
||||
checkResponseBody(response);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
throw new ApiException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建参数
|
||||
*
|
||||
|
@@ -33,6 +33,7 @@ import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -137,6 +138,7 @@ public class MyCardBizServiceImpl implements MyCardBizService {
|
||||
return orders;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public String callback(CallbackDto callback) {
|
||||
String preHashValue = callback.getReturnCode() + callback.getPayResult() + callback.getFacTradeSeq() + callback.getPaymentType() + callback.getAmount() + callback.getCurrency() + callback.getMyCardTradeNo() + callback.getMyCardType() + callback.getPromoCode() + myCardConfig.getSecretKey();
|
||||
@@ -167,6 +169,7 @@ public class MyCardBizServiceImpl implements MyCardBizService {
|
||||
if (chargeRecord == null) {
|
||||
throw new ApiException("儲值失敗");
|
||||
}
|
||||
String authCode = chargeRecord.getExtra();
|
||||
String metadata = chargeRecord.getMetadata();
|
||||
if (StrUtil.isEmpty(metadata)) {
|
||||
throw new ApiException("儲值失敗");
|
||||
@@ -188,8 +191,20 @@ public class MyCardBizServiceImpl implements MyCardBizService {
|
||||
log.error("支付非成功状态, payResult : {}", payResult);
|
||||
return failureUrl;
|
||||
}
|
||||
//厂商查询交易结果
|
||||
TradeQueryResp tradeQuery = myCardService.tradeQuery(authCode);
|
||||
if (!tradeQuery.isSuccess()) {
|
||||
throw new ApiException(tradeQuery.getReturnMsg());
|
||||
}
|
||||
//更新订单
|
||||
boolean isSuccess = updateOrder(chargeRecordId, currency, amount, myCardTradeNo);
|
||||
if (isSuccess) {
|
||||
//执行请款
|
||||
TradeQueryResp confirm = myCardService.paymentConfirm(authCode);
|
||||
if (!confirm.isSuccess()) {
|
||||
throw new ApiException(confirm.getReturnMsg());
|
||||
}
|
||||
}
|
||||
return isSuccess ? successUrl : failureUrl;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user