
go-thunes
Go SDK for Thunes Money Transfer API.
CHINESE README
δΈζθ―΄ζ
Main Features
π Worldwide Money Transfers: Send money across 130+ countries through mobile wallets, bank accounts, and cash pickup
π± Quotation Management: Lock exchange rates and calculate fees before creating transactions
π Transaction Lifecycle: Complete transaction flow from quotation to confirmation with status tracking
π° Balance Monitoring: Track available, pending, and credit balances across currencies
π¦ Payer Information: Access payer data (banks and mobile wallets) with filters
β‘ Auto Retries: Built-in mechanism with backoff when network issues happen
Installation
go get github.com/yylego/go-thunes
Prerequisites
Usage
Complete transaction workflow from quotation to confirmation:
package main
import (
"context"
"encoding/hex"
"fmt"
"log"
"os"
"github.com/yylego/go-thunes/thunes"
"github.com/google/uuid"
"github.com/yylego/must"
)
func main() {
// Initialize client
client := thunes.NewClient(&thunes.Config{
BaseURL: must.Nice(os.Getenv("THUNES_BASE_URL")),
RequestKey: must.Nice(os.Getenv("THUNES_REQUEST_KEY")),
RequestSecret: must.Nice(os.Getenv("THUNES_REQUEST_SECRET")),
})
ctx := context.Background()
// Generate unique ID
quotationID := newUUID()
// Step 1: Create quotation
quotation, exc := client.CreateQuotation(ctx, &thunes.CreateQuotationParam{
ExternalID: quotationID,
PayerID: "3460",
Mode: thunes.DestinationAmount,
TransactionType: "C2C",
Source: &thunes.SourceInput{
CountryIsoCode: "KHM",
Currency: "USD",
},
Destination: &thunes.DestinationInput{
Amount: "100",
Currency: "CNY",
},
})
if exc != nil {
log.Fatal(exc)
}
fmt.Printf("Quotation created: %s\n", quotation.ExternalID)
// Step 2: Retrieve quotation
quotation, exc = client.GetQuotation(ctx, quotationID)
if exc != nil {
log.Fatal(exc)
}
fmt.Printf("Quotation retrieved: Rate=%s\n", quotation.WholesaleFxRate)
// Step 3: Create transaction
transactionID := newUUID()
transaction, exc := client.CreateTransaction(ctx, quotationID, &thunes.CreateTransactionParam{
ExternalID: transactionID,
CreditPartyIdentifier: map[string]string{
"msisdn": "+86xxxxxxxxxx",
},
Beneficiary: map[string]string{
"lastname": "Zhang",
"firstname": "San",
},
Sender: map[string]string{
"lastname": "Li",
"firstname": "Si",
"country_of_birth": "CHN",
"nationality": "CHN",
},
PurposeOfRemittance: "PERSONAL_TRANSFER",
CallbackUrl: "https://your-callback-url.com/webhook",
})
if exc != nil {
log.Fatal(exc)
}
fmt.Printf("Transaction created: %s\n", transaction.ExternalID)
// Step 4: Retrieve transaction
transaction, exc = client.GetTransaction(ctx, transactionID)
if exc != nil {
log.Fatal(exc)
}
fmt.Printf("Transaction status: %s\n", transaction.StatusMessage)
// Step 5: Confirm transaction
transaction, exc = client.ConfirmTransaction(ctx, transactionID)
if exc != nil {
log.Fatal(exc)
}
fmt.Printf("Transaction confirmed: %s\n", transaction.StatusMessage)
// Step 6: Check final status
transaction, exc = client.GetTransaction(ctx, transactionID)
if exc != nil {
log.Fatal(exc)
}
fmt.Printf("Final status: %s (Class: %s)\n", transaction.StatusMessage, transaction.StatusClass)
}
func newUUID() string {
u := uuid.New()
return hex.EncodeToString(u[:])
}
β¬οΈ Source: Source
API Reference
GetPing() - Health check endpoint
CreateQuotation() - Create quotation with locked exchange rate
GetQuotation() - Retrieve quotation using external ID
CreateTransaction() - Create transaction from quotation
GetTransaction() - Retrieve transaction using external ID
ConfirmTransaction() - Confirm transaction and proceed with transfer
GetBalances() - Retrieve account balances across currencies
GetPayers() - Retrieve payer options (banks and wallets)
GetPayerRates() - Retrieve payer exchange rates using specified currency
GetCountries() - Retrieve supported countries
Important Notes
- Quotation Expiration: Quotations expire after 24 hours (standard behavior)
- Two-Step Transaction: Must invoke
CreateTransaction() then ConfirmTransaction()
- External ID: Must be unique when creating each quotation and transaction
- Callback URL: Configure webhook endpoint to receive transaction status updates
- Balance Management:
ConfirmTransaction() moves funds from available to pending balance
- Testing: Use
if false {} blocks in tests to prevent actual money transfers
Official Documentation
π License
MIT License. See LICENSE.
π€ Contributing
Contributions are welcome! Report bugs, suggest features, and contribute code:
- π Found a mistake? Open an issue on GitHub with reproduction steps
- π‘ Have a feature idea? Create an issue to discuss the suggestion
- π Documentation confusing? Report it so we can improve
- π Need new features? Share the use cases to help us understand requirements
- β‘ Performance issue? Help us optimize through reporting slow operations
- π§ Configuration problem? Ask questions about complex setups
- π’ Follow project progress? Watch the repo to get new releases and features
- π Success stories? Share how this package improved the workflow
- π¬ Feedback? We welcome suggestions and comments
π§ Development
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git).
- Navigate: Navigate to the cloned project (
cd repo-name)
- Branch: Create a feature branch (
git checkout -b feature/xxx).
- Code: Implement the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and follow Go code style conventions
- Documentation: Update documentation to support client-facing changes and use significant commit messages
- Stage: Stage changes (
git add .)
- Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code
- Push: Push to the branch (
git push origin feature/xxx).
- PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
π Support
Welcome to contribute to this project via submitting merge requests and reporting issues.
Project Support:
- β Give GitHub stars if this project helps you
- π€ Share with teammates and (golang) programming friends
- π Write tech blogs about development tools and workflows - we provide content writing support
- π Join the ecosystem - committed to supporting open source and the (golang) development scene
Have Fun Coding with this package! πππ
GitHub Stars
