A simple backend API for processing payments with Authorize.net. Built with Next.js API routes.
- Process payments through Authorize.net
- No authentication required - all endpoints are public
- SQLite database for storing transaction records
- TypeScript for type safety
- POST
/api/payment/process
- Process a new payment through Authorize.net
- Request body:
{
"amount": number,
"cardNumber": string,
"expirationMonth": string,
"expirationYear": string,
"cvv": string,
"billingInfo": {
"firstName": string,
"lastName": string,
"address": string,
"city": string,
"state": string,
"zip": string
}
}
- Response:
{
"transactionId": string,
"status": "success" | "failed",
"message": string
}
- GET
/api/payment/transaction/:id
- Check the status of a transaction
- Response:
{
"transactionId": string,
"status": "success" | "failed",
"amount": number,
"cardLast4": string,
"errorMessage": string | null,
"createdAt": string
}
-
Clone the repository
-
Copy .env.example to .env and fill in your Authorize.net credentials:
AUTHORIZE_NET_API_LOGIN_ID=your_login_id
AUTHORIZE_NET_TRANSACTION_KEY=your_transaction_key
AUTHORIZE_NET_ENVIRONMENT=SANDBOX # or PRODUCTION
- Install dependencies:
bun install
- Initialize the database:
bunx prisma db push
- Start the development server:
bun dev
AUTHORIZE_NET_API_LOGIN_ID
: Your Authorize.net API Login IDAUTHORIZE_NET_TRANSACTION_KEY
: Your Authorize.net Transaction KeyAUTHORIZE_NET_ENVIRONMENT
: Environment to use (SANDBOX or PRODUCTION)
The project uses SQLite with Prisma ORM. Here's the main schema for transactions:
model Transaction {
id String @id @default(cuid())
amount Float
status String
transactionId String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
All API endpoints return standard error responses:
{
"error": "Error message here",
"status": 400 // HTTP status code
}