Skip to content

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

ParameterTypeRequiredDescription
modestringYesUI mode type: 'button' or 'banner'

Return Value

void - No return value

Usage Example

Step 1: Import SDK

html
<script src="https://sdk.rakufun.com/rakufun-universal.min.js"></script>

Step 2: Add Container to HTML

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

javascript
// Switch to banner mode
rakufun.setUIMode('banner');

// Switch to button mode
rakufun.setUIMode('button');

Notes

  • SDK must be imported before use
  • button mode requires <div class="rakufun-sdk-embed-button"></div> to exist on the page
  • banner mode 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

ParameterTypeRequiredDescription
dataobjectYesProduct data object, see Product Data Object

Return Value

void - No return value

Usage Example

javascript
// 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

ParameterTypeRequiredDescription
productDataobjectYesProduct data object, see Product Data Object

Return Value

Promise<void> - Returns Promise, resolve on success, reject on failure

Usage Example

html
<!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-catch to 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

javascript
(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 initPromise to 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

javascript
// 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

FieldTypeRequiredDescriptionExample
urlstring✅ YesProduct page URL"https://example.com/product/123"
titlestring✅ YesProduct name"Bose QuietComfort Headphones"
pricestring✅ YesProduct price (numeric string)"19800"
imagesstring[]✅ YesProduct image array["img1.jpg", "img2.jpg"]
descriptionstringNoProduct detailed description"Premium noise-canceling headphones"

Product Attributes

FieldTypeRequiredDescriptionExample
minQuantitystring✅ YesMinimum order quantity"1"
maxStockstring✅ YesMaximum stock quantity"100"
conditionstringNoProduct condition"New" / "Used" / "Display"
brandstringNoBrand name"Bose"
shippingInfostringNoShipping information"500"

Logistics Information

FieldTypeRequiredDescriptionExample
deliveryTimestringNoEstimated delivery time"3-5 days"
precautionsstringNoNotes/Additional information"Fragile, handle with care"

Specifications

FieldTypeRequiredDescriptionExample
productParametersstringNoProduct parameters (spec sheet, etc.)"Size: 20x15x10cm"

System Information

FieldTypeRequiredDescriptionExample
timestampstringNoCapture timestamp (auto-generated)"2024-11-06T12:00:00Z"

Complete Example

javascript
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"
};

Released under the MIT License