Skip to main content

FastPay SDK for Python

FastPayをPythonで簡単に利用するためのSDKです。

インストール

pipコマンドでインストールを行います

$ pip install fastpay

使い方

FastPayではクレジットカード情報は直接扱わず、FastPay側でトークン化したものを使って安全に決済を行います。 トークン化など全体的な流れについては、 FastPayのドキュメント[支払いフロー] をご覧ください。

課金

詳細についてはFastPayのドキュメント 新規決済の作成 をご覧ください。

import fastpay

# fastpay.jsで取得します。"fastpayToken"というパラメータでhiddenのinputにて送信されます。
token = "CARD_TOKEN"

client = fastpay.FastPay("シークレット")

try:
    charge = client.charge.create(
        amount=100,  # 金額
        card=token,  # fastpay.jsで取得したトークン
        description="fastpay@example.com",  # 詳細情報。フリーフォームです
        capture=False  # 確定を行わない場合False。同時確定の場合は省略またはTrueを指定する
    )
    # 例外が上がらなかった場合、課金成功
    print("注文完了 ID: %s" % charge.id)  # -> 注文ID表示
except fastpay.CardError as e:
    # カード与信エラー。必要に応じて再度画面を表示など行う
    if e.code == FastPayError.CARD_DECLINED:
        print("カード決済に失敗しました。(オーソリ時のエラー)")
    elif e.code == FastPayError.INCORRECT_CVC:
        print("セキュリティコードが正しくありません。(オーソリ時のエラー)")
    # 他のコードは https://fastpay.yahoo.co.jp/docs/error を参照
except fastpay.FastPayError as e:
    print("システムエラー %s" % str(e))

確定

詳細についてはFastPayのドキュメント 決済の確定 をご覧ください。

import fastpay

client = fastpay.FastPay("シークレット")

try:
    charge = client.charge.retrieve("対象のcharge_id")
    # 確定を行う
    charge.capture()
    # 例外が上がらなかった場合、確定成功
    print("確定成功")
except fastpay.FastPayError as e:
    print("システムエラー %s" % str(e))

返金

詳細についてはFastPayのドキュメント 払い戻し処理 をご覧ください。

import fastpay

client = fastpay.FastPay("シークレット")

try:
    charge = client.charge.retrieve("対象のcharge_id")
    # 確定を行う。引数を与えることで部分返金も可能
    charge.refund()
    # 例外が上がらなかった場合、払い戻し成功
    print("払い戻し成功")
except fastpay.FastPayError as e:
    print("システムエラー %s" % str(e))

継続課金の開始

継続課金についてはまずはFastPayのドキュメント 継続課金とは をごらんください。

import fastpay

client = fastpay.FastPay("シークレット")

try:
    subscription = client.subscription.activate("対象のsubscription_id")
    print("継続課金開始成功")
except fastpay.FastPayError as e:
    print("システムエラー %s" % str(e))

継続課金の停止

継続停止についてもFastPayのドキュメント 継続課金とは をごらんください。

import fastpay

client = fastpay.FastPay("シークレット")

try:
    subscription = client.subscription.cancel("対象のsubscription_id")
    print("継続課金停止成功")
except fastpay.FastPayError as e:
    print("システムエラー %s" % str(e))

License

MITライセンスにて提供しています。詳しくはLICENSEをご覧ください。

Metadata

Release files for fastpay 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastpay 1.0.0
File Size Uploaded
fastpay-1.0.0.tar.gz 9.4 kB Details

Release files / fastpay-1.0.0.tar.gz

Download URL fastpay-1.0.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a878baa0c2099afb7fd8d17d3ede079aa06b3e26bb152e834cea1f361576398e
BLAKE2b-256 checksum
How to use checksums
9d93e15ed27860d95386fa98b573e6887b7c493ee74398c1a5cffccb98bb784c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page