diff --git a/identity-service/default-config.json b/identity-service/default-config.json index d6a04aa4667..610aa3cd283 100644 --- a/identity-service/default-config.json +++ b/identity-service/default-config.json @@ -4,7 +4,7 @@ "redisHost": "identity-redis", "redisPort": 6379, "logLevel": "debug", - "ipdataAPIKey":"", + "ipdataAPIKey": "", "twitterAPIKey": "", "twitterAPISecret": "", "tikTokAPIKey": "", @@ -70,5 +70,6 @@ "hCaptchaSecret": "", "solanaFeePayerWallets": "[]", "sentryDSN": "", - "solanaEndpoint": "https://api.mainnet-beta.solana.com" + "solanaEndpoint": "https://api.mainnet-beta.solana.com", + "stripeSecretKey": "" } diff --git a/identity-service/src/config.js b/identity-service/src/config.js index 45b6cff12af..5921ae7a5c2 100644 --- a/identity-service/src/config.js +++ b/identity-service/src/config.js @@ -809,6 +809,12 @@ const config = convict({ format: String, env: 'cognitoRetrySecret', default: '' + }, + stripeSecretKey: { + doc: 'Secret key for Stripe Crypto On-Ramp Integration', + format: String, + env: 'stripeSecretKey', + default: '' } }) diff --git a/identity-service/src/routes/stripe.js b/identity-service/src/routes/stripe.js new file mode 100644 index 00000000000..f19d662078c --- /dev/null +++ b/identity-service/src/routes/stripe.js @@ -0,0 +1,64 @@ +const { + handleResponse, + successResponse, + errorResponse, + errorResponseBadRequest +} = require('../apiHelpers') +const config = require('../config') +const axios = require('axios') +const axiosHttpAdapter = require('axios/lib/adapters/http') +const { logger } = require('../logging') + +const createAuthHeader = () => { + const secretKey = config.get('stripeSecretKey') + return { + Authorization: `Basic ${Buffer.from(secretKey + ':', 'utf-8').toString( + 'base64' + )}` + } +} + +module.exports = function (app) { + app.post( + '/stripe/session', + handleResponse(async (req) => { + const { destinationWallet, amount } = req.body + + if (!destinationWallet || !amount) { + return errorResponseBadRequest('Missing destinationWallet or amount') + } + + const urlEncodedData = new URLSearchParams({ + customer_wallet_address: destinationWallet, + 'transaction_details[wallet_address]': destinationWallet, + 'transaction_details[supported_destination_networks][]': 'solana', + 'transaction_details[supported_destination_currencies][]': 'sol', + 'transaction_details[destination_network]': 'solana', + 'transaction_details[destination_currency]': 'sol', + 'transaction_details[destination_exchange_amount]': amount + }) + + try { + const req = { + adapter: axiosHttpAdapter, + url: 'https://api.stripe.com/v1/crypto/onramp_sessions', + method: 'POST', + headers: { + // Required form-urlencoded for the Stripe API + 'Content-Type': 'application/x-www-form-urlencoded', + ...createAuthHeader() + }, + data: urlEncodedData + } + const response = await axios(req) + return successResponse(response.data) + } catch (e) { + logger.error('Failed to create Stripe session:', e.response.data) + return errorResponse( + e.response.status, + 'Failed to create Stripe session' + ) + } + }) + ) +}