Project

General

Profile

Actions

New Function #79

closed

PG 결제 (payment)

Added by Deca Park about 1 year ago. Updated 8 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Start date:
07/28/2023
Due date:
% Done:

0%

Estimated time:
Spent time:

Description

1.[Scheduler] VBank Payment Expire Scheduler

1.reference
  - non-violent #9874-note#18
2.crontab
  - execute per 1 hour
3.logic
  1) SELECT st_order_payment with payment_status = 'PS20' (wait deposit)
    a) get va_due_date
    b) if current datetime > va_due_date
       b-1) UPDATE st_order_payment
         - payment_status = 'PS22' (deposit expire)
         - mod_date / mod_user_no = NULL
   * define fee_payment_status value as constant

2.[API] VBank deposit complete process (가상계좌 웹훅)

1.document
  https://docs.tosspayments.com/guides/learn/virtual-account-webhook

2.make Webhook endpoint to receive DEPOSIT_CALLBACK event payload from PG
  1) URL: POST {domain}/hook
    - permitAll (don't check authentication)

3.DEPOSIT_CALLBACK Webhook event data (JSON) from PG
    [example]
    {
      createdAt: '2023-05-23T14:42:26.000000',
      secret: 'ps_Z1aOwX7K8mYpalqAGRwj8yQxzvNP',
      orderId: '3f9c765d-60ed-4735-8af5-ab9d1142a3e8',
      status: 'DONE',
      transactionKey: '83B3CD71DF004878066FEDCB7C21E775'
    }

4.process Logic
  1) SELECT DB (st_order_payment)
      condition: order_no = {orderId param}
  2) if No data OR {pg_secret} != {secret param}, SKIP
      - response status(200) ok

  3) if {pg_secret} = {secret param}
     a) if {status param} = 'DONE'
        UPDATE DB (st_order_payment)
        - payment_status = 'PS21', va_proc_date = {current date}
     b) if {status param} = 'WAITING_FOR_DEPOSIT'
        UPDATE DB (st_order_payment)
        - payment_status = 'PS23', va_proc_date = {current date}
  4) response status(200) ok

3.[Common] PG payment cancellation (결제취소)  function

  • it's called on API and ADMIN both

1.parameters
  1) order no
  2) user_seq
  3) cancel reason

2.Process
  0) SELECT DB (st_order_payment) (with order_no = {order no param})
    a) if No data OR payment_key value is NUL(empty), SKIP
    b) if not, continue
  1) call PG payment cancel API
    a) document
      - https://docs.tosspayments.com/reference#%EA%B2%B0%EC%A0%9C-%EC%B7%A8%EC%86%8C
    b) URL: POST /v1/payment/{paymentKey}/cancel
      - {paymentKey} : st_order_payment.payment_key
    c) header
       - Authorization: {same with pg confirm API}
    d) RequestBody
      d-1) cancelReason : {cancel reason param}
      d-2) cancelAmount : don't set because cancel amount is total amount
      d-3) refundReceiveAccount object
        - if {st_order_payment.payment_method} = 'PV02' (VBank), set (it not, don't set)
        d-3-1) bank : {st_order_payment.refund_bank_code}
        d-3-2) accountNumber : {refund_account_number}
        d-3-3) holderName : {refund_holder_name}

     [example]
     curl --request POST \
      --url https://api.tosspayments.com/v1/payments/5zJ4xY7m0kODnyRpQWGrN2xqGlNvLrKwv1M9ENjbeoPaZdL6/cancel \
      --header 'Authorization: Basic dGVzdF9za196WExrS0V5cE5BcldtbzUwblgzbG1lYXhZRzVSOg==' \
      --header 'Content-Type: application/json' \
      --header 'Idempotency-Key: e9b779ed-3541-4b6e-aa95-88f710689a68' \
      --data '{"cancelReason":"고객 변심"}'

  2) if cancel API is success
    a) UPDATE st_order_payment
      condition: order_no = {order_no param}
      set :
        payment_status = 'PS11'
        cancel_amount = {payment_amount}, cancel_reason = {decided by process type}
        cancel_proc_date = {current date}, cancel_user_seq = {decided by process type}

  3) if cancel API is fail
    a) return PG error_code / error_msg without DB UPDATE

4.[API] 스마트오더 주문 취소 (store order cancel) - Change

1.URL: POST /api/store_order_cancel
2.Response (Add)
  1) order_no : {order_no}
  2) pg_error_code / pg_error_msg : if PG cancel API is fail, set it.

3.process logic
  1) call Common PG payment cancellation (결제취소) function 
    a) parameter
      - order no : {order_no param}
      - user_seq : {user_seq of id param}
      - cancel reason : {code name of cancel_reason_type param - grp_code: SD}
  2) if PG cancel API is fail
    - response error (500) with order_no / pg_error_code / pg_error_msg
  3) if PG cancel API is success
    a) UPDATE DB (st_order)
      - same with previous definition

Actions

Also available in: Atom PDF