Skip to content

Commit

Permalink
Rename attributes of pay_with_card API (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking13 authored Sep 26, 2023
1 parent 75e2ff9 commit 4ceace5
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 76 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## Unreleased

## v2.3.0 (2023/09/26)

- 카드 결제 기능 추가
([#249](https://github.com/ryanking13/SRT/pull/249))

## v2.2.0 (2023/08/22)

- 예약 대기 기능 추가
([#247](https://github.com/ryanking13/SRT/pull/247))

## v2.1.0 (2023/08/15)

- [SRT 열차운행 조정 알림](https://etk.srail.kr/cms/article/view.do?postNo=554&pageId=TK0502000000)에 따른 신규 정차역 코드 및 이름 추가.
Expand Down
18 changes: 9 additions & 9 deletions SRT/srt.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ def pay_with_card(
reservation: SRTReservation,
number: str,
password: str,
card_validation_number: str,
card_expire_date: str,
card_installment: int = 0,
validation_number: str,
expire_date: str,
installment: int = 0,
card_type: str = "J",
) -> bool:
"""결제합니다.
Expand All @@ -595,9 +595,9 @@ def pay_with_card(
reservation (:class:`SRTReservation`): 예약 내역
number (str): 결제신용카드번호 (하이픈(-) 제외)
password (str): 카드비밀번호 앞 2자리
card_validation_number (str): 생년월일 (card_type이 J인 경우) || 사업자번호 (card_type이 S인 경우)
card_expire_date (str): 카드유효기간(YYMM)
card_installment (int): 할부선택 (0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24)
validation_number (str): 생년월일 (card_type이 J인 경우) || 사업자번호 (card_type이 S인 경우)
expire_date (str): 카드유효기간(YYMM)
installment (int): 할부선택 (0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24)
card_type (str): 카드타입 (J : 개인, S : 법인)
Returns:
Expand All @@ -616,18 +616,18 @@ def pay_with_card(
"totNewStlAmt": reservation.total_cost, # 총 신규 결제금액
"athnDvCd1": card_type, # 카드타입 (J : 개인, S : 법인)
"vanPwd1": password, # 카드비밀번호 앞 2자리
"crdVlidTrm1": card_expire_date, # 카드유효기간(YYMM)
"crdVlidTrm1": expire_date, # 카드유효기간(YYMM)
"stlMnsCd1": "02", # 결제수단코드1: (02:신용카드, 11:전자지갑, 12:포인트)
"rsvChgTno": "0", # 예약변경번호 (0 고정값인듯)
"chgMcs": "0", # 변경마이크로초 (0고정값인듯)
"ismtMnthNum1": card_installment, # 할부선택 (0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24)
"ismtMnthNum1": installment, # 할부선택 (0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24)
"ctlDvCd": "3102", # 조정구분코드(3102 고정값인듯)
"cgPsId": "korail", # korail 고정
"pnrNo": reservation.reservation_number, # 예약번호
"totPrnb": reservation.seat_count, # 승차인원
"mnsStlAmt1": reservation.total_cost, # 결제금액1
"crdInpWayCd1": "@", # 카드입력방식코드 (@: 신용카드/ok포인트, "": 전자지갑)
"athnVal1": card_validation_number, # 생년월일/사업자번호
"athnVal1": validation_number, # 생년월일/사업자번호
"stlCrCrdNo1": number, # 결제신용카드번호1
"jrnyCnt": "1", # 여정수(1 고정)
"strJobId": "3102", # 업무구분코드(3102 고정값인듯)
Expand Down
26 changes: 16 additions & 10 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,23 @@ Highly inspired by [@dotaitch](https://github.com/dotaitch).

```python
>>> reservation = srt.reserve(trains[0])
>>> srt.pay_with_card(reservation, "1234567890123456", "12", "981204", "2309", 0, "J")
>>> srt.pay_with_card(
reservation,
number="1234567890123456",
password="12",
validation_number="981204",
expire_date="2309",
)
```

### 각 파라미터 기입요령

| 순서 | 변수명 | 설명 | 예시 | 기본 값 |
| ---- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------- | ------- |
| 1 | reservation | **결제대상 예약내역** <br>_\* `SRTReservation` 타입을 준수_ | - | - |
| 2 | number | **결제 카드번호** <br>_\* 하이픈(-) 제외_ | `"1234000056780000"` | - |
| 3 | password | **카드비밀번호 앞 2자리** | `"12"` | - |
| 4 | card_validation_number | **개인(`J`)인 경우: 생년월일<br>법인(`S`)인 경우: 사업자번호** | `"981204"` | - |
| 5 | card_expire_date | **카드유효기간** <br>_\* YYMM(연도+월) 형식의 만료일을 입력<br>\*카드 표현방식 MMYY(월+연도)형식과 착오에 주의_ | `"2309"` | - |
| 6 | card_installment | **할부선택** <br>_\* 할부 개월 수 입력, 0의 경우 일시불.<br> \* 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24 개월 선택 가능_ | `0` | `0` |
| 7 | card_type | **카드 유형** <br>_\* J : 개인, S : 법인_ | `"J"` | `"J"` |
| 순서 | 변수명 | 설명 | 예시 | 기본 값 |
| ---- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------- | ------- |
| 1 | reservation | **결제대상 예약내역** | - | - |
| 2 | number | **결제 카드번호** <br>_\* 하이픈(-) 제외_ | `"1234000056780000"` | - |
| 3 | password | **카드비밀번호 앞 2자리** | `"12"` | - |
| 4 | validation_number | **개인(`J`)인 경우: 생년월일<br>법인(`S`)인 경우: 사업자번호** | `"981204"` | - |
| 5 | expire_date | **카드유효기간** <br>_\* YYMM(연도+월) 형식의 만료일을 입력<br>\*카드 표현방식 MMYY(월+연도)형식과 착오에 주의_ | `"2309"` | - |
| 6 | installment | **할부선택** <br>_\* 할부 개월 수 입력, 0의 경우 일시불.<br> \* 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24 개월 선택 가능_ | `0` | `0` |
| 7 | card_type | **카드 유형** <br>_\* J : 개인, S : 법인_ | `"J"` | `"J"` |
46 changes: 0 additions & 46 deletions tests/test_srt.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,49 +93,3 @@ def test_reserve_and_cancel(srt, pytestconfig):
pytest.warns(Warning("Empty seat not found, skipping reservation test"))

srt.cancel(reservation)


def test_reserve_and_pay_with_card(srt, pytestconfig):
pytestconfig.getoption("--full", skip=True)
dep = "수서"
arr = "대전"
time = "000000"

membership_number = "1234567890"
password = "12"
card_expire_date = "2209"
card_installment = 0
card_validation_number = "1234567890123"
number = "1234567890123456"
card_type = "J"

# loop until empty seat is found
reservation = None
for day in range(5, 30):
date = (datetime.now() + timedelta(days=day)).strftime("%Y%m%d")

trains = srt.search_train(dep, arr, date, time)

assert len(trains) != 0

for train in trains:
if train.general_seat_available():
reservation = srt.reserve(train)
break

if reservation is not None:
break

if reservation is None:
pytest.warns(Warning("Empty seat not found, skipping reservation test"))

srt.pay_with_card(
reservation,
membership_number,
password,
card_expire_date,
card_installment,
card_validation_number,
number,
card_type,
)
88 changes: 77 additions & 11 deletions tests/test_srt_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ def test_pay_with_card_success(mock_server, httpserver):
srt = SRT("010-1234-1234", "password")

assert srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -140,7 +146,13 @@ def test_pay_with_card_fail_bad_request(mock_server, httpserver):

with pytest.raises(SRTResponseError, match="% 입력이 잘못되었습니다."):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -157,7 +169,13 @@ def test_pay_with_card_fail_cant_installment(mock_server, httpserver):

with pytest.raises(SRTResponseError, match="할부불가카드"):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -176,7 +194,13 @@ def test_pay_with_card_fail_card_password(mock_server, httpserver):
SRTResponseError, match="비밀번호오류<br><br>사용하신 각 신용카드사의 고객센터로 문의 바랍니다."
):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -193,7 +217,13 @@ def test_pay_with_card_fail_expired_card(mock_server, httpserver):

with pytest.raises(SRTResponseError, match="유효기간경과카드"):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -210,7 +240,13 @@ def test_pay_with_card_fail_invalid_auth_number(mock_server, httpserver):

with pytest.raises(SRTResponseError, match="주민번호 또는 사업자번호 오류입니다."):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -227,7 +263,13 @@ def test_pay_with_card_fail_invalid_card_number(mock_server, httpserver):

with pytest.raises(SRTResponseError, match="카드번호오류"):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -244,7 +286,13 @@ def test_pay_with_card_fail_invalid_expiration_date(mock_server, httpserver):

with pytest.raises(SRTResponseError, match="유효기간을 잘못입력하셨습니다."):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -263,7 +311,13 @@ def test_pay_with_card_fail_invalid_reservation(mock_server, httpserver):
SRTResponseError, match="취소된 여정이므로 발매할 수 없습니다.<br>비회원은 다시 예약하셔야합니다."
):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -278,7 +332,13 @@ def test_pay_with_card_fail_over_limit(mock_server, httpserver):

with pytest.raises(SRTResponseError, match="사용한도초과"):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)


Expand All @@ -295,5 +355,11 @@ def test_pay_with_card_fail_suspension_card(mock_server, httpserver):

with pytest.raises(SRTResponseError, match="거래정지카드"):
srt.pay_with_card(
mock_reservation, "12", "1221", 0, "981204", "0000000000000000", "J"
mock_reservation,
number="0000000000000000",
password="12",
validation_number="700101",
expire_date="1221",
installment=0,
card_type="J",
)

0 comments on commit 4ceace5

Please sign in to comment.