{
  "name": "결제 관리 플로우",
  "description": "결제 등록 → 완료 처리 → 명세서 조회 → 취소 → 환불 플로우 테스트",
  "version": "1.0",
  "config": {
    "baseUrl": "",
    "timeout": 30000,
    "stopOnFailure": true
  },
  "variables": {
    "user_id": "{{$env.FLOW_TESTER_USER_ID}}",
    "user_pwd": "{{$env.FLOW_TESTER_USER_PWD}}"
  },
  "steps": [
    {
      "id": "login",
      "name": "로그인",
      "method": "POST",
      "endpoint": "/api/v1/login",
      "body": {
        "user_id": "{{user_id}}",
        "user_pwd": "{{user_pwd}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.access_token": "@isString"
        }
      },
      "extract": {
        "token": "$.access_token"
      }
    },
    {
      "id": "list_payments",
      "name": "결제 목록 조회",
      "method": "GET",
      "endpoint": "/api/v1/payments",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "queryParams": {
        "page": 1,
        "per_page": 10
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      }
    },
    {
      "id": "create_payment",
      "name": "결제 등록",
      "method": "POST",
      "endpoint": "/api/v1/payments",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "subscription_id": 1,
        "amount": 99000,
        "payment_method": "card",
        "billing_name": "테스트 결제",
        "billing_email": "test@example.com"
      },
      "expect": {
        "status": [200, 201],
        "jsonPath": {
          "$.success": true
        }
      },
      "extract": {
        "payment_id": "$.data.id"
      },
      "continueOnFailure": true
    },
    {
      "id": "get_payment_detail",
      "name": "결제 상세 조회",
      "method": "GET",
      "endpoint": "/api/v1/payments/{{create_payment.payment_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true,
          "$.data.id": "@isNumber"
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "complete_payment",
      "name": "결제 완료 처리",
      "method": "POST",
      "endpoint": "/api/v1/payments/{{create_payment.payment_id}}/complete",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "transaction_id": "TXN_{{$timestamp}}",
        "pg_response": {
          "code": "0000",
          "message": "성공"
        }
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "verify_completed",
      "name": "완료 상태 확인",
      "method": "GET",
      "endpoint": "/api/v1/payments/{{create_payment.payment_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true,
          "$.data.status": "completed"
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "get_statement",
      "name": "결제 명세서 조회",
      "method": "GET",
      "endpoint": "/api/v1/payments/{{create_payment.payment_id}}/statement",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "cancel_payment",
      "name": "결제 취소 요청",
      "method": "POST",
      "endpoint": "/api/v1/payments/{{create_payment.payment_id}}/cancel",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "reason": "테스트 취소",
        "cancel_type": "full"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "create_payment_for_refund",
      "name": "환불 테스트용 결제 등록",
      "method": "POST",
      "endpoint": "/api/v1/payments",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "subscription_id": 1,
        "amount": 50000,
        "payment_method": "card",
        "billing_name": "환불 테스트",
        "billing_email": "refund@example.com"
      },
      "expect": {
        "status": [200, 201],
        "jsonPath": {
          "$.success": true
        }
      },
      "extract": {
        "refund_payment_id": "$.data.id"
      },
      "continueOnFailure": true
    },
    {
      "id": "complete_refund_payment",
      "name": "환불 테스트용 결제 완료",
      "method": "POST",
      "endpoint": "/api/v1/payments/{{create_payment_for_refund.refund_payment_id}}/complete",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "transaction_id": "TXN_REFUND_{{$timestamp}}",
        "pg_response": {
          "code": "0000",
          "message": "성공"
        }
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "request_refund",
      "name": "환불 요청",
      "method": "POST",
      "endpoint": "/api/v1/payments/{{create_payment_for_refund.refund_payment_id}}/refund",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "body": {
        "refund_amount": 50000,
        "reason": "테스트 환불",
        "refund_method": "original"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true
        }
      },
      "continueOnFailure": true
    },
    {
      "id": "verify_refunded",
      "name": "환불 상태 확인",
      "method": "GET",
      "endpoint": "/api/v1/payments/{{create_payment_for_refund.refund_payment_id}}",
      "headers": {
        "Authorization": "Bearer {{login.token}}"
      },
      "expect": {
        "status": [200],
        "jsonPath": {
          "$.success": true,
          "$.data.status": "refunded"
        }
      },
      "continueOnFailure": true
    }
  ]
}
