Skip to main content

Shopline Python SDK

版本:0.2.0

功能概述

  • OAuth 授权与 token 刷新
  • Product / Order / Customer OpenAPI 封装
  • Webhook 订阅管理接口
  • Webhook verification token 与签名校验辅助方法

Webhook 用法

from shopline.api import ShoplineAPI


client = ShoplineAPI(
	client_id="your_app_id",
	client_secretkey="your_app_secret",
	handle="Your App",
	merchant_id="your_merchant_id",
)
client.set_access_token("your_access_token")

# 创建 webhook
webhook = client.webhook.create_webhook(
	address="https://example.com/shopline/webhook",
	topics=["order/create", "order/update"],
)

# 查询 webhook 列表
webhooks = client.webhook.get_webhooks(per_page=20, page=1)

# 查询单个 webhook
detail = client.webhook.get_webhook(webhook["id"])

# 更新 webhook
updated = client.webhook.update_webhook(
	webhook["id"],
	topics=["order/create", "order/paid"],
)

# 删除 webhook
client.webhook.delete_webhook(webhook["id"])

Webhook 接收辅助

SHOPLINE 在验证 webhook endpoint 时,会先发一个 {"topic": "webhook/verification"} 的 POST 请求。你的服务需要返回纯文本 verification token。

# App token 模式: 返回 base64(app_id)
plain_text = client.webhook.get_webhook_verification_token(use_app_token=True)

# Merchant token 模式: 返回 base64(merchant_id)
plain_text = client.webhook.get_webhook_verification_token(use_app_token=False)

如果后续需要校验 sign 参数,可以直接使用 SDK helper:

payload = {
	"topic": "application/uninstall",
	"merchant_id": "5dad5d2604515400018dcc90",
}
timestamp = "1618994178"
signature = client.webhook.generate_webhook_signature(payload, timestamp)
is_valid = client.webhook.verify_webhook_signature(payload, timestamp, signature)

Metadata

Release files for shopline-sdk 0.2.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 shopline-sdk 0.2.0
File Size Uploaded
shopline_sdk-0.2.0.tar.gz 11.1 kB Details

Release files / shopline_sdk-0.2.0.tar.gz

Download URL shopline_sdk-0.2.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a3eb9061d3306b308d82d86dc008fcaeadd6f58bb3fb92961981ddb8f61996db
BLAKE2b-256 checksum
How to use checksums
a65164a12968a082c6b9030076ac2c0a6926955e12dcd4829ffb79ac15d3a1b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.21.0 setuptools/45.2.0 requests-toolbelt/1.0.0 tqdm/4.30.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

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