A payment provider for Medusa.js 2.0 that accepts Solana cryptocurrency payments.
- Accept Solana (SOL) cryptocurrency payments in your Medusa store
- Convert cart totals from USD/EUR to SOL
- Display wallet address for payment
- Monitor the blockchain for payment confirmation
- Support for payment authorization, capture, and refund workflows
- Medusa.js 2.0 or higher
- Node.js 16 or higher
- A Solana wallet address
npm install medusa-payment-solanaAdd the following to your medusa-config.js or medusa-config.ts:
module.exports = defineConfig({
// ...
modules: [
// ...
{
resolve: "@medusajs/medusa/payment",
options: {
providers: [
{
resolve: "medusa-payment-solana",
id: "solana",
options: {
walletAddress: process.env.SOLANA_ADDRESS,
rpcUrl: "https://api.testnet.solana.com", // Use mainnet for production
// Optional: Set a custom polling interval (in ms) for checking payments
paymentPollingInterval: 30000,
}
}
]
}
}
]
});Make sure to set the SOLANA_ADDRESS environment variable in your .env file:
SOLANA_ADDRESS=your_solana_wallet_address
- Go to Settings > Regions
- Edit a region or create a new one
- In the Payment Providers section, enable "Solana"
- Save the region
When a customer reaches the checkout page, they will be able to select "Solana" as a payment method. The checkout will display:
- The total amount in SOL
- The wallet address to send the payment to
- Instructions for completing the payment
npm run buildnpm test-
Initiate Payment: When a customer selects Solana as their payment method, the provider converts the cart total to SOL and generates a unique payment ID.
-
Display Payment Details: The storefront displays the Solana wallet address and the amount in SOL to be paid.
-
Monitor for Payment: The provider periodically checks the blockchain for incoming transactions to the specified wallet address.
-
Authorize Payment: Once a matching payment is detected, the payment is authorized.
-
Capture Payment: The payment is captured, and the order is processed.
The payment provider supports two currency conversion options:
-
Default Converter - Uses fixed exchange rates:
- 1 USD = 0.0075 SOL
- 1 EUR = 0.008 SOL
-
CoinGecko Converter - Uses real-time rates from CoinGecko API
To configure the currency converter, update your Medusa config:
{
resolve: "medusa-payment-solana",
options: {
walletAddress: process.env.SOLANA_ADDRESS,
currencyConverter: {
provider: "coingecko", // or "default"
apiKey: process.env.COINGECK_API_KEY // Required for coingecko
}
}
}When using the CoinGecko provider:
- Set the COINGECK_API_KEY in your .env file
- Ensure your API key has sufficient permissions for the CoinGecko API
- Cache exchange rates to reduce API calls
- Implement error handling for API failures
- Monitor API usage to avoid rate limits
The provider includes functionality to generate QR codes for payments, but this is not enabled by default. To enable QR codes in your storefront, you can use the generatePaymentQRCode function from the utils.ts file.
MIT