Qinghai long cloud dark snow mountain, lonely city overlooking Yumen Pass. Huangsha hundred battles wear gold armor, not broken Loulan end not also. -- Wang Changling from the ArmyCopy the code

Noun explanation

noun explain
Application (Access Party) Business parties using payment gateways, such as e-commerce business applications and advertising business applications
Method of payment The way users choose to pay, such as wechat scan code payment and wechat APP payment
The payment channel Entities that realize payment are various third-party payment platforms, such as wechat, Alipay, Pudong Development Bank, etc
Pay the routing According to the payment method selected by the user, the most appropriate payment channel to complete the payment operation is determined. If the user chooses wechat scan code payment, the wechat official channel API can be realized, or the wechat scan CODE API of SPD Bank channel can be realized

Simplified architecture

Payment gateway

Entry of core functions of payment, such as payment, refund, transfer, query of payment results, query of refund results and other functions

Pay the routing

Payment route Automatically selects an appropriate third-party payment channel according to the configuration rules to complete the payment function

Pay the callback

Receive callback notification of third-party payment results and be responsible for notifying access party

Payment schedule

The payment scheduling service will take the initiative to query the payment result to the third party periodically in case of failure to obtain the result callback notification from the third party for various reasons

Pay check

Responsible for reconciliation with third party channels and provide statement to access party for download

The payment channel

Wechat, Alipay, UnionPay and other payment channels docking management

The key logic

Design instructions for some key logic

Intelligent routing

Payment channels can be automatically selected according to the rate, payment success rate, marketing logic and so on. Here provides a simple implementation of route switching through manual configuration

  1. A routing mapping table is used to associate access parties with payment channels. Different payment modes can use different payment channels
  2. One payment method can also be configured with multiple payment channels, and the first payment channel can be selected by configuring priority

  1. Related tables

Payment process

  1. In the third party payment channel asynchronously notifies the payment result, the payment callback service, after processing the local transaction, puts the payment result into MQ and the independent service consumer notifies the business party
  2. The payment scheduling service can be added to proactively inquire to the third party for orders that have not received payment asynchronous notification within a certain period of time
Interface to retry
  1. The callback interface provided by the access party may be unstable when the transaction result is notified asynchronously, and the retry function must be implemented
  2. The access party shall ensure idempotent
  3. Delay queue or Retry framework
A distributed lock
  1. Idempotency needs to be taken into account for payment, refund, and other requests that do not allow repeated operations
  2. Distributed lock implementations can be either A ZooKeeper-based Curator or a Redis-based Redisson?