I have been dealing with payment in the past few years. I would like to share with you how to design and do the payment system through the SKR-Shop project. We first analyze some common processes of payment, find out the commonness of these payments, and then discuss the specific database design and code structure design after abstraction.

Related projects:

  • PHP version of the payment SDK
  • Go version of payment SDK- under development

The overall process of payment is as follows: a transaction is initiated to a third party, the user completes the payment through the third party, the third party tells me that the payment is successful, and I give the product purchased by the user to the user.

The seemingly simple process is handled differently by different payment institutions. Here’s a summary of some of the payments I’ve worked with

Domestic payment

The typical payment representatives in China are Alipay, wechat and banks (taking China Merchants Bank as an example). Since domestic payment methods all support payment through multiple channels, we take payment on PC as an example for simple description.

Alipay

Alipay access is the easiest kind of payment in my opinion. For the ability to pay on PC, Alipay provides “computer payment”. When the user places an order, the merchant system builds a URL according to the rules of Alipay, and the user jumps to this URL to enter the payment page of Alipay, and then completes the payment process.

After the payment is successful, Alipay will inform the merchant system of the payment success through synchronous notification and asynchronous notification, and the results of the two notification methods are credible, and the message delay of asynchronous notification is very short.

For the refund process, Alipay supports full and partial refund. In addition, it can distinguish whether it is the same refund according to the refund receipt number of the merchant so as to avoid the possibility of repeated refund. The paid refund is returned synchronously after the call and will not be notified asynchronously.

WeChat pay

Wechat does not provide real PC payment capability, but we can use [scan code payment] to achieve the purpose of computer payment. There are two modes of scan payment. Here, mode 2 is taken as an example.

Wechat calls the ordering interface to obtain the QR code link, and then users scan the code to enter the payment process. Wechat will be notified asynchronously after the payment is completed, but there is no synchronous notification here. Therefore, the front page can only check whether the transaction is paid through regular rotation training until the query is successful or the user actively closes the page.

The biggest difference between the refund process and Alipay is that there is an asynchronous notification that needs to be processed by the merchant system.

The first difference:

  1. The interface for asynchronous notification needs to handle many different types of asynchronous messages

China merchants bank,

With the rapid development of online payment in China, banks are also constantly introducing their own online payment capabilities. The leader among them is China Merchants Bank. We often use didi has this payment method, you can experience it.

Merchants pay uses bank cards, so first-time users must tie cards. So there might be an additional process of recording whether the user has tied the card, and then the public key used for the signature changes and needs to be updated periodically.

The payment experience of all CMB platforms is consistent. It will jump to THE H5 page of CMB to complete the logic. After successful payment, it will not automatically jump back to the merchant, that is, there is no synchronous notification.

The refund process is the same as Alipay, and the refund results are returned synchronously without asynchronous notification.

Second difference:

  1. Before payment, it is necessary to check whether the user has signed a contract and has a signing process

summary

Domestic online payment processes are relatively complete, access is also very easy. It should be noted that the order paid before the refund is still in the successful payment state, and will not become the refund state. Because refunds and payments are different transactions.

This is basically the general practice of online payment in China.

International payments

There are many international payment platforms, including Alipay and wechat, which are also expanding this market. I’ll make a brief summary with a few payment companies I’ve been in contact with.

WorldPay

This is a well-known international payment company, which mainly makes bank card payment. The company is located in the UK

In terms of the payment process, the requested URL is constructed according to the rules, and the payment is directly redirected to the WorldPay page through the credit card. The tricky thing here is that the first asynchronous/synchronous message notification he sends you after the payment is successful is not the basis for the payment to be successful. After confirming the successful transfer from the bank, the notice of successful payment will be given. There may also be an asynchronous notification telling you that the payment request has been rejected. The biggest headache is that the time interval between asynchronous messages of different states is measured in minutes or more

In the refund process, the status is the same as wechat, and the refund status needs to be confirmed by asynchronous message. Secondly, its difference is that it cannot confirm whether a refund has been initiated according to the merchant’s refund bill number. Therefore, as long as it requests the one-time refund interface, it will initiate a refund by default.

Third and fourth differences:

  1. There are various notification states after successful payment, which involve special processing of merchant system business process
  2. The refund does not support the merchant’s refund bill number, and the merchant needs to deal with the failure to support repeated refund

Assist

This is a payment company in Russia, which is also a dead company, see the following introduction

Its payment initiation requires building a form to post payment data to it. After success, it will jump to its payment page, and the user can complete the payment. For synchronous notification, it requires the user to manually trigger the jump back to the merchant, much like the logic of merchants, synchronization is only to return and does not actually inform the payment result. Asynchronous notifications really tell you about payment status. What’s disgusting is that you have to pass in the product information in the specified format, which is used for partial refunds.

As for refund, just like WorldPay, refund receipt number of merchants is not supported. Therefore, the prevention department may design its own system. And if it is a partial refund, the designated refund goods need to be passed in, which will lead to a very embarrassing situation: the amount of partial refund does not correspond to the amount of any goods, and the refund will fail.

Fifth difference:

  1. For partial refund, the commodity information of partial refund should be passed in, and the amount should be consistent

Doku

Let’s talk about Doku, the Payment agency in Indonesia. Since credit cards are not widely used in Indonesia, its online payment system offers a way to pay for goods in a supermarket.

What is superbusiness payment? When users place an order online, they are given a QR code or bar code. The user takes the barcode to the supermarket (711, familymart), scans the code by the cashier, pays cash to the supermarket, and completes the payment process.

The problem with this approach is that the user does not pay for a long time, resulting in the order being closed for a long time before the payment. It does a lot of damage to the business process and the user experience.

As for refund, online automatic refund cannot be supported due to the existence of the payment method of supermarket. It is necessary to collect the user’s bank card information manually and then complete the transfer operation. It was very painful.

Sixth difference:

  1. There is no online payment, only to obtain the payment code, the refund needs to be manually operated

AmazonPay

Amazon, very similar to Alipay. It provides an integrated wallet process.

To pay, build a URL and go to Amazon. It also provides an authorization model that allows payment to be made at the merchant end without having to jump to Amazon.

After the payment is successful, the synchronization will also jump, and the content of the synchronization notice can be used as the basis to judge whether the payment is successful. After actual inspection, the asynchronous notification will arrive with a slight delay of about 10 seconds.

Refund also supports merchant refund number can rely on this to prevent duplication. But the refund status is also based on asynchrony.

conclusion

There are also some international payments, such as PayPal, GooglePay, PayTM and other well-known payment institutions, which are not introduced, because basically their processes are also in the above model. Our subsequent code structure design and database design are based on satisfying the above payment models.

Finally, I’ll give you a brain map, a list of questions you need to know when accessing a payment service

Next preview: Payment Database and Code Structure Design

These are some business designs that some of our friends have been thinking about in their spare time. If there is something wrong or not perfect, we hope you can comment more and learn from each other and make progress

Project address: github.com/skr-shop/ma…

Brief introduction of SKR-SHOP project members

In no particular order, lexicographical order

nickname Introduction to the Personal blog
AStraw Graduate entrepreneur, now engaged in shopping mall back-end research and development work in xiaomi Technology overseas shopping mall group ——–
Dayu Payment open source author and server-side developer dayutalk.cn
lwhcv I used to work for Baidu/Rong360, and now I am engaged in the back-end research and development of mall in overseas mall group of Miui Technology ——–
TIGERB Author of EasyPHP framework, with working experience in A/B/C round of e-commerce start-up companies, now engaged in shopping mall back-end research and development work in Overseas shopping mall group of Miui Technology TIGERB.cn