package com.supwisdom.dlpay.agent;
import com.supwisdom.dlpay.api.domain.TTransactionMain;
+import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
* @param transation
* @return
*/
+ @Transactional
AgentResponse<T> init(TTransactionMain transation);
/**
* 当用支付完成后,第三方支付平台会发起通知给服务端,由服务端处理后续业务
*
+ *
+ * @param refno
* @param request - 第三方平台通知请求的 HttpRequest
* @return
*/
- AgentResponse<T> notify(HttpServletRequest request);
+ @Transactional
+ AgentResponse<T> notify(String refno, HttpServletRequest request);
/**
* 由服务端主动发起的查询第三方支付平交易情况
* @param transation - 交易参数
* @return
*/
+ @Transactional
AgentResponse<T> query(TTransactionMain transation);
}
class WechatServiceImpl(val sourceTypeService: SourceTypeService,
val agentServiceProxy: AgentServiceProxy,
val personIdentityDao: PersonIdentityDao,
- val sourceTypeConfigDao: SourceTypeConfigDao,
- var shopSourceTypeConfigDao: ShopSourceTypeConfigDao,
val consumePayService: ConsumePayService,
val transactionService: TransactionServiceProxy,
val restTemplate: RestTemplate) : WechatService {
this.total_fee = 1
this.spbill_create_ip = "14.23.150.211"
this.body = "充值测试"
- this.notify_url = "http://ykt.supwisdom.com:10201/payapi/api/notify/inapp/wechat/100010"
+ this.notify_url = "http://ykt.supwisdom.com:10201/payapi/api/notify/inapp/wechat/100010/${transaction.refno}"
this.trade_type = "MWEB"
this.scene_info = "{\"h5_info\": {\"type\":\"Wap\",\"wap_url\": \" https://pay.qq.com\",\"wap_name\": \"微信支付\"}}"
}
return agentResponse
}
- override fun doPayNotify(param: Map<String, String>): AgentResponse<QrcodePayTrans> {
+ override fun doPayNotify(transaction: TTransactionMain?, param: Map<String, String>): AgentResponse<QrcodePayTrans> {
val agentResponse = AgentResponse<QrcodePayTrans>()
- val transaction = consumePayService.getTransactionMainDtl(param["out_trade_no"], null, null)
if (transaction == null) {
agentResponse.code = AgentCode.REFNO_NOT_EXISTS
agentResponse.agentCode = AgentResponse.AGENTCODE_FAIL
val resultCode = param["result_code"]
if (!returnCode.isNullOrEmpty() && "SUCCESS" == returnCode
&& !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode) {
- val transid = param["transaction_id"]
- if (transid.isNullOrEmpty()) {
- transactionService.success(transaction.refno)
- } else {
- transactionService.success(transaction.refno, transid, true)
- }
agentResponse.code = AgentCode.SUCCESS
agentResponse.agentCode = resultCode
} else {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun notify(request: HttpServletRequest): AgentResponse<AlipayInAppResponse>? {
+ override fun notify(String: refno, request: HttpServletRequest): AgentResponse<AlipayInAppResponse>? {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
import com.supwisdom.dlpay.agent.AgentCode
import com.supwisdom.dlpay.agent.AgentResponse
import com.supwisdom.dlpay.agent.InAppPayService
-import com.supwisdom.dlpay.api.domain.TShopdtl
import com.supwisdom.dlpay.api.domain.TTransactionMain
-import com.supwisdom.dlpay.api.service.SourceTypeService
+import com.supwisdom.dlpay.api.service.TransactionServiceProxy
import mu.KotlinLogging
-import org.dom4j.Element
import org.dom4j.io.SAXReader
import org.springframework.stereotype.Component
import java.util.HashMap
@Component("wechatInAppAgent")
-class WechatInAppService(private val sourceTypeService: SourceTypeService,
- private val wechatService: WechatService)
+class WechatInAppService(private val wechatService: WechatService,
+ private val transactionServiceProxy: TransactionServiceProxy)
: InAppPayService<TTransactionMain> {
private val logger = KotlinLogging.logger { }
return wechatPayResponse;
}
- override fun notify(request: HttpServletRequest): AgentResponse<TTransactionMain>? {
- val wechatPayResponse = AgentResponse<TTransactionMain>();
+ override fun notify(refno: String, request: HttpServletRequest): AgentResponse<TTransactionMain>? {
+ val wechatPayResponse = AgentResponse<TTransactionMain>()
// 解析结果存储在HashMap
val map = HashMap<String, String>()
// 读取输入流
}
// 释放资源
request.inputStream.close()
- val resp = wechatService.doPayNotify(map)
+ val transation = transactionServiceProxy.findTransactionByRefno(refno)
+ val resp = wechatService.doPayNotify(transation, map)
if (resp.code == AgentCode.SUCCESS) {
+ wechatPayResponse.payload = transactionServiceProxy.success(refno)
wechatPayResponse.agentBody = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"
} else {
wechatPayResponse.agentBody = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[" + resp.agentMsg + "]]></return_msg></xml>"
+ wechatPayResponse.payload = transactionServiceProxy.fail(refno, resp.agentMsg)
}
return wechatPayResponse
}
fun doPayQuery(transaction: TTransactionMain): AgentResponse<QrcodePayTrans>
- fun doPayNotify(param: Map<String, String>): AgentResponse<QrcodePayTrans>
+ fun doPayNotify(transaction: TTransactionMain?, param: Map<String, String>): AgentResponse<QrcodePayTrans>
}
@Component("wechatAgent")
private val transactionServiceProxy: TransactionServiceProxy,
private val agentPayServiceContext: AgentPayServiceContext) {
- @PostMapping("/inapp/{sourcetype}/{tenant}")
+ @PostMapping("/inapp/{sourcetype}/{tenant}/{refno}")
fun inAppPayCallback(@PathVariable("sourcetype") sourcetype: String,
@PathVariable("tenant") tenant: String,
+ @PathVariable("refno") refno: String,
request: HttpServletRequest): ResponseEntity<*> {
val tenantDetails = tenantDetailsRegistrar.getTenantDetailsById(tenant)
if (!tenantDetails.isPresent) {
TenantContextHolder.getContext().tenant = tenantDetails.get()
val agent = agentPayServiceContext.findInAppPayService<Any>(sourcetype)
?: return ResponseBodyBuilder.badRequest("请求支付类型错误 <$sourcetype> 不存在")
- val agentResponse = agent.notify(request)
+ val agentResponse = agent.notify(refno, request)
return ResponseBodyBuilder.ok(agentResponse.agentBody)
}
return success(refno, "", true)
}
+ override fun readByRefnoForUpdate(refno: String): TTransactionMain {
+ return transactionMainDao.findByRefnoForUpdate(refno)
+ }
+
//////////////////////////////////////////////////////////////////
// 回退业务接口,包括撤销和退款
override fun refundInit(originRefno: String, refundAmount: Double, builder: TransactionBuilder): TTransactionMain {
@Transactional
fun success(refno: String): TTransactionMain
+ @Transactional
+ fun readByRefnoForUpdate(refno: String): TTransactionMain
+
/**
* 退款类业务
*/
return transactionMainDao.findByRefno(refno)
}
+ fun findTransactionByRefnoForUpdate(refno: String): TTransactionMain {
+ return transactionMainDao.findByRefnoForUpdate(refno)
+ }
+
fun findByOutTradeNo(refno: String): TTransactionMain? {
return transactionMainDao.findByOutTradeNo(refno)
}