当前位置:网站首页>The server prevents repeated payment of orders
The server prevents repeated payment of orders
2022-06-11 14:58:00 【Ant】
The server prevents repeated payment of orders
The figure above shows a simplified order placing process , The first is to submit the order , Then there's the payment . If you pay , It's usually through the payment gateway ( Payment center ), Then the payment center and the third party payment channel ( WeChat 、 Alipay 、 UnionPay ) Interaction , After the payment is successful , Asynchronous notification to payment center , The payment center updates the status of its own payment order , Then inform the business application , Each business updates its order status .
In this process, we often encounter the problem of dropping orders , Whether it's timeout or not receiving callback notification , Or the program itself reports an error , In short, for various reasons , Didn't receive the notice as scheduled and handle the follow-up logic correctly, etc , Will cause the user to pay successfully , But the order status on the server side has not been updated , At this time, there may be complaints , Or users pay repeatedly .
from ③⑤ The resulting drop is called external drop , from ④⑥ The loss of orders caused by this is called internal loss of orders
How to prevent missing orders
Add intermediate status
Payment orders add an intermediate state “ In the payment ”, When the same order goes to pay , Check to see if the status is “ In the payment ” Payment flow , Of course, pay (prepay) Put a lock on it . After the payment is completed, when the payment flow status is updated, it will be changed to “ Successful payment ” state .
Play the role of locking
Define timeout
The payment center has to define a time-out ( such as :30 second ), If the payment is not received within this time frame, the callback will be successful , Then the interface should be called to actively query the payment result , such as 10s、20s、30s Check it out , If no result is found within the maximum number of queries , Exception handling should be done .
Synchronize payment results
After the payment center receives the payment result , Synchronize the results to the business system , Can send MQ, It can also be called directly , If you call it directly, try again ( such as :SpringBoot Retry).
Consider interface idempotency
Whether it's payment centers , Or business applications , When receiving payment result notification, we should consider the idempotency of the interface , Messages are processed only once , The rest is ignored
Active inquiry of payment results
Business applications should also take the initiative to query payment results over time , Overtime active query can put these payment orders into a table when initiating payment , Scan with timed tasks .
In order to prevent duplicate order submission , You can do this :
- When you create an order , Use order information to calculate a hash value
- Judge redis If there key, If yes, duplicate submission is not allowed
- If not, a new key, Put it in redis Set an expiration time in
- Then create the order
In fact, the same operation cannot be repeated for a period of time
Reference material
Sharing plans
Blog content will be synchronized to Tencent cloud + Community , Invite everyone to join us :https://cloud.tencent.com/
license agreement
In this paper A signature - Noncommercial use - Share in the same way 4.0 The international license agreement , Reprint please indicate the source .
边栏推荐
- Lippon instrument software intern interview
- [team learning] task06:for, if, and while
- Nexus of repository manager
- 线程池的七个参数与拒绝策略
- 思科瑞递交科创板注册:拟募资6亿 年营收2.22亿
- Hashicopy之nomad应用编排方案01
- In depth research and analysis report on global and Chinese smart lamp Market
- System. out. What should I pay attention to when using the println () method
- [verification of SystemVerilog] ~ test platform, hardware design description, excitation generator, monitor and comparator
- After many years of digital transformation projects, the main architects are desperate: outsourcing should not have been used at the beginning!
猜你喜欢
![[process blocks and methods of SystemVerilog] ~ domain, always process block, initial process block, function, task, life cycle](/img/c7/ff28df36b8d5dda704aa829dd5264f.png)
[process blocks and methods of SystemVerilog] ~ domain, always process block, initial process block, function, task, life cycle

How to play seek tiger, which has attracted much attention in the market?

Illustration of tiger international quarterly report: revenue of USD 52.63 million continued to be internationalized

Station B executives interpret the financial report: the epidemic has no impact on the company's long-term development, and the video trend is irresistible

Qualcomm WLAN framework learning (29) -- 6GHz overview

C language simple webserver

uniapp设置页面跳转效果 - navigateTo切换效果 - 全局animationType动画

大道至簡 | 設計 ViT 到底怎麼配置Self-Attention才是最合理的?

19. 二叉搜索樹的插入删除修剪

树莓派获得网络安装系统功能,无需借助其他设备
随机推荐
Simple C language address book
North China pushed Yale hard, MIT won the first place in a row, and the latest 2023qs world university ranking was released
MySQL create table error 1067 - invalid default value for 'update_ time‘
Summary of some classic embedded C interview questions
In depth research and analysis report on global and Chinese gas monitor market
C语言简易版webserver
浙江大学搞出了一款无人机,自动规避障碍,像鸟一样穿过树林,真正的蜂群来了...
After many years of digital transformation projects, the main architects are desperate: outsourcing should not have been used at the beginning!
【Azure 应用服务】NodeJS Express + MSAL 实现API应用Token认证(AAD OAuth2 idToken)的认证实验 -- passport.authenticate()
Explain the kubernetes package management tool Helm
19. 二叉搜索樹的插入删除修剪
线程池的七个参数与拒绝策略
Repository Manager之Nexus配置yum仓库
Zhejiang University has developed a UAV, which can automatically avoid obstacles and walk through the woods like a bird. The real swarm is coming
化“被动”为“主动”,如何构建安全合规的智能产品 | Q推荐
Live800: several ways for intelligent customer service to improve customer experience
In depth research and analysis report on global and Chinese octamethylcyclotetrasiloxane (D4) market
[SystemVerilog interface] ~ interface
01discussion on Tekton
Hamad application layout scheme 05 of hashicopy (visit the web page)