Sample Code
In order to describe more accurate technical details, we provide a simple implementation of the Python code, please use this reference to get detailed information about the details of the HTTP request.
info
We apologize for not being able to provide more references to implementations in other programming languages!
import requests
import uuid
WONDER_PAYMENT_API_URL = "https://gateway.wonder.app/api/galaxy/payment-link"
WONDER_API_HEADER_BUSINESS_ID = "<please fill here>"
WONDER_API_HEADER_APP_KEY = "<please fill here>"
WONDER_API_HEADER_APP_SLUG = "<please fill here>"
WONDER_API_HEADER_AUTHORIZATION = "<please fill here>"
# All of APIs should be using same header
def generate_wonder_header():
return {
"x-app-slug": WONDER_API_HEADER_APP_SLUG,
"x-app-key": WONDER_API_HEADER_APP_KEY,
"authorization": WONDER_API_HEADER_AUTHORIZATION,
"x-p-business-id": WONDER_API_HEADER_BUSINESS_ID,
"Content-Type" : "application/json"
}
# Please check our online documentation: https://developer.wonder.today/payment_link/api_reference#create-order-api
def generate_create_payment_link_payload(reference_number, initial_amount):
return {
"reference_number": reference_number,
"charge_fee": initial_amount,
"currency": "HKD",
"redirect_url": "https://www.example.com/yourpath?yourqueryname=yourqueryvalue",
"callback_url": "https://www.example.com/yourpath?yourqueryname=yourqueryvalue",
}
def create_payment_link(reference_number, initial_amount):
headers = generate_wonder_header()
payload = generate_create_payment_link_payload(reference_number, initial_amount)
response = requests.post(WONDER_PAYMENT_API_URL, headers=headers, json=payload)
if response.status_code == 201 or response.status_code == 200:
return response.json()["data"]["url"]
else:
print("Generate Payment Link Fails:", response.json())
return None
payment_url = create_payment_link(str(uuid.uuid4()), 1.0)
print("Your should redirect to the url from you website:", payment_url)