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)

Download files

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

Source Distribution

shopline_sdk-0.2.0.tar.gz (11.1 kB view details)

Uploaded Source

File details

Details for the file shopline_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: shopline_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for shopline_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a3eb9061d3306b308d82d86dc008fcaeadd6f58bb3fb92961981ddb8f61996db
MD5 6539f2e28a07fa18b55d759c290cae00
BLAKE2b-256 a65164a12968a082c6b9030076ac2c0a6926955e12dcd4829ffb79ac15d3a1b9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page