package main

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"strings"
	"time"
)

type PayinRequest struct {
	OrderID     string `json:"order_id"`
}

func main() {

	secret := "{{YOUR_SECRET_KEY}}"
	path := "api/v1/payin/transactions"
	method := "POST"

	data := PayinRequest{
		OrderID:     "adsd-ewerz-23sdsd-ad234",
	}

	// Marshal JSON (ordered because struct)
	jsonData, _ := json.Marshal(data)

	
	jsonPHP := strings.ReplaceAll(string(jsonData), "/", "\\/")

	
	timestamp := time.Now().UnixMilli()

	
	message := fmt.Sprintf(
		"%s\n%s\n%s\n%d\n",
		method,
		path,
		jsonPHP,
		timestamp,
	)

	h := hmac.New(sha256.New, []byte(secret))
	h.Write([]byte(message))
	signature := hex.EncodeToString(h.Sum(nil))

	
	fmt.Println("Signature:", signature)
	fmt.Println("Timestamp:", timestamp)
}
