Skip to content

Custom Mode: Use Your Own Button ​

Instead of the SDK's built-in panel, button, or banner, you use your own "Buy" button on your site. When the user clicks it, you call rakufun.quickBuy() to hand the product information to the SDK. The SDK then opens the RAKUFUN product page in a new tab, where the user completes the purchase.

When to use it: you want the button's style, text, and position to follow your own design, or you want to put the purchase entry inside your own modal or form. If you just want a quick integration, Default Mode is easier.

Integration Steps ​

Step 1: Include the SDK and turn off the built-in panel ​

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

Once included, the SDK shows its own purchase panel at the bottom of the page by default. disableAutoUI() turns it off. Put it right after the line that includes the SDK. Without it, both your button and the SDK's panel will appear on the page.

Step 2: Add your own button ​

html
<button id="my-buy-button">Buy Now</button>

The button's style, text, and position are up to you.

Step 3: Call quickBuy when the button is clicked ​

javascript
document.getElementById('my-buy-button').addEventListener('click', async () => {
  const result = await rakufun.quickBuy({
    url: window.location.href,                   // Address of the current product page
    title: 'Bose QuietComfort Headphones',       // Product name
    price: '26800',                              // Price, digits only, no ¥ or commas
    images: ['https://example.com/product.jpg']  // Product images, full addresses
  });

  if (!result.success) {
    console.error('Purchase failed:', result.message);
    alert('Purchase failed, please try again');
  }
});

Always call quickBuy when the user clicks. It opens a new tab, and if that isn't triggered by a click, the browser may block it.

Complete Example ​

All three steps together. You can copy this into a page and try it:

html
<!DOCTYPE html>
<html>
<head>
    <title>Custom Purchase Button</title>
</head>
<body>
    <h1>Bose QuietComfort Headphones</h1>
    <img src="https://example.com/product.jpg" alt="Product Image">
    <p class="price">¥26,800</p>

    <!-- Your own button -->
    <button id="my-buy-button">🛒 Buy Now</button>

    <script src="https://sdk.rakufun.com/rakufun-universal.min.js"></script>
    <script>
        rakufun.disableAutoUI(); // Don't show the SDK's bottom panel

        document.getElementById('my-buy-button').addEventListener('click', async () => {
            const result = await rakufun.quickBuy({
                url: window.location.href,
                title: 'Bose QuietComfort Headphones',
                price: '26800',
                images: ['https://example.com/product.jpg'],
                description: 'Premium noise-canceling headphones'
            });
            if (!result.success) {
                console.error('Purchase failed:', result.message);
                alert('Purchase failed, please try again');
            }
        });
    </script>
</body>
</html>

What quickBuy Returns ​

quickBuy never throws, so you don't need try/catch. Just check result.success:

CaseReturned resultNotes
Success{ success: true, url, message, data }The RAKUFUN product page has opened in a new tab. The current page does not navigate away
Failure{ success: false, message, error }message is the reason, print it for troubleshooting

What Product Information You Can Pass ​

The examples above only pass a few fields. The more you pass, the more complete the RAKUFUN product page will be for the user. All fields:

javascript
await rakufun.quickBuy({
  // Recommended
  url: window.location.href,       // Address of the current product page
  title: "Nintendo Switch OLED",   // Product name
  price: "37980",                  // Price, digits only
  images: [                        // Product images, more than one is fine
    "https://example.com/switch-1.jpg",
    "https://example.com/switch-2.jpg"
  ],

  // Optional
  description: "7-inch OLED display, 64GB storage",  // Description, truncated beyond 2000 characters
  brand: "Nintendo",               // Brand
  condition: "New",                // Condition, e.g. New / Used / Display item
  minQuantity: "1",                // Minimum order quantity, defaults to 1
  maxStock: "100",                 // Maximum stock quantity, defaults to 99
  shippingInfo: "Free shipping",   // Shipping information
  deliveryTime: "3-5 business days",  // Estimated delivery time
  precautions: "1-year warranty included",  // Precautions
  productParameters: "Size: 102mm × 242mm × 13.9mm, Weight: approx. 320g"  // Specifications
});

For details on each field, see API Reference - Product Information Fields.

Using It in React, Vue, and Other Frameworks ​

It works the same way: call rakufun.disableAutoUI() once after the SDK is included, then call window.rakufun.quickBuy() in your button's click handler. React example:

jsx
function BuyButton({ product }) {
  const handleBuy = async () => {
    const result = await window.rakufun.quickBuy({
      url: window.location.href,
      title: product.title,
      price: product.price,
      images: product.images
    });
    if (!result.success) {
      alert('Purchase failed, please try again');
    }
  };

  return <button onClick={handleBuy}>Buy Now</button>;
}

FAQ ​

Besides my button, the SDK's bottom panel also appears? ​

rakufun.disableAutoUI() wasn't called, or was called too late. Put it right after the line that includes the SDK.

Nothing opens after clicking the button? ​

  1. Open the browser console and check whether "Purchase failed" and a reason were printed
  2. Check whether the browser's address bar says a pop-up was blocked. Call quickBuy when the user clicks, not on page load or in a timer
  3. If the console says rakufun is not defined, the SDK isn't loaded yet. Check the address and position of the <script> tag

Does the current page navigate away after calling quickBuy? ​

No. The RAKUFUN product page opens in a new tab, and the user stays on your site.

Will visitors from Japan see my button too? ​

Yes. In the other three modes the SDK hides its own interface for Japanese IPs by default. In custom mode the button is yours, and the SDK doesn't hide it. If you want only overseas visitors to see it, please contact us.

Other Integration Options ​

  • Default Mode - Purchase panel shown automatically at the bottom of the page, the fastest integration
  • Button Mode - Shows a purchase button where you choose
  • Banner Mode - Shows a banner where you choose

Questions? Contact us: service@rakufun.com

Released under the MIT License