Commit c4e87076 authored by gaodapeng's avatar gaodapeng

增加支付和退款功能

parent 14a115b3
package com.miya.fastcashier.repository
import androidx.annotation.WorkerThread
import com.sdy.miya.moblie.component.pay.core.constance.AppTagConstance
import com.sdy.miya.moblie.component.pay.core.result.MiYaMobilePayResult
import com.sdy.miya.moblie.component.pay.core.result.ResultBuilder
import com.sdy.miya.moblie.component.pay.platform.MiYaPlatformPayService
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import java.lang.Exception
import java.util.HashMap
/**
* 提供支付、退款的功能
*/
class PayRepository {
/**
* 支付功能
*/
@WorkerThread
fun pay(params: Map<String, String>): PayServiceResponse {
if (params == null) {
throw RuntimeException("MiyaPayServiceComponent startPay params is null")
}
val baseUrl = params["baseUrl"]
val payPrice = params["payPrice"]
val payType = params["payType"]
val token = params["token"]
val goodsDetail = params["goodsDetail"]
val signKey = params["signKey"]
val saasid = params["saasid"]
val marketid = params["marketid"]
val posId = params["posId"]
val cashierCode = params["cashierCode"]
val version = params["version"]
val orderNo = params["orderNo"]
val memberPhone = params["memberPhone"]
var terminalParams = params["terminalParams"]
val paymentInfoShowMessage = params["paymentInfoShowMessage"]
checkNotNull(baseUrl) { "MiyaPayServiceComponent startPay baseUrl is null" }
checkNotNull(payPrice) { "MiyaPayServiceComponent startPay payPrice is null" }
checkNotNull(payType) { "MiyaPayServiceComponent startPay payType is null" }
checkNotNull(goodsDetail) { "MiyaPayServiceComponent startPay goodsDetail is null" }
checkNotNull(signKey) { "MiyaPayServiceComponent startPay signKey is null" }
checkNotNull(saasid) { "MiyaPayServiceComponent startPay saasid is null" }
checkNotNull(marketid) { "MiyaPayServiceComponent startPay marketid is null" }
checkNotNull(posId) { "MiyaPayServiceComponent startPay posId is null" }
checkNotNull(cashierCode) { "MiyaPayServiceComponent startPay cashierCode is null" }
checkNotNull(version) { "MiyaPayServiceComponent startPay version is null" }
checkNotNull(orderNo) { "MiyaPayServiceComponent startPay oderNo is null" }
val paramsMap: MutableMap<String, Any?> = HashMap(14, 1.0f)
paramsMap["baseUrl"] = baseUrl
paramsMap["signKey"] = signKey
paramsMap["saasId"] = saasid
paramsMap["marketId"] = marketid
paramsMap["posId"] = posId
paramsMap["cashierCode"] = cashierCode
paramsMap["version"] = version
paramsMap["token"] = token
paramsMap["goodsDetail"] = goodsDetail
paramsMap["payPrice"] = payPrice
paramsMap["payType"] = payType
paramsMap["orderNo"] = orderNo
paramsMap["appTag"] = AppTagConstance.QINGTING_TYPE
paramsMap["needRetryWhenNetworkError"] = true
try {
//发起付款
val miYaMobilePayResult =
MiYaPlatformPayService.getService().syncStartMiYaPay(paramsMap)
if (miYaMobilePayResult != null && miYaMobilePayResult.resultCode == ResultBuilder.SUCCESS) {
return miYaMobilePayResult.payServiceResponse
} else {
throw RuntimeException(miYaMobilePayResult!!.errorMsg)
}
} catch (e: Exception) {
e.printStackTrace()
throw RuntimeException(e.message)
}
}
/**
* 退款功能
*/
fun refundByOrderNo(params: Map<String, String>): PayServiceResponse {
if (params == null) {
throw RuntimeException("MiyaPayServiceComponent refundByOrderNo params is null")
}
val baseUrl = params["baseUrl"]
val signKey = params["signKey"]
val saasid = params["saasid"]
val marketid = params["marketid"]
val posId = params["posId"]
val cashierCode = params["cashierCode"]
val version = params["version"]
val oriOrderNo = params["oriOrderNo"]
val refundOrderNo = params["refundOrderNo"]
val refundPrice = params["refundPrice"]
checkNotNull(baseUrl) { "MiyaPayServiceComponent refundByOrderNo baseUrl is null" }
checkNotNull(signKey) { "MiyaPayServiceComponent refundByOrderNo signKey is null" }
checkNotNull(saasid) { "MiyaPayServiceComponent refundByOrderNo saasid is null" }
checkNotNull(marketid) { "MiyaPayServiceComponent refundByOrderNo marketid is null" }
checkNotNull(posId) { "MiyaPayServiceComponent refundByOrderNo posId is null" }
checkNotNull(cashierCode) { "MiyaPayServiceComponent refundByOrderNo cashierCode is null" }
checkNotNull(version) { "MiyaPayServiceComponent refundByOrderNo version is null" }
checkNotNull(oriOrderNo) { "MiyaPayServiceComponent refundByOrderNo oriOrderNo is null" }
checkNotNull(refundOrderNo) { "MiyaPayServiceComponent refundByOrderNo refundOrderNo is null" }
checkNotNull(refundPrice) { "MiyaPayServiceComponent refundByOrderNo refundPrice is null" }
val paramsMap: MutableMap<String, Any> = HashMap(14, 1.0f)
paramsMap["baseUrl"] = baseUrl
paramsMap["signKey"] = signKey
paramsMap["saasId"] = saasid
paramsMap["marketId"] = marketid
paramsMap["posId"] = posId
paramsMap["cashierCode"] = cashierCode
paramsMap["version"] = version
paramsMap["oriOrderNo"] = oriOrderNo
paramsMap["refundOrderNo"] = refundOrderNo
paramsMap["refundPrice"] = refundPrice
try {
//发起付款
val miYaMobilePayResult = MiYaPlatformPayService.getService()
.syncRequestRefundOrderByOrderId(paramsMap)
if (miYaMobilePayResult != null && miYaMobilePayResult.resultCode == ResultBuilder.SUCCESS) {
return miYaMobilePayResult.payServiceResponse
} else {
throw RuntimeException(miYaMobilePayResult!!.errorMsg)
}
} catch (e: Exception) {
e.printStackTrace()
throw RuntimeException(e.message)
}
}
}
\ No newline at end of file
package com.miya.fastcashier.service
class PayRepository {
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment