From 4ceace5d09fc68a108c8a7b13daa811a758dde2f Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Tue, 26 Sep 2023 18:59:43 +0900 Subject: [PATCH] Rename attributes of pay_with_card API (#253) --- CHANGELOG.md | 10 +++++ SRT/srt.py | 18 ++++----- docs/advanced.md | 26 ++++++++----- tests/test_srt.py | 46 ---------------------- tests/test_srt_mock.py | 88 ++++++++++++++++++++++++++++++++++++------ 5 files changed, 112 insertions(+), 76 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd14654..ce7ad9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)에 따른 신규 정차역 코드 및 이름 추가. diff --git a/SRT/srt.py b/SRT/srt.py index 28cbb03..8a3f366 100644 --- a/SRT/srt.py +++ b/SRT/srt.py @@ -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: """결제합니다. @@ -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: @@ -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 고정값인듯) diff --git a/docs/advanced.md b/docs/advanced.md index 1a94db2..dc23296 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -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 | **결제대상 예약내역**
_\* `SRTReservation` 타입을 준수_ | - | - | -| 2 | number | **결제 카드번호**
_\* 하이픈(-) 제외_ | `"1234000056780000"` | - | -| 3 | password | **카드비밀번호 앞 2자리** | `"12"` | - | -| 4 | card_validation_number | **개인(`J`)인 경우: 생년월일
법인(`S`)인 경우: 사업자번호** | `"981204"` | - | -| 5 | card_expire_date | **카드유효기간**
_\* YYMM(연도+월) 형식의 만료일을 입력
\*카드 표현방식 MMYY(월+연도)형식과 착오에 주의_ | `"2309"` | - | -| 6 | card_installment | **할부선택**
_\* 할부 개월 수 입력, 0의 경우 일시불.
\* 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24 개월 선택 가능_ | `0` | `0` | -| 7 | card_type | **카드 유형**
_\* J : 개인, S : 법인_ | `"J"` | `"J"` | +| 순서 | 변수명 | 설명 | 예시 | 기본 값 | +| ---- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------- | ------- | +| 1 | reservation | **결제대상 예약내역** | - | - | +| 2 | number | **결제 카드번호**
_\* 하이픈(-) 제외_ | `"1234000056780000"` | - | +| 3 | password | **카드비밀번호 앞 2자리** | `"12"` | - | +| 4 | validation_number | **개인(`J`)인 경우: 생년월일
법인(`S`)인 경우: 사업자번호** | `"981204"` | - | +| 5 | expire_date | **카드유효기간**
_\* YYMM(연도+월) 형식의 만료일을 입력
\*카드 표현방식 MMYY(월+연도)형식과 착오에 주의_ | `"2309"` | - | +| 6 | installment | **할부선택**
_\* 할부 개월 수 입력, 0의 경우 일시불.
\* 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24 개월 선택 가능_ | `0` | `0` | +| 7 | card_type | **카드 유형**
_\* J : 개인, S : 법인_ | `"J"` | `"J"` | diff --git a/tests/test_srt.py b/tests/test_srt.py index 7a401fe..eb42693 100644 --- a/tests/test_srt.py +++ b/tests/test_srt.py @@ -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, - ) diff --git a/tests/test_srt_mock.py b/tests/test_srt_mock.py index 0d5c64e..4a2fd75 100644 --- a/tests/test_srt_mock.py +++ b/tests/test_srt_mock.py @@ -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", ) @@ -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", ) @@ -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", ) @@ -176,7 +194,13 @@ def test_pay_with_card_fail_card_password(mock_server, httpserver): 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", ) @@ -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", ) @@ -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", ) @@ -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", ) @@ -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", ) @@ -263,7 +311,13 @@ def test_pay_with_card_fail_invalid_reservation(mock_server, httpserver): 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", ) @@ -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", ) @@ -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", )