from uuid import uuid4
# Detect payment method from phone
mmo = requests.get(f"{BASE_URL}/v1/predictions/mmo-provider-info", headers=headers, params={
"phone": "231771234567", "operation_type": "COLLECTION",
}).json()
payment_method = mmo["payment_method"]
provider = mmo["gateway_provider"]
# Create checkout session
session = requests.post(f"{BASE_URL}/v1/sessions/checkout", headers=headers, json={
"source_id": invoice_id,
"source_type": "INVOICE",
}).json()
session_id = session["id"]
# Register customer wallet
account = requests.post(
f"{BASE_URL}/v1/payment-accounts/create",
headers=headers,
params={"operation_type": "COLLECTION"},
json={
"account_name": "Amara MTN Wallet",
"provider": provider,
"method": payment_method,
"party_id": party_id,
"country_code": "LR",
"insensitive_account_number": "231771234567",
},
).json()
# Execute — generate and store reference_id BEFORE the call
reference_id = str(uuid4())
execution = requests.post(f"{BASE_URL}/v1/executions/collection", headers=headers, json={
"session_id": str(session_id),
"payment_account_id": str(account["id"]),
"currency": "USD",
"reference_id": reference_id,
}).json()
print("Execution status:", execution["status"])