> ## Documentation Index
> Fetch the complete documentation index at: https://waffo.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Code examples

> Multilingual API integration code examples for Node.js, Java, Go, Python, and raw HTTP.

The following examples use the same one-time payment payload so you can compare SDK and raw HTTP integration.

## Node.js (using the SDK)

```typescript theme={null}
import { Waffo, Environment } from '@waffo/waffo-node';
import { randomUUID } from 'crypto';

const waffo = new Waffo({
  apiKey: process.env.WAFFO_API_KEY,
  privateKey: process.env.WAFFO_PRIVATE_KEY,
  waffoPublicKey: process.env.WAFFO_PUBLIC_KEY,
  merchantId: process.env.WAFFO_MERCHANT_ID,
  environment: Environment.SANDBOX,
});

const paymentRequestId = randomUUID().replace(/-/g, '');
const response = await waffo.order().create({
  paymentRequestId,
  merchantOrderId: `ORDER_${Date.now()}`,
  orderCurrency: 'HKD',
  orderAmount: '100.00',
  orderDescription: 'Premium Plan',
  notifyUrl: 'https://your-site.com/webhook/waffo',
  successRedirectUrl: 'https://your-site.com/payment/success',
  failedRedirectUrl: 'https://your-site.com/payment/failed',
  cancelRedirectUrl: 'https://your-site.com/payment/cancel',
  userInfo: {
    userId: 'user_123',
    userEmail: 'user@example.com',
    userTerminal: 'WEB',
  },
  paymentInfo: { productName: 'ONE_TIME_PAYMENT' },
  goodsInfo: {
    goodsName: 'Premium Plan',
    goodsUrl: 'https://your-site.com/product/001',
  },
});
```

## Java (using the SDK)

```java theme={null}
import com.waffo.Waffo;
import com.waffo.types.config.WaffoConfig;
import com.waffo.types.config.Environment;
import com.waffo.types.ApiResponse;
import com.waffo.types.order.*;
import com.waffo.types.payment.ProductName;
import com.waffo.types.iso.CurrencyCode;
import java.util.UUID;

WaffoConfig config = WaffoConfig.builder()
    .apiKey(System.getenv("WAFFO_API_KEY"))
    .privateKey(System.getenv("WAFFO_PRIVATE_KEY"))
    .waffoPublicKey(System.getenv("WAFFO_PUBLIC_KEY"))
    .merchantId(System.getenv("WAFFO_MERCHANT_ID"))
    .environment(Environment.SANDBOX)
    .build();
Waffo waffo = new Waffo(config);

String paymentRequestId = UUID.randomUUID().toString().replace("-", "");
CreateOrderParams params = CreateOrderParams.builder()
    .paymentRequestId(paymentRequestId)
    .merchantOrderId("ORDER_" + System.currentTimeMillis())
    .orderCurrency(CurrencyCode.HKD)
    .orderAmount("100.00")
    .orderDescription("Premium Plan")
    .notifyUrl("https://your-site.com/webhook/waffo")
    .successRedirectUrl("https://your-site.com/payment/success")
    .failedRedirectUrl("https://your-site.com/payment/failed")
    .cancelRedirectUrl("https://your-site.com/payment/cancel")
    .userInfo(UserInfo.builder()
        .userId("user_123")
        .userEmail("user@example.com")
        .userTerminal(UserTerminalType.WEB)
        .build())
    .paymentInfo(PaymentInfo.builder()
        .productName(ProductName.ONE_TIME_PAYMENT)
        .build())
    .goodsInfo(GoodsInfo.builder()
        .goodsName("Premium Plan")
        .goodsUrl("https://your-site.com/product/001")
        .build())
    .build();

ApiResponse<CreateOrderData> response = waffo.order().create(params);
```

## Go (using the SDK)

```go theme={null}
import (
    "context"
    "strings"

    "github.com/google/uuid"
    waffo "github.com/waffo-com/waffo-go/v2"
    "github.com/waffo-com/waffo-go/v2/config"
    "github.com/waffo-com/waffo-go/v2/types/order"
)

cfg, _ := config.NewConfigBuilder().
    APIKey(os.Getenv("WAFFO_API_KEY")).
    PrivateKey(os.Getenv("WAFFO_PRIVATE_KEY")).
    WaffoPublicKey(os.Getenv("WAFFO_PUBLIC_KEY")).
    MerchantID(os.Getenv("WAFFO_MERCHANT_ID")).
    Environment(config.Sandbox).
    Build()

client := waffo.New(cfg)
paymentRequestID := strings.ReplaceAll(uuid.New().String(), "-", "")

resp, err := client.Order().Create(context.Background(), &order.CreateOrderParams{
    PaymentRequestID:   paymentRequestID,
    MerchantOrderID:    "ORDER-" + uuid.New().String()[:8],
    OrderCurrency:      "HKD",
    OrderAmount:        "100.00",
    OrderDescription:   "Premium Plan",
    NotifyURL:          "https://your-site.com/webhook/waffo",
    SuccessRedirectURL: "https://your-site.com/payment/success",
    FailedRedirectURL:  "https://your-site.com/payment/failed",
    CancelRedirectURL:  "https://your-site.com/payment/cancel",
    UserInfo: &order.UserInfo{
        UserID:       "user_123",
        UserEmail:    "user@example.com",
        UserTerminal: "WEB",
    },
    PaymentInfo: &order.PaymentInfo{
        ProductName: "ONE_TIME_PAYMENT",
    },
    GoodsInfo: &order.GoodsInfo{
        GoodsName: "Premium Plan",
        GoodsURL:  "https://your-site.com/product/001",
    },
}, nil)
```

## Python (using the SDK)

```python theme={null}
import os
from uuid import uuid4

from waffo import Environment, Waffo, WaffoConfig

waffo = Waffo(
    WaffoConfig(
        api_key=os.environ["WAFFO_API_KEY"],
        private_key=os.environ["WAFFO_PRIVATE_KEY"],
        waffo_public_key=os.environ["WAFFO_PUBLIC_KEY"],
        merchant_id=os.environ["WAFFO_MERCHANT_ID"],
        environment=Environment.SANDBOX,
    )
)

payment_request_id = uuid4().hex
response = waffo.order().create(
    {
        "paymentRequestId": payment_request_id,
        "merchantOrderId": f"ORDER_{payment_request_id}",
        "orderCurrency": "HKD",
        "orderAmount": "100.00",
        "orderDescription": "Premium Plan",
        "notifyUrl": "https://your-site.com/webhook/waffo",
        "successRedirectUrl": "https://your-site.com/payment/success",
        "failedRedirectUrl": "https://your-site.com/payment/failed",
        "cancelRedirectUrl": "https://your-site.com/payment/cancel",
        "userInfo": {
            "userId": "user_123",
            "userEmail": "user@example.com",
            "userTerminal": "WEB",
        },
        "paymentInfo": {"productName": "ONE_TIME_PAYMENT"},
        "goodsInfo": {
            "goodsName": "Premium Plan",
            "goodsUrl": "https://your-site.com/product/001",
        },
    }
)
```

## Raw HTTP

```bash theme={null}
curl -X POST https://api-sandbox.waffo.com/api/v1/order/create \
  -H "Content-Type: application/json" \
  -H "X-API-KEY: YOUR_API_KEY" \
  -H "X-SIGNATURE: YOUR_RSA_SIGNATURE" \
  -H "X-API-VERSION: 1.0.0" \
  -d '{
    "paymentRequestId": "abc123def456",
    "merchantOrderId": "ORDER_001",
    "orderCurrency": "HKD",
    "orderAmount": "100.00",
    "orderDescription": "Premium Plan",
    "orderRequestedAt": "2026-08-06T00:00:00.000Z",
    "notifyUrl": "https://your-site.com/webhook/waffo",
    "successRedirectUrl": "https://your-site.com/payment/success",
    "failedRedirectUrl": "https://your-site.com/payment/failed",
    "cancelRedirectUrl": "https://your-site.com/payment/cancel",
    "merchantInfo": { "merchantId": "M000001" },
    "userInfo": {
      "userId": "user_123",
      "userEmail": "user@example.com",
      "userTerminal": "WEB"
    },
    "paymentInfo": { "productName": "ONE_TIME_PAYMENT" },
    "goodsInfo": {
      "goodsName": "Premium Plan",
      "goodsUrl": "https://your-site.com/product/001"
    }
  }'
```
