[Note 6 - payment and order module] independently completed the development of enterprise Java e-commerce website (server side) from 0

Payment module

In the actual development work, we often encounter the following scenarios: one payment module, one Order module, has certain dependence, one colleague is responsible for the payment module, and another colleague is responsible for the Order module, but when developing the payment module, we need to rely on the relevant classes, methods, or tool classes of the Order module. These have not been developed yet, and we cannot see a complete Order business logic, You may only get the Order class of the Order, but it can't affect the parallel development of our back-end. Just like the parallel development between the front-end and the back-end, there are also parallel development between the back-end. Sometimes the back-end projects are very large. What should you do at this time? This chapter's payment module and the next section's Order module need to simulate this scenario to improve their competence in the abstract development of cross business Development ability, which is very important when developing large-scale projects, and is a very important standard to measure an excellent developer. For example, when interviewing, you often ask such questions to judge whether the interviewee has experience or potential in developing large-scale projects. At the same time, there is an important purpose. In Order to consider the later advanced courses, you will In the evolution of microservices and dubbo services, we can only get one interface and one class. We can't see anything. The specific implementation is in the remote rpc server. The development of this scenario requires certain abstract development capability across businesses

Database table design

Payment information sheet

CREATE TABLE' mmall_ pay_ info' (
'id' int(11) NOT NULL AUTO_ INCREMENT,
'user_ id' int(11) DEFAULT NULL COMMENT . user id',
'order_ no' bigint(20) DEFAULT NULL COMMENT 'Order number'
'pay_ platform' int(10) DEFAULT NULL COMMENT ' payment platform:1-Alipay,2-WeChat',
'platform_ number' varchar (200) DEFAULT NULL COMMENT ' Alipay pays serial numbers' ,
'platform_ _status' varchar(20) DEFAULT NULL COMMENT ' Alipay payment status' ,
'create_ time' datetime DEFAULT NULL COMMENT ' Creation time,
'update_ time' datetime DEFAULT NULL COMMENT ' Update time',
PRIMARY KEY ( id')
) ENGINE= InnoDB AUTO_ INCREMENT=53 DEFAULT CHARSET=utf8

function

  • Alipay docking

  • Payment callback

  • Query payment status

Alipay docking docking process

1, first you have to have a Alipay account.

2. To create an application, because we develop it by ourselves or our company, we need to create a self-developed application (self-developed application is divided into web mobile application, AR, life number and small program). In the process of creating an application:

a) You need a user name and a logo (application icon, because I learn by myself, and can design one for free on the online website). After filling in, confirm to create it. Then you can see the created application in the application list. Generally, you will go to the next page to fill in more details of the application

b) Go to the following page

c) As for the application gateway and the authorized callback address, the simple payment interface does not need to configure these two information. To put it simply, the application gateway is used to receive word-of-mouth or life number information, and the authorized callback address is authorized by the third party or the user information. If it is not used, it can not be configured!

d) Let's wait for the audit (say it's a working day)

Knowledge points involved

  • Familiar with Alipay docking core document, tune Alipay payment function official Demo
  • Analysis of Alipay SDK docking source code
  • RSA1 and RSA2 verify signature and encryption
  • Avoid repeated notification and data validation of Alipay
  • natapp Internet penetration and tomcat remote debug
  • Generate QR code and persist it to image server

interface design

[foreground]

1. payment

/order/pay.do

http://localhost:8080/order/pay.do?orderNo=1485158676346

request

orderNo

response

success

{
    "status": 0,
    "data": {
        "orderNo": "1485158676346",
        "qrPath": "http://img.happymmall.com/qr-1492329044075.png"
    }
}

2. Query order payment status

/order/query_order_pay_status.do

http://localhost:8080/order/query_order_pay_status.do?orderNo=1485158676346

request

orderNo

response

success

{
    "status": 0,
    "data": true
}

3. Alipay callback

Refer to Alipay callback document:
https://support.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.mFogPC&treeId=193&articleId=103296&docType=1

/order/alipay_callback.do

request

HttpServletRequest

response

success

success

Order module

Database table design

Order form

CREATE TABLE mmall_ order'(
'id' int(11) NOT NULL AUTO_ INCREMENT COMMENT 'Order id',
'order_ no'   bigint(20) DEFAULT NULL COMMENT 'Order number',
'user_ id'  int(11) DEFAULT NULL COMMENT 'user id' ,
'shipping_ id' int(11) DEFAULT NULL,
'payment' decimal(20,2) DEFAULT NULL COMMENT ' Actual payment amount, unit: yuan, two decimal places reserved',
'payment_ type'  int(4) DEFAULT NULL COMMENT ' Payment type, 1-Online payment' ,
'postage'  int(10) DEFAULT NULL COMMENT ' Freight, unit: Yuan',
'status' int(10) DEFAULT NULL COMMENT 'Order status:0-Cancelled-10- Unpaid, 20-Paid, 40-Shipped, 50- Transaction success, 60- Transaction closed",
'payment_time' datetime DEFAULT NULL COMMENT ' Payment time',
'send_ time' datetime DEFAULT NULL COMMENT ' Delivery time,
'end. time' datetime DEFAULT NULL COMHENT 'Transaction completion time',
'close_ time' datetine DEFAULT NULL COMMENT 'Transaction closing time',
'create_ _time' datetime DEFAULT NULL COMMENT ' Creation time",
'update_ time' datetime DEFAULT NULL COMMENT ' Update time' ,
PRIHARY KEY ( id'),
UNIQUE KEY" order_ _no_ index" (order_ no') USING BTREE
) ENGINE-InnoDB AUTO INCREMENT-103 DEFAULT CHARSET=utf8

Order Details

CREATE TABLE: mmall_ order_ item'(
'id' int(11) NOT NULL AUTO_ ,INCREMENT COMMENT 'Booking form id' ,
'user_ id'  int(11) DEFAULT NULL,
'order_ no' bigint(20) DEFAULT NULL,
'product_ id' int(11) DEFAULT NULL COMNENT .Shang Jing id',
'product_ name' varchar(100) DEFAULT NULL COMMENT ' Trade name',
'product_ image' varchar(500) DEFAULT NULL COMNENT ' Product image address,
'current _unit_ price' decimal(20,2) DEFAULT NULL COMNENT 'Unit price of goods when generating order, unit is yuan, two decimal places are reserved' , .
'quantity' int(10) DEFAULT NULL COMMENT Quantity of commodities
'total_ price' decimal(20,2) DEFAULT NULL COMMENT "The total price of the goods, in Yuan,Keep two decimal places' ,
'create_ time' datetime DEFAULT NULL,
'update_ time' datetime DEFAULT NULL,
PRIMARY KEY ( id'),
KEY 'order_ no_ index'  ('order. no' ) USING BTREE,
KEY 'order_ no_user_ id_ index' ('user_ _id' ,'order_ no') USING BTREE
) ENGINE: =InnoDB AUTO_ INCREMENT-113 DEFAULT CHARSET=utf8

function

Foreground function

Create order
Commodity information
Order list
Order details
Cancellation of order

Background function

Order list
Order search
Order details
Order shipment

Knowledge points involved

  • Avoid security loopholes such as horizontal and vertical ultra vires in business logic
  • Design practical, safe and extensible constant and enumeration classes
  • Order number generation rule, order strictness judgment
  • Practice between POJO and VO
  • mybatis bulk insert

interface design

[foreground]

1. Create order

/order/create.do

Reference to the existing receiving address id
http://localhost:8080/order/create.do?shippingId=5

request

shippingId

response

success

{
    "status": 0,
    "data": {
        "orderNo": 1485158223095,
        "payment": 2999.11,
        "paymentType": 1,
        "postage": 0,
        "status": 10,
        "paymentTime": null,
        "sendTime": null,
        "endTime": null,
        "closeTime": null,
        "createTime": 1485158223095,
        "orderItemVoList": [
            {
                "orderNo": 1485158223095,
                "productId": 2,
                "productName": "oppo R8",
                "productImage": "mainimage.jpg",
                "currentUnitPrice": 2999.11,
                "quantity": 1,
                "totalPrice": 2999.11,
                "createTime": null
            }
        ],
        "shippingId": 5,
        "shippingVo": null
    }
}

2. Get the product information of the order

/order/get_order_cart_product.do

http://localhost:8080/order/get_order_cart_product.do

request

nothing

response

success

{
    "status": 0,
    "data": {
        "orderItemVoList": [
            {
                "orderNo": null,
                "productId": 1,
                "productName": "iphone7",
                "productImage": "mmall/aa.jpg",
                "currentUnitPrice": 7999,
                "quantity": 10,
                "totalPrice": 79990,
                "createTime": ""
            }
        ],
        "imageHost": "http://img.happymmall.com/",
        "productTotalPrice": 79990
    }
}

3. order List

http://localhost:8080/order/list.do?pageSize=3

/order/list.do

request

pageSize(default=10)
pageNum(default=1)

response

success

{
  "status": 0,
  "data": {
    "pageNum": 1,
    "pageSize": 3,
    "size": 3,
    "orderBy": null,
    "startRow": 1,
    "endRow": 3,
    "total": 16,
    "pages": 6,
    "list": [
      {
        "orderNo": 1485158676346,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:36",
        "orderItemVoList": [
          {
            "orderNo": 1485158676346,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:36"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      },
      {
        "orderNo": 1485158675516,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675516,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      },
      {
        "orderNo": 1485158675316,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675316,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      }
    ],
    "firstPage": 1,
    "prePage": 0,
    "nextPage": 2,
    "lastPage": 6,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
      1,
      2,
      3,
      4,
      5,
      6
    ]
  }
}

4. Order detail s

http://localhost:8080/order/detail.do?orderNo=1480515829406

/order/detail.do

request

orderNo

response

success

{
  "status": 0,
  "data": {
    "orderNo": 1480515829406,
    "payment": 30000.00,
    "paymentType": 1,
    "paymentTypeDesc": "Online payment",
    "postage": 0,
    "status": 10,
    "statusDesc": "Unpaid",
    "paymentTime": "",
    "sendTime": "",
    "endTime": "",
    "closeTime": "",
    "createTime": "2016-11-30 22:23:49",
    "orderItemVoList": [
      {
        "orderNo": 1480515829406,
        "productId": 1,
        "productName": "iphone7",
        "productImage": "mainimage.jpg",
        "currentUnitPrice": 10000.00,
        "quantity": 1,
        "totalPrice": 10000.00,
        "createTime": "2016-11-30 22:23:49"
      },
      {
        "orderNo": 1480515829406,
        "productId": 2,
        "productName": "oppo R8",
        "productImage": "mainimage.jpg",
        "currentUnitPrice": 20000.00,
        "quantity": 1,
        "totalPrice": 20000.00,
        "createTime": "2016-11-30 22:23:49"
      }
    ],
    "imageHost": "http://img.happymmall.com/",
    "shippingId": 3,
    "receiverName": "geely",
    "shippingVo": {
      "receiverName": "geely",
      "receiverPhone": "0100",
      "receiverMobile": "186",
      "receiverProvince": "Beijing",
      "receiverCity": "Beijing",
      "receiverDistrict": "Changping District",
      "receiverAddress": "Matrix cell",
      "receiverZip": "100000"
    }
  }
}

5. Cancel the order

http://localhost:8080/order/cancel.do?orderNo=1480515829406

/order/cancel.do

request

orderNo

response

success

{
  "status": 0
}

[background]

1. order List

http://localhost:8080/manage/order/list.do?pageSize=3

/manage/order/list.do

request

pageSize(default=10)
pageNum(default=1)

response

success

{
  "status": 0,
  "data": {
    "pageNum": 1,
    "pageSize": 3,
    "size": 3,
    "orderBy": null,
    "startRow": 1,
    "endRow": 3,
    "total": 16,
    "pages": 6,
    "list": [
      {
        "orderNo": 1485158676346,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:36",
        "orderItemVoList": [
          {
            "orderNo": 1485158676346,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:36"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "shippingVo": null
      },
      {
        "orderNo": 1485158675516,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675516,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      },
      {
        "orderNo": 1485158675316,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675316,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      }
    ],
    "firstPage": 1,
    "prePage": 0,
    "nextPage": 2,
    "lastPage": 6,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
      1,
      2,
      3,
      4,
      5,
      6
    ]
  }
}

2. Query by order number

http://localhost:8080/manage/order/search.do?orderNo=1480515829406

/manage/order/search.do

request

orderNo

response

success

{
  "status": 0,
  "data": {
    "pageNum": 1,
    "pageSize": 3,
    "size": 3,
    "orderBy": null,
    "startRow": 1,
    "endRow": 3,
    "total": 16,
    "pages": 6,
    "list": [
      {
        "orderNo": 1485158676346,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:36",
        "orderItemVoList": [
          {
            "orderNo": 1485158676346,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:36"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "shippingVo": null
      },
      {
        "orderNo": 1485158675516,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675516,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      },
      {
        "orderNo": 1485158675316,
        "payment": 2999.11,
        "paymentType": 1,
        "paymentTypeDesc": "Online payment",
        "postage": 0,
        "status": 10,
        "statusDesc": "Unpaid",
        "paymentTime": "2017-02-11 12:27:18",
        "sendTime": "2017-02-11 12:27:18",
        "endTime": "2017-02-11 12:27:18",
        "closeTime": "2017-02-11 12:27:18",
        "createTime": "2017-01-23 16:04:35",
        "orderItemVoList": [
          {
            "orderNo": 1485158675316,
            "productId": 2,
            "productName": "oppo R8",
            "productImage": "mainimage.jpg",
            "currentUnitPrice": 2999.11,
            "quantity": 1,
            "totalPrice": 2999.11,
            "createTime": "2017-01-23 16:04:35"
          }
        ],
        "imageHost": "http://img.happymmall.com/",
        "shippingId": 5,
        "receiverName": "geely",
        "shippingVo": null
      }
    ],
    "firstPage": 1,
    "prePage": 0,
    "nextPage": 2,
    "lastPage": 6,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
      1,
      2,
      3,
      4,
      5,
      6
    ]
  }
}

3. Order details

http://localhost:8080/manage/order/detail.do?orderNo=1480515829406

/manage/order/detail.do

request

orderNo

response

success

{
  "status": 0,
  "data": {
    "orderNo": 1480515829406,
    "payment": 30000.00,
    "paymentType": 1,
    "paymentTypeDesc": "Online payment",
    "postage": 0,
    "status": 10,
    "statusDesc": "Unpaid",
    "paymentTime": "",
    "sendTime": "",
    "endTime": "",
    "closeTime": "",
    "createTime": "2016-11-30 22:23:49",
    "orderItemVoList": [
      {
        "orderNo": 1480515829406,
        "productId": 1,
        "productName": "iphone7",
        "productImage": "mainimage.jpg",
        "currentUnitPrice": 10000.00,
        "quantity": 1,
        "totalPrice": 10000.00,
        "createTime": "2016-11-30 22:23:49"
      },
      {
        "orderNo": 1480515829406,
        "productId": 2,
        "productName": "oppo R8",
        "productImage": "mainimage.jpg",
        "currentUnitPrice": 20000.00,
        "quantity": 1,
        "totalPrice": 20000.00,
        "createTime": "2016-11-30 22:23:49"
      }
    ],
    "imageHost": "http://img.happymmall.com/",
    "shippingId": 3,
    "receiverName": "geely",
    "shippingVo": {
      "receiverName": "geely",
      "receiverPhone": "0100",
      "receiverMobile": "186",
      "receiverProvince": "Beijing",
      "receiverCity": "Beijing",
      "receiverDistrict": "Changping District",
      "receiverAddress": "Matrix cell",
      "receiverZip": "100000"
    }
  }
}

4. Order delivery

http://localhost:8080/manage/order/send_goods.do?orderNo=1480515829406

/manage/order/send_goods.do

request

orderNo

response

success

{
  "status": 0,
  "data": "Shipment is successful"
}

Tags: Java Database Dubbo Mobile SDK

Posted on Mon, 10 Feb 2020 23:57:38 -0800 by computerzworld