GithubHelp home page GithubHelp logo

enoch2110 / iamport-rest-client-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iamport/iamport-rest-client-python

0.0 2.0 0.0 23 KB

Python 사용자를 위한 아임포트 REST API 연동 모듈입니다

License: MIT License

Python 100.00%

iamport-rest-client-python's Introduction

I'mport; REST Client

https://travis-ci.org/iamport/iamport-rest-client-python.svg?branch=master https://coveralls.io/repos/github/iamport/iamport-rest-client-python/badge.svg?branch=master

Python 사용자를 위한 아임포트 REST API 연동 모듈입니다.

설치

pip install iamport-rest-client

기능

  1. 결제 정보 찾기
  2. 가격 확인
  3. 취소
  4. 비 인증 결제

사용법

준비

사용하기 위해 객체를 만듭니다.

from iamport import Iamport

# 테스트 용
iamport = Iamport(='{테스트용 키}', 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.ResonseError as e:
    print e.code
    print e.message  # 에러난 이유를 알 수 있음

비인증 결제

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

저장된 빌링키로 재결제합니다.

# 테스트용 값
payload = {
    'customer_uid': '{고객 아이디}',
    'merchant_uid': '00000000',
    'amount': 5000,
}
try:
    response = iamport.pay_again(**payload)
except KeyError:
    # 필수 값이 없을때 에러 처리
    pass
except Iamport.ResponseError as e:
    # 응답 에러 처리
    pass

기여

할 일

  • 결제 목록 읽기
  • 비인증 결제 세부 기능 지원
  • 문서화
  • 기타 등등

iamport-rest-client-python's People

Contributors

dahlia avatar enoch2110 avatar jangbora avatar pcompassion avatar perhapsspy avatar psy2848048 avatar woojing avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.