I’mport; REST Client
Python3 사용자를 위한 아임포트 REST API 연동 모듈입니다.
이용 중 발생한 문제에 대해 책임지지 않습니다.
Iamport 공식 라이브러리 가 관리되지 않아 포크하여 만들었습니다
설치
pip install iamport-rest-client2
기능
결제 정보 찾기
가격 확인
취소
비 인증 결제
정기 예약 결제
결제 없이 카드정보 등록
사용법
준비
사용하기 위해 객체를 만듭니다.
from iamport import Iamport
# 테스트 용
iamport = Iamport(imp_key='{테스트용 키}', imp_secret='{테스트 시크릿}')
# 테스트용 키와 시크릿은 tests/conftest.py 파일에 DEFAULT_TEST_IMP_KEY, DEFAULT_TEST_IMP_SECRET를 참고하세요.
# 실제 상점 정보
iamport = Iamport(imp_key='{발급받은 키}', imp_secret='{발급받은 시크릿}')
찾기
결제를 진행한 상품 아이디나, 전달받은 IMP 아이디를 이용해 결제 정보를 찾습니다.
# 상품 아이디로 조회
response = iamport.find(merchant_uid='{상품 아이디}')
# I'mport; 아이디로 조회
response = iamport.find(imp_uid='{IMP UID}')
가격 확인
실제 제품 가격과 결제된 가격이 같은지 확인합니다.
# 상품 아이디로 확인
iamport.is_paid(product_price, merchant_uid='{상품 아이디}')
# I'mport; 아이디로 확인
iamport.is_paid(product_price, imp_uid='{IMP UID}')
# 이미 찾은 response 재활용하여 확인
iamport.is_paid(product_price, response=response)
취소
결제를 취소합니다.
# 상품 아이디로 취소
response = iamport.cancel(u'취소하는 이유', merchant_uid='{상품 아이디}')
# I'mport; 아이디로 취소
response = iamport.cancel(u'취소하는 이유', imp_uid='{IMP UID}')
# 취소시 오류 예외처리(이미 취소된 결제는 에러가 발생함)
try:
response = iamport.cancel(u'취소하는 이유', imp_uid='{IMP UID}')
except Iamport.ResponseError as e:
print e.code
print e.message # 에러난 이유를 알 수 있음
except Iamport.HttpError as http_error:
print http_error.code
print http_error.reason # HTTP not 200 에러난 이유를 알 수 있음
비인증 결제
1회성 비인증 결제를 진행합니다.
# 테스트용 값
payload = {
'merchant_uid': '00000000',
'amount': 5000,
'card_number': '4092-0230-1234-1234',
'expiry': '2019-03',
'birth': '500203',
'pwd_2digit': '19'
}
try:
response = iamport.pay_onetime(**payload)
except KeyError:
# 필수 값이 없을때 에러 처리
pass
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
저장된 빌링키로 재결제합니다.
# 테스트용 값
payload = {
'customer_uid': '{고객 아이디}',
'merchant_uid': '00000000',
'amount': 5000,
}
try:
response = iamport.pay_again(**payload)
except KeyError:
# 필수 값이 없을때 에러 처리
pass
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
정기 예약 결제
정기 결제를 예약합니다.
# 테스트용 값
payload = {
'customer_uid': '{고객 아이디}',
'schedules': [
{
'merchant_uid': 'test_merchant_01',
# UNIX timestamp
'schedule_at': 1478150985,
'amount': 1004
},
{
'merhcant_uid': 'test_merchant_02',
# UNIX timestamp
'schedule_at': 1478150985,
'amount': 5000,
'name': '{주문명}',
'buyer_name': '{주문자명}',
'buyer_email': '{주문자 이메일}',
'buyer_tel': '{주문자 전화번호}',
'buyer_addr': '{주문자 주소}',
'buyer_postcode': '{주문자 우편번호}',
},
]
}
try:
reponse = iamport.pay_schedule(**payload)
except KeyError:
# 필수 값이 없을때 에러 처리
pass
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
정기 결제 예약을 취소합니다.
# 테스트용 값 (merchant_uid 가 누락되면 customer_uid 에 대한 결제예약정보 일괄취소)
payload = {
'customer_uid': '{고객 아이디}',
'merchant_uid': 'test_merchant_01',
}
try:
response = iamport.pay_unschedule(**payload)
except KeyError:
# 필수 값이 없을때 에러 처리
pass
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
결제 사전 검증
결제될 내역에 대한 사전정보를 등록합니다
# 테스트용 값
amount = 12000
mid = 'merchant_test'
try:
response = iamport.prepare(amount=amount, merchant_uid=mid)
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
등록된 사전정보를 확인합니다
# 테스트용 값
amount = 12000
mid = 'merchant_test'
try:
result = iamport.prepare_validate(merchant_uid=mid, amount=amount)
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
카드정보 등록
결제 없이 카드 정보를 등록합니다
# 테스트용 값
payload = {
'customer_uid': '{고객 아이디}',
'card_number': '4092-0230-1234-1234',
'expiry': '2019-03',
'birth': '500203',
'pwd_2digit': '19' # 법인일땐 생략 가능
}
try:
response = iamport.customer_create(**payload)
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
등록된 카드 정보(=빌링키)를 요청합니다
# 테스트용 값
customer_uid = '{고객 아이디}'
try:
response = iamport.customer_get(customer_uid)
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
구매자의 빌링키 정보를 삭제 합니다
# 테스트용 값
customer_uid = '{고객 아이디}'
try:
response = iamport.customer_delete(customer_uid)
except Iamport.ResponseError as e:
# 응답 에러 처리
pass
except Iamport.HttpError as http_error:
# HTTP not 200 응답 에러 처리
pass
개발환경 및 테스트 설정
macOS 기준
pip install -r requirements.txt
pytest
할 일
결제 목록 읽기
문서화
기타 등등
Metadata
Release files for iamport-rest-client2 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iamport-rest-client2-0.0.2.tar.gz | 8.7 kB | Without provenance | Details for iamport-rest-client2-0.0.2.tar.gz |
Release files / iamport-rest-client2-0.0.2.tar.gz
| Download URL | iamport-rest-client2-0.0.2.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
764bb62ec29734848a8d774bdbc8b5a0bb6af825be2a4643a8840a57bb3adba3
|
|
BLAKE2b-256 checksum How to use checksums |
5c987a8ad9b81c5d45c5dfddee391abf13dc45c8711a94b4b5ac318a98f3b668
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
|
Security for iamport-rest-client2 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.