API Documentation
RAKUFUN SDK provides a simple and intuitive API to help you integrate international purchasing service capabilities into e-commerce sites.
setUIMode
Set UI display mode, dynamically switch between button or banner styles.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
mode | string | Yes | UI mode type: 'button' or 'banner' |
Return Value
void - No return value
Usage Example
Step 1: Import SDK
<script src="https://sdk.rakufun.com/rakufun-universal.min.js"></script>Step 2: Add Container to HTML
<!-- Button mode container -->
<div class="rakufun-sdk-embed-button"></div>
<!-- Banner mode container -->
<div class="rakufun-sdk-embed-banner"></div>Step 3: Switch Mode in JavaScript
// Switch to banner mode
rakufun.setUIMode('banner');
// Switch to button mode
rakufun.setUIMode('button');Notes
- SDK must be imported before use
buttonmode requires<div class="rakufun-sdk-embed-button"></div>to exist on the pagebannermode requires<div class="rakufun-sdk-embed-banner"></div>to exist on the page- Switching modes will clear the current UI and reinitialize
- Will asynchronously wait for IP detection to complete before displaying the new mode's UI
setUIProductData
Preset product data for default mode, floating button or banner UI. The data will be used when the button is clicked.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
data | object | Yes | Product data object, see Product Data Object |
Return Value
void - No return value
Usage Example
// Set product data when page loads or when product data is ready
window.addEventListener('load', () => {
// Prepare product data
const productData = {
title: document.querySelector('.product-name').textContent,
price: document.querySelector('.price').textContent,
images: [document.querySelector('.main-image').src],
url: window.location.href,
minQuantity: '1',
maxStock: '100'
};
// Set to UI
rakufun.setUIProductData(productData);
// Now when users click the floating button, the above data will be used automatically
});Notes
- SDK must be imported before use
- If this method is not called before clicking the UI button, it will prompt "Product data not set, please call rakufun.setUIProductData(data)"
- Can be called multiple times to update product data
quickBuy
Add product to Rakufun shopping cart and automatically open checkout page. Skip built-in UI, use your own design and components, only call RAKUFUN's one-click purchase API. Suitable for scenarios requiring deep customization.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
productData | object | Yes | Product data object, see Product Data Object |
Return Value
Promise<void> - Returns Promise, resolve on success, reject on failure
Usage Example
<!DOCTYPE html>
<html>
<head>
<title>Custom Buy Button</title>
</head>
<body>
<h1>Featured Product</h1>
<img src="product.jpg" alt="Product Image">
<p class="price">¥26,800</p>
<!-- Your custom button -->
<button id="my-buy-button" class="custom-btn">
🛒 Buy Now
</button>
<script src="https://sdk.rakufun.com/rakufun-universal.min.js"></script>
<script>
document.getElementById('my-buy-button').addEventListener('click', async () => {
try {
await rakufun.quickBuy({
title: 'Bose QuietComfort Headphones',
price: '26800',
url: window.location.href,
images: ['product.jpg'],
description: 'Premium noise-canceling headphones',
minQuantity: '1',
maxStock: '50'
});
} catch (error) {
console.error('Purchase failed:', error);
alert('Purchase failed, please try again');
}
});
</script>
</body>
</html>Notes
- Recommend using
try-catchto catch errors - Ensure required fields are complete
- Will automatically redirect to Rakufun checkout page on success
isJapanUser
Check if user is from Japan (synchronous method).
Parameters
None
Return Value
boolean - Returns true if user is from Japan, otherwise false
Usage Example
(async () => {
await rakufun.initPromise; // Ensure initialization is complete
await rakufun.detectUserRegion(); // Wait for IP detection to complete
const isJapan = rakufun.isJapanUser(); // Synchronous call
if (isJapan) {
console.log('User is from Japan');
}
})();Notes
- Must wait for
initPromiseto complete for accurate results - Recommend using asynchronous method
isJapanUserAsync()
isJapanUserAsync
Check if user is from Japan (asynchronous method, recommended).
Parameters
None
Return Value
Promise<boolean> - Returns Promise, resolve value true means user is from Japan, false otherwise
Usage Example
// Use asynchronous method directly (recommended)
(async () => {
const isJapan = rakufun.isJapanUserAsync(); // Automatically waits for detection to complete
if (isJapan) {
console.log('User is from Japan');
}
})();Notes
- Recommend using this method, automatically handles initialization waiting
- No need to manually wait for
initPromise
Product Data Object
Basic Information
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
url | string | ✅ Yes | Product page URL | "https://example.com/product/123" |
title | string | ✅ Yes | Product name | "Bose QuietComfort Headphones" |
price | string | ✅ Yes | Product price (numeric string) | "19800" |
images | string[] | ✅ Yes | Product image array | ["img1.jpg", "img2.jpg"] |
description | string | No | Product detailed description | "Premium noise-canceling headphones" |
Product Attributes
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
minQuantity | string | ✅ Yes | Minimum order quantity | "1" |
maxStock | string | ✅ Yes | Maximum stock quantity | "100" |
condition | string | No | Product condition | "New" / "Used" / "Display" |
brand | string | No | Brand name | "Bose" |
shippingInfo | string | No | Shipping information | "500" |
Logistics Information
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
deliveryTime | string | No | Estimated delivery time | "3-5 days" |
precautions | string | No | Notes/Additional information | "Fragile, handle with care" |
Specifications
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
productParameters | string | No | Product parameters (spec sheet, etc.) | "Size: 20x15x10cm" |
System Information
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
timestamp | string | No | Capture timestamp (auto-generated) | "2024-11-06T12:00:00Z" |
Complete Example
const productData = {
// Required fields
url: "https://example.com/product/123",
title: "Bose QuietComfort Headphones",
price: "26800",
images: ["https://example.com/img1.jpg", "https://example.com/img2.jpg"],
minQuantity: "1",
maxStock: "50",
// Optional fields
description: "Premium noise-canceling headphones with superior sound quality",
condition: "New",
brand: "Bose",
shippingInfo: "Free shipping",
deliveryTime: "3-5 business days",
precautions: "Please check package integrity upon delivery",
productParameters: "Color: Black\nWeight: 240g\nConnection: Bluetooth 5.1"
};