# Clone repository
git clone git@github.com:yesil/twint-node-sdk.git
cd twint-node-sdk
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env with your TWINT credentials
# Run development server
npm run devThe SDK includes a development server with real TWINT integration:
npm run devFeatures:
- Real TWINT API integration (no mocks)
- Validates connection at startup
- Logs all operations to
server.log - Web UI demo at http://localhost:3000/demo
- API endpoints for testing
POST /api/orders/start- Start new orderGET /api/orders/:orderId- Monitor order statusPOST /api/orders/:orderId/confirm- Confirm orderPOST /api/orders/:orderId/cancel- Cancel orderGET /health- Health check
Create a .env file with:
# Certificate Configuration
TWINT_CERTIFICATE_PATH=certificate.p12
TWINT_CERTIFICATE_PASSWORD=your-password
# TWINT Configuration
TWINT_STORE_UUID=your-store-uuid
# Environment: PRODUCTION, INTEGRATION, or STAGING
TWINT_ENVIRONMENT=INTEGRATION
# Server Configuration
PORT=3000
LOG_LEVEL=infoThe SDK includes a reusable web component for integration testing:
<pay-with-twint
reference="ORDER-123"
amount="99.95"
api-url="/api"
theme="light"
confirmation-needed="true">
</pay-with-twint>Run the demo:
npm run dev:demoThis starts a web server with live reload for testing the web component.
Tests use Node.js built-in test runner:
# Run all tests
npm test
# Run specific test file
node --test test/values/Money.test.js
# Run with watch mode
npm run test:watch
# Run with coverage
npm run test:coverageExample test:
import { test } from 'node:test';
import assert from 'node:assert';
import { Money } from '../src/values/Money.js';
test('Money.CHF creates Swiss Francs', () => {
const amount = Money.CHF(99.95);
assert.strictEqual(amount.amount, 99.95);
assert.strictEqual(amount.currency, 'CHF');
});# Format code
npm run format
# Check formatting
npm run format:check
# Lint code
npm run lint
# Fix linting issues
npm run lint:fixtwint-node-sdk/
├── src/
│ ├── client/ # Main TWINT client
│ │ └── TwintClient.js
│ ├── soap/ # SOAP/WSDL integration
│ │ └── SoapClient.js
│ ├── certificates/ # Certificate handling
│ │ └── Certificate.js
│ ├── values/ # Value objects
│ │ ├── Money.js
│ │ ├── OrderStatus.js
│ │ ├── Environment.js
│ │ └── Uuid.js
│ ├── components/ # Web components
│ │ └── pay-with-twint.js
│ └── index.js # Main exports
├── wsdl/ # TWINT WSDL definitions
│ └── v8.6/ # Current API version
├── demo/ # Web UI demo
│ ├── index.html
│ └── app.js
├── test/ # Test files
│ └── values/
│ └── Money.test.js
├── dev-server.js # Development server
├── .env.example # Environment template
└── package.json
Edit src/soap/SoapClient.js:
async newMethod(request) {
if (!this.#client) {
await this.initialize();
}
const [result] = await this.#client.NewMethodAsync(request);
return result;
}Edit src/client/TwintClient.js:
async newFeature(params) {
const request = {
MerchantInformation: this.#merchantInfo,
// ... build request
};
const response = await this.#soapClient.newMethod(request);
return this.#mapResponse(response);
}Create new value objects in src/values/:
export class NewValue {
#value;
constructor(value) {
this.#value = value;
}
get value() {
return this.#value;
}
toString() {
return this.#value.toString();
}
}Add to src/index.js:
export { NewValue } from './values/NewValue.js';Set environment variable:
SOAP_DEBUG=trueThis will:
- Log formatted XML requests/responses to console
- Save structured logs to
server.log - Show request/response correlation
- Ensure .p12 file exists and path is correct
- Check certificate password
- Verify certificate isn't expired
- Use INTEGRATION environment for development
- Ensure Store UUID matches certificate
- Check firewall/proxy settings
- Always use
.jsextension in imports - Use ES module syntax (
import/export) - Ensure Node.js 20+ is installed
- Update version in
package.json - Update CHANGELOG.md
- Run tests:
npm test - Check code quality:
npm run lint - Commit changes
- Tag release:
git tag v1.0.0 - Push with tags:
git push --tags
- Fork the repository
- Create feature branch:
git checkout -b feature/new-feature - Make changes and test
- Commit with descriptive message
- Push to your fork
- Create Pull Request
- Use ES modules (no CommonJS)
- Use private fields with
#syntax - Use async/await for asynchronous code
- No TypeScript (pure JavaScript)
- Follow existing patterns in codebase
Use conventional commits:
feat:New featurefix:Bug fixdocs:Documentationtest:Testsrefactor:Code refactoringchore:Maintenance
For development questions:
- GitHub Issues: https://github.com/yesil/twint-node-sdk/issues
- TWINT Documentation: https://www.twint.ch/en/business/