Complete your first payment flow with the nekuda SDK in under 5 minutes.
Welcome to the rapid-fire tour of the nekuda SDK. In less than five minutes you will:
Install the package
Authenticate with your API key
Run your first card-reveal workflow with type-safe responses
This SDK handles the backend payment processing. Youโll also need to integrate our frontend wallet SDK to securely collect credit card details from users.
Grab your secret key from the nekuda Dashboard and export it as an environment variable:
Copy
Ask AI
export NEKUDA_API_KEY="sk_live_โฆ" # required# The SDK defaults to the production API: https://api.nekuda.ai# For staging or local testing, you can override the base URL:# export NEKUDA_BASE_URL="https://staging-api.nekuda.ai"
Thatโs all the configuration you need for the quickstart.
from nekuda import NekudaClientclient = NekudaClient.from_env()print("๐ Authenticated! Your account ID is:", client.api_key[:8] + "โฆ")
Copy
Ask AI
python hello.py
hello.py
Copy
Ask AI
from nekuda import NekudaClientclient = NekudaClient.from_env()print("๐ Authenticated! Your account ID is:", client.api_key[:8] + "โฆ")
Copy
Ask AI
python hello.py
hello.ts
Copy
Ask AI
import { NekudaClient } from '@nekuda/nekuda-js';const client = NekudaClient.fromEnv();console.log("๐ Authenticated! Your account ID is:", (client as any).apiKey.slice(0, 8) + "โฆ");
Copy
Ask AI
npx ts-node hello.ts
If everything is set up correctly you should see:
Copy
Ask AI
๐ Authenticated! Your account ID is: sk_live_12โฆ
The snippet below walks through the full payment flow with type-safe responses. This flow requires a user_id to associate the payment with a user, and a mandate_id which is obtained after creating a mandate (the userโs intent to purchase).
quick_demo.py
Copy
Ask AI
from nekuda import MandateData, NekudaClient, NekudaErrorclient = NekudaClient.from_env()# A unique identifier for your user is required.user_id = "user_example_123"user = client.user(user_id)try: # 1) Describe what the user is about to purchase and create a mandate. # This step is crucial to get a mandate_id for token requests. mandate = MandateData( product="Premium Subscription", price=49.99, currency="USD", merchant="nekuda Corp" ) # Create mandate - returns MandateCreateResponse # The user_id is implicitly passed via the user object. mandate_response = user.create_mandate(mandate) print(f"โ Created mandate: {mandate_response.mandate_id} for user: {user_id}") # 2) Request a reveal token using the mandate_id. # This token is short-lived and single-use. reveal_response = user.request_card_reveal_token(mandate_response.mandate_id) print(f"๐ Token: {reveal_response.reveal_token}") # IDE knows these fields exist! No more KeyErrors! if reveal_response.expires_at: print(f"โฐ Expires at: {reveal_response.expires_at}") # 3) Exchange token for card details (returns CardDetailsResponse). # The user_id is implicitly passed here as well. card = user.reveal_card_details(reveal_response.reveal_token) print(f"๐ณ **** **** **** {card.card_number[-4:]}") print(f"๐ Expiry: {card.card_expiry_date}") # Always MM/YY format print(f"๐ค Name: {card.cardholder_name}")except NekudaError as e: print(f"โ Error: {e}")
quick_demo.py
Copy
Ask AI
from nekuda import MandateData, NekudaClient, NekudaErrorclient = NekudaClient.from_env()# A unique identifier for your user is required.user_id = "user_example_123"user = client.user(user_id)try: # 1) Describe what the user is about to purchase and create a mandate. # This step is crucial to get a mandate_id for token requests. mandate = MandateData( product="Premium Subscription", price=49.99, currency="USD", merchant="nekuda Corp" ) # Create mandate - returns MandateCreateResponse # The user_id is implicitly passed via the user object. mandate_response = user.create_mandate(mandate) print(f"โ Created mandate: {mandate_response.mandate_id} for user: {user_id}") # 2) Request a reveal token using the mandate_id. # This token is short-lived and single-use. reveal_response = user.request_card_reveal_token(mandate_response.mandate_id) print(f"๐ Token: {reveal_response.reveal_token}") # IDE knows these fields exist! No more KeyErrors! if reveal_response.expires_at: print(f"โฐ Expires at: {reveal_response.expires_at}") # 3) Exchange token for card details (returns CardDetailsResponse). # The user_id is implicitly passed here as well. card = user.reveal_card_details(reveal_response.reveal_token) print(f"๐ณ **** **** **** {card.card_number[-4:]}") print(f"๐ Expiry: {card.card_expiry_date}") # Always MM/YY format print(f"๐ค Name: {card.cardholder_name}")except NekudaError as e: print(f"โ Error: {e}")
quick_demo.ts
Copy
Ask AI
import { NekudaClient, MandateData, NekudaError } from '@nekuda/nekuda-js';async function main() { const client = NekudaClient.fromEnv(); const user = client.user('user_example_123'); try { // 1) Describe what the user is about to purchase const mandate = new MandateData({ product: 'Premium Subscription', price: 49.99, currency: 'USD', merchant: 'Nekuda Corp' }); // Create mandate - returns MandateCreateResponse const mandateResponse = await user.createMandate(mandate); console.log(`โ Created mandate: ${mandateResponse.mandateId}`); // 2) Request a reveal token - returns CardRevealTokenResponse const revealResponse = await user.requestCardRevealToken(mandateResponse.mandateId); console.log(`๐ Token: ${revealResponse.revealToken}`); // TypeScript knows these fields exist! No more undefined errors! if (revealResponse.expiresAt) { console.log(`โฐ Expires at: ${revealResponse.expiresAt}`); } // 3) Exchange token for card details - returns CardDetailsResponse const card = await user.revealCardDetails(revealResponse.revealToken); console.log(`๐ณ **** **** **** ${card.cardNumber.slice(-4)}`); console.log(`๐ Expiry: ${card.cardExpiryDate}`); // Always MM/YY format console.log(`๐ค Name: ${card.cardholderName}`); } catch (error) { if (error instanceof NekudaError) { console.log(`โ Error: ${error.message}`); } else { console.log(`โ Unexpected error: ${error}`); } }}main().catch(console.error);
Run it and youโll see the card details with full type safety and IDE autocomplete support!
Complete Integration: Remember that in a real application, creating a mandate and requesting a token happen on your backend (using this SDK), while the actual card collection happens on your frontend using our React wallet SDK. A user_id must be consistently used for both frontend and backend operations for a given user.