feat(abonnement): client.change_subscription (PUT /v1/subscription) (#109)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -155,3 +155,13 @@ def get_payment_info_url(sub_handle: str, accept_url: str, cancel_url: str) -> s
|
|||||||
|
|
||||||
def get_plan(plan_handle: str) -> dict:
|
def get_plan(plan_handle: str) -> dict:
|
||||||
return _call("GET", f"/v1/plan/{plan_handle}")
|
return _call("GET", f"/v1/plan/{plan_handle}")
|
||||||
|
|
||||||
|
|
||||||
|
def change_subscription(
|
||||||
|
sub_handle: str, plan_handle: str, timing: str = "renewal"
|
||||||
|
) -> dict:
|
||||||
|
return _call(
|
||||||
|
"PUT",
|
||||||
|
f"/v1/subscription/{sub_handle}",
|
||||||
|
json={"timing": timing, "plan": plan_handle},
|
||||||
|
)
|
||||||
|
|||||||
@@ -131,3 +131,18 @@ def test_get_payment_info_url_merges_existing_query_string(fake_httpx):
|
|||||||
assert "locale=fr" in url
|
assert "locale=fr" in url
|
||||||
assert "accept_url=https%3A%2F%2Fapp%2Fok" in url
|
assert "accept_url=https%3A%2F%2Fapp%2Fok" in url
|
||||||
assert "cancel_url=https%3A%2F%2Fapp%2Fko" in url
|
assert "cancel_url=https%3A%2F%2Fapp%2Fko" in url
|
||||||
|
|
||||||
|
|
||||||
|
def test_change_subscription_sends_timing_and_plan(fake_httpx):
|
||||||
|
fake_httpx["queue"].append(fake_httpx["Response"](200, {"handle": "abo-1-1"}))
|
||||||
|
client.change_subscription("abo-1-1", "plan_soutien", timing="renewal")
|
||||||
|
call = fake_httpx["calls"][0]
|
||||||
|
assert call["method"] == "PUT"
|
||||||
|
assert call["url"] == "https://api.test/v1/subscription/abo-1-1"
|
||||||
|
assert call["json"] == {"timing": "renewal", "plan": "plan_soutien"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_change_subscription_immediate_timing(fake_httpx):
|
||||||
|
fake_httpx["queue"].append(fake_httpx["Response"](200, {"handle": "abo-1-2"}))
|
||||||
|
client.change_subscription("abo-1-2", "plan_simple", timing="immediate")
|
||||||
|
assert fake_httpx["calls"][0]["json"]["timing"] == "immediate"
|
||||||
|
|||||||
Reference in New Issue
Block a user