当前位置:网站首页>聊聊支付流程的设计与实现逻辑
聊聊支付流程的设计与实现逻辑
2022-07-03 17:34:00 【InfoQ】
一、业务背景

二、支付业务
1、流程拆解

- 账面管理:对于开通支付功能的用户,必须清晰的管理资金信息;比如可用,冻结,账单等;
- 交易流水:整个资金管理的流水记录,不局限于交易场景,还有充值,提现,退款等;
- 支付对接:通常流程中的支付功能都是对接第三方支付平台来实现的,所以要做好请求和报文的记录;
- 订单结构:比如在电商交易中,订单模型的管理,拆单策略等,支付的商品规格等;
2、流程时序

- 支付前:在商品下单时,构建订单模型,根据拆单规则校验库存、商品状态等,然后进行账户资金冻结,生成交易流水,此时的状态都是待支付;
- 支付对接:支付前业务模型初始化成功之后,构建第三方支付对接请求,发起付款流程,并记录相应的请求动作和参数,等待支付结果的通知;
- 支付后:根据支付结果的成功与否,执行相应的业务模型状态更新,如果支付成功则交易记录、冻结的资金、订单结构与库存等都需要做一系列更新;
3、结构设计

- 账面管理:三个核心维度,账户金额,可用余额,冻结金额;
- 交易记录:存储用户的交易动作,但是可能会产生多个交易明细,典型的场景就是购物车下单;
- 交易明细:通常因为订单拆分,从而导致交易被拆分多条明细,进而将资金支付给不同商家;
- 支付对接:请求第三方支付平台时,需要记录请求时参数,以及第三方回调通知的报文;
- 订单记录:在一笔订单中可能存在多个拆分的子单,拆分策略也很多,比如仓库,商家,品类等;
- 订单明细:管理每笔子订单的信息,下单的商品、规格、买卖双方、单价、数量、金额等;
三、关联业务

- 商品主体:维护商品各个维度的信息,并提供各种规格选项,以及基础的定价阶梯,构建商品详情描述;
- 仓储管理:订单拆单之后,需要根据商品编号去校验仓储信息,进行相应的库存冻结以及支付后的仓库发货;

- 优惠券主体:为了适配更多的业务场景,需要对优惠规则有诸多的设计,比如满减或折扣比例、按价格阶梯优惠、有效期限制等;
- 发放规则:支撑日常的运营活动,用户生命周期的维护,以及渠道流量的转化,提供用户群营销的基础能力;
四、实践总结
- 业务模型:对业务有清晰的理解,并能拆分出核心的节点,设计出相应的流程时序和数据结构;
- 事务管理:交易流程中常用TCC事务机制,即Try(预处理)、Confirm(确认)、Cancel(取消)模式;
- 加锁与重试:支付完成后发出支付成功的消息,而后进行业务更新,通常需要对处理的订单号加锁,避免消息重试机制引发数据问题;
- 资金结算:涉及金额的计算,自然要求不能出现精度损失的问题,在一次交易中必须保证每笔资金可以通过对账核验;
- 流程维护:流程本身是很难保证不出现错误的,需要在开发的时候,提供流程的可视化界面,并且支持手动维护的机制;
边栏推荐
- Host based intrusion system IDS
- [combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
- Unity notes unityxr simple to use
- Detailed explanation of common network attacks
- [combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
- Kubernetes resource object introduction and common commands (4)
- Great changes! National housing prices fell below the 10000 yuan mark
- AcWing 3438. 数制转换
- 问题随记 —— 在 edge 上看视频会绿屏
- Swm32 series Tutorial 4 port mapping and serial port application
猜你喜欢

Redis: operation commands for list type data

QT adjust win screen brightness and sound size
![Luogu: p2685 [tjoi2012] Bridge](/img/f5/f77027288a211ae466781b09ce650f.jpg)
Luogu: p2685 [tjoi2012] Bridge

Wechat applet for the first time
![[UE4] brush Arctic pack high quality Arctic terrain pack](/img/e7/bc86bd8450b0b2bdec8980a2aa1a10.jpg)
[UE4] brush Arctic pack high quality Arctic terrain pack

Vs2013 has blocked the installer, and ie10 needs to be installed

鸿蒙第四次培训

kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)

UE4 official charging resources, with a total price of several thousand

Hongmeng third training
随机推荐
AcWing 4489. 最长子序列
The third day of writing C language by Yabo people
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
Apache service suspended asynchronous acceptex failed
Free data | new library online | cnopendata complete data of China's insurance intermediary outlets
How to train mask r-cnn model with your own data
QT adjust win screen brightness and sound size
Simple use of unity pen XR grab
Golang unit test, mock test and benchmark test
Leetcode540: a single element in an ordered array
Kubernetes resource object introduction and common commands (III)
Stm32h7 Hal library SPI DMA transmission has been in busy solution
Unity notes unityxr simple to use
IntelliJ 2021.3 short command line when running applications
Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part
STM32实现74HC595控制
PHP returns 500 errors but no error log - PHP return 500 error but no error log
鸿蒙第四次培训
List of financial products in 2022
Select 3 fcpx plug-ins. Come and see if you like them