Skip to main content

A package for initiating payments via the Stitch API

Project description

stitch-money-api

A Python package for processing digitial wallets payments via the Stitch API. For the complete integration guide, visit docs.stitch.money.

Installation

$ pip3 install stitch-money-api

Usage

Payment Initiation

from pyramid.view import view_config
from pyramid.response import Response
from stitch.payins import Wallets
from stitch.utils.types import Wallet, Currency, Transaction
import json
import uuid
import os
from dotenv import load_dotenv

load_dotenv()

client_id = os.getenv("STITCH_CLIENT_ID")
client_secret = os.getenv("STITCH_CLIENT_SECRET")

if not client_id or not client_secret:
    raise EnvironmentError(
        "Missing STITCH_CLIENT_ID or STITCH_CLIENT_SECRET in environment variables"
    )

sdk = Wallets(client_id, client_secret, "merchant.money.stitch")


@view_config(route_name="create", request_method="POST", renderer="json")
def create_apple_pay_payment(request) -> Response:
    data = request.json_body
    payment_token = data.get("payment_token")

    if not payment_token:
        return Response(json_body={"error": "Missing payment_token"}, status=400)

    nonce = str(uuid.uuid4())
    quantity = 1
    currency = Currency.ZAR
    reference = "StitchTest"

    transaction: Transaction = sdk.create(
        Wallet.APPLE_PAY, payment_token, quantity, currency, nonce, reference
    )

    return Response(json_body={"transaction": transaction}, status=200)

Merchant Verification

Note this is not required for mobile (native) app integrations.

from pyramid.view import view_config
from pyramid.response import Response
from stitch.payins import Wallets
from stitch.utils.types import Wallet, Currency, Session
import os
from dotenv import load_dotenv

load_dotenv()

client_id = os.getenv("STITCH_CLIENT_ID")
client_secret = os.getenv("STITCH_CLIENT_SECRET")

if not client_id or not client_secret:
    raise EnvironmentError(
        "Missing STITCH_CLIENT_ID or STITCH_CLIENT_SECRET in environment variables"
    )

sdk = Wallets(client_id, client_secret, "merchant.money.stitch")


@view_config(route_name="verify", request_method="POST", renderer="json")
def verify_apple_pay_merchant(request) -> Response:
    data = request.json_body
    verification_url = data.get(
        "verification_url"
    )  # 'https://apple-pay-gateway.apple.com/paymentservices/startSession'
    initiative_context = data.get("initiative_context")  # secure.stitch.money (FQDN)

    if not verification_url or not initiative_context:
        return Response(
            json_body={"error": "Missing verification_url or initiative_context"},
            status=400,
        )

    quantity = 1
    currency = Currency.ZAR
    display_name = "Stitch"

    session: Session = sdk.verify(
        Wallet.APPLE_PAY,
        quantity,
        currency,
        verification_url,
        display_name,
        initiative_context,
    )

    return Response(json_body={"session": session}, status=200)

License

The stitch-money-api package is open source and available under the MIT license. See the LICENSE file for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stitch_money_api-1.0.4.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

stitch_money_api-1.0.4-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file stitch_money_api-1.0.4.tar.gz.

File metadata

  • Download URL: stitch_money_api-1.0.4.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.4

File hashes

Hashes for stitch_money_api-1.0.4.tar.gz
Algorithm Hash digest
SHA256 07b99358ad76710da8a37c1610b06e6943e0d54a88c004d5d21feddfd34601ad
MD5 16074668fbc1abf5b34f7296ad5f5ddc
BLAKE2b-256 743d7f93bbbe9e9f99805435c501474193aa8c4e9c6d28439f59a02446615295

See more details on using hashes here.

File details

Details for the file stitch_money_api-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for stitch_money_api-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3ffd0c070f2e658c52c7dfeda08cbac1efd5d069e2f95e40d0465ed3fc2aba7f
MD5 000eee47d0b8f66318b82ee26dff053e
BLAKE2b-256 2252454dbe755ae58fac9e24b809faf6f0283e44e8ff2ff4502a36ba9ed94471

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page