Refresh Order Status

This interface can be used to actively query and refresh the latest payment status of an order. After the user completes the payment, this interface can be used to confirm whether the order has been completed.

Prerequisites

  1. Register and log in to the Ace Data Cloud platform.
  2. Obtain the Platform Token, for details please refer to the Platform Token Documentation.
  3. There is an order in Pending status.

Interface Description

  • Request Method: POST
  • Request URL: https://platform.acedata.cloud/api/v1/orders/{id}/refresh/
  • Request Headers:
    • accept: application/json
    • authorization: Bearer {token}

Where {id} is the order UUID, and {token} is the Platform Token.

CURL Request Example

curl -X POST \
  -H "accept: application/json" \
  -H "authorization: Bearer {token}" \
  "https://platform.acedata.cloud/api/v1/orders/{id}/refresh/"

Response Result Example

Order has been paid and completed:

{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "state": "Finished",
  "pay_way": "STRIPE",
  "price": "9.90",
  "currency": "USD",
  "service": {
    "id": "xxxx-xxxx-xxxx",
    "name": "ChatGPT",
    "alias": "chatgpt"
  },
  "packages": [...],
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:35:00Z"
}

Order is still waiting for payment:

{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "state": "Pending",
  "pay_way": "STRIPE",
  "pay_url": "https://buy.stripe.com/xxxxxxxxxxxx",
  "price": "9.90",
  "currency": "USD",
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-15T10:30:00Z"
}

Order Status Transition

Status Description
Pending Waiting for payment
Paid Paid, processing (recharge amount)
Finished Payment completed, amount credited
Expired Order has expired (exceeded payment time limit)
Failed Payment failed
Refunded Refunded

Use Cases

  1. Confirmation after Payment: After the user completes the payment and returns to the platform, call this interface to confirm the order status.
  2. Polling Query: While waiting for payment completion, periodically call this interface to check for status updates.
  3. Timeout Detection: For orders that have not been paid for a long time, call this interface to trigger an expiration check.

Code Example

Python:

import requests
import time

token = "your-platform-token"
order_id = "your-order-id"
url = f"https://platform.acedata.cloud/api/v1/orders/{order_id}/refresh/"
headers = {
    "accept": "application/json",
    "authorization": f"Bearer {token}",
}

# Polling to wait for payment completion
for _ in range(30):
    response = requests.post(url, headers=headers)
    result = response.json()
    state = result["state"]
    print(f"Order status: {state}")

    if state == "Finished":
        print("Payment successful, amount credited!")
        break
    elif state in ["Expired", "Failed"]:
        print("Payment failed or has expired")
        break

    time.sleep(5)

Node.js:

const axios = require("axios");

const token = "your-platform-token";
const orderId = "your-order-id";
const url = `https://platform.acedata.cloud/api/v1/orders/${orderId}/refresh/`;

const response = await axios.post(url, null, {
  headers: {
    accept: "application/json",
    authorization: `Bearer ${token}`,
  },
});

console.log(`Order status: ${response.data.state}`);