@ -1,9 +1,11 @@
package cn.iocoder.mall.pay .biz.client ;
package cn.iocoder.mall.pay service.client.thirdpay ;
import cn.iocoder.common.framework.vo.CommonResult ;
import cn.iocoder.mall.pay.biz.dataobject.PayRefundDO ;
import cn.iocoder.mall.pay.biz.dataobject.PayTransactionDO ;
import cn.iocoder.mall.pay.biz.dataobject.PayTransactionExtensionDO ;
import cn.iocoder.mall.payservice.client.thirdpay.dto.ThirdPayRefundSuccessRespDTO ;
import cn.iocoder.mall.payservice.client.thirdpay.dto.ThirdPayTransactionSuccessRespDTO ;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.refund.PayRefundDO ;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionDO ;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionExtensionDO ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
import com.google.common.collect.ImmutableMap ;
@ -17,7 +19,7 @@ import java.util.HashMap;
import java.util.Map ;
// TODO 代码略乱,后面重构下
public class Pingxx PaySDK extends AbstractPaySDK {
public class Pingxx ThirdPayClient extends AbstractThirdPayClient {
static {
Pingpp . privateKeyPath = "/Users/yunai/Downloads/pingxx.pem" ;
@ -65,14 +67,14 @@ public class PingxxPaySDK extends AbstractPaySDK {
}
@Override
public CommonResult < T ransactionSuccessB O> parseTransactionSuccessParams ( String params ) {
public CommonResult < T hirdPayTransactionSuccessRespDT O> parseTransactionSuccessParams ( String params ) {
JSONObject paramsObj = JSON . parseObject ( params ) ;
JSONObject chargeObj = paramsObj . getJSONObject ( "data" ) . getJSONObject ( "object" ) ;
T ransactionSuccessBO transactionPaySuccessBO = new TransactionSuccessB O( )
T hirdPayTransactionSuccessRespDTO successRespDTO = new ThirdPayTransactionSuccessRespDT O( )
. setTransactionCode ( chargeObj . getString ( "order_no" ) )
. setPaymentTime ( new Date ( chargeObj . getLong ( "time_paid" ) * 1000 ) )
. setTradeNo ( chargeObj . getString ( "transaction_no" ) ) ;
return CommonResult . success ( transactionPaySuccessB O) ;
return CommonResult . success ( successRespDT O) ;
}
@Override
@ -99,16 +101,16 @@ public class PingxxPaySDK extends AbstractPaySDK {
// {"id":"evt_400190427005305341228202","created":1556297585,"livemode":false,"type":"refund.succeeded","data":{"object":{"id":"re_HO0m9GOGOi50KCmX104ufHe1","object":"refund","order_no":"HO0m9GOGOi50KCmX104ufHe1","amount":1,"created":1556297585,"succeed":true,"status":"succeeded","time_succeed":1556297585,"description":"测试下退款","failure_code":null,"failure_msg":null,"metadata":{},"charge":"ch_y1iXjLnDS4G4OO4uT4a5C4W1","charge_order_no":"20190427004410165545","transaction_no":"201904270053053608824","extra":{}}},"object":"event","request":"iar_Oa188KCiHC40iLibbHX5WrHC","pending_webhooks":0}
@Override
public CommonResult < RefundSuccessB O> parseRefundSuccessParams ( String params ) {
public CommonResult < ThirdPayRefundSuccessRespDT O> parseRefundSuccessParams ( String params ) {
JSONObject paramsObj = JSON . parseObject ( params ) ;
JSONObject chargeObj = paramsObj . getJSONObject ( "data" ) . getJSONObject ( "object" ) ;
RefundSuccessBO refundSuccessBO = new RefundSuccessB O( )
ThirdPayRefundSuccessRespDTO successRespDTO = new ThirdPayRefundSuccessRespDT O( )
. setRefundCode ( chargeObj . getJSONObject ( "metadata" ) . getString ( "refundCode" ) )
. setRefundTime ( new Date ( chargeObj . getLong ( "time_succeed" ) * 1000 ) )
. setTradeNo ( chargeObj . getString ( "transaction_no" ) )
// TODO 芋艿,需要测试下,退款失败
. setSuccess ( chargeObj . containsValue ( "failure_code" ) | | chargeObj . containsValue ( "failure_msg" ) ) ;
return CommonResult . success ( refundSuccessB O) ;
return CommonResult . success ( successRespDT O) ;
}
private Map < String , Object > createRefundRequest ( PayRefundDO refund , String chargeId , String orderDescription , Integer price ) {
@ -123,7 +125,7 @@ public class PingxxPaySDK extends AbstractPaySDK {
}
public static void main ( String [ ] args ) {
if ( fals e) { // 测试支付请求
if ( tru e) { // 测试支付请求
PayTransactionDO transaction = new PayTransactionDO ( ) ;
transaction . setOrderSubject ( "测试商品" ) ;
transaction . setOrderDescription ( "测试描述" ) ;
@ -133,14 +135,14 @@ public class PingxxPaySDK extends AbstractPaySDK {
extension . setTransactionCode ( System . currentTimeMillis ( ) + "" ) ;
extension . setCreateIp ( "127.0.0.1" ) ;
new Pingxx PaySDK ( ) . submitTransaction ( transaction , extension , null ) ;
new Pingxx ThirdPayClient ( ) . submitTransaction ( transaction , extension , null ) ;
}
if ( tru e) { // 测试退款请求
if ( fals e) { // 测试退款请求
PayRefundDO refund = new PayRefundDO ( ) . setPrice ( 9999999 ) . setOrderDescription ( "测试描述" ) ;
PayTransactionExtensionDO transactionExtension = new PayTransactionExtensionDO ( )
. setExtensionData ( "{\"id\":\"evt_400190423100354205607502\",\"created\":1555985033,\"livemode\":false,\"type\":\"charge.succeeded\",\"data\":{\"object\":{\"id\":\"ch_DCGyXTmDGuHKb1C0yTzjPOGC\",\"object\":\"charge\",\"created\":1555985032,\"livemode\":false,\"paid\":true,\"refunded\":false,\"reversed\":false,\"app\":\"app_aTyfXDjrvzDSbLuz\",\"channel\":\"wx_pub\",\"order_no\":\"20190423100352158401\",\"client_ip\":\"114.87.158.59\",\"amount\":10,\"amount_settle\":10,\"currency\":\"cny\",\"subject\":\"kafka 实战\",\"body\":\"测试描述\",\"extra\":{\"open_id\":\"just_for_test\",\"bank_type\":\"your bank type\"},\"time_paid\":1555985033,\"time_expire\":1555992232,\"time_settle\":null,\"transaction_no\":\"1244341374201904238178164740\",\"refunds\":{\"object\":\"list\",\"url\":\"/v1/charges/ch_DCGyXTmDGuHKb1C0yTzjPOGC/refunds\",\"has_more\":false,\"data\":[]},\"amount_refunded\":0,\"failure_code\":null,\"failure_msg\":null,\"metadata\":{},\"credential\":{},\"description\":\"测试备注\"}},\"object\":\"event\",\"request\":\"iar_4e9mPODW5ujPqLen5OOmvL8S\",\"pending_webhooks\":0}" ) ;
new Pingxx PaySDK ( ) . submitRefund ( refund , transactionExtension , null ) ;
new Pingxx ThirdPayClient ( ) . submitRefund ( refund , transactionExtension , null ) ;
}
}