Fyber API Quickstart
Get started with Fyber's payment API in 5 minutes.
1. Get Your API Keys
- Log in to console.fyber.one
- Go to Developer > API Keys
- Copy your test keys:
pk_test_...(publishable - for client-side)sk_test_...(secret - for server-side)
2. Install the SDK
JavaScript/Node.js
bash
npm install @fyber.one/sdk-js
# or
pnpm add @fyber.one/sdk-jsPHP
bash
composer require fyber/sdk-phpC#/.NET
bash
dotnet add package FyberFlutter/Dart
bash
flutter pub add fyberPython (Coming Soon)
bash
pip install fyber # Not yet available3. Initialize the Client
Node.js
javascript
import { Fyber } from '@fyber.one/sdk-js';
const fyber = new Fyber({
apiKey: 'sk_test_your_secret_key',
environment: 'test', // or 'live'
});PHP
php
use Fyber\Fyber;
$fyber = new Fyber('sk_test_your_secret_key', [
'environment' => 'test', // or 'live'
]);C#
csharp
using Fyber;
var fyber = new FyberClient("sk_test_your_secret_key", new FyberClientOptions
{
Environment = "test" // or "live"
});Flutter
dart
import 'package:fyber/fyber.dart';
final fyber = Fyber(
apiKey: 'sk_test_your_secret_key',
environment: 'test', // or 'live'
);4. Create Your First Payment
Using Hosted Checkout (Recommended)
Hosted Checkout is the easiest and most secure way to accept payments. It handles PCI compliance and 3D Secure automatically.
javascript
// Create a checkout session
const session = await fyber.checkout.sessions.create({
mode: 'payment',
intent: 'sale',
amount: 5000, // $50.00 in cents
currency: 'JMD',
successUrl: 'https://your-site.com/success?session_id={SESSION_ID}',
cancelUrl: 'https://your-site.com/cancel',
customerEmail: 'customer@example.com',
lineItems: [{
name: 'Premium Plan',
quantity: 1,
unitAmount: 5000
}]
});
// Redirect customer to hosted checkout
console.log(session.url);
// Redirect the customer to this URL5. Handle Webhooks
Webhooks notify your server when payment events occur.
javascript
import express from 'express';
import { Fyber } from '@fyber.one/sdk-js';
const app = express();
app.post('/webhooks/fyber', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['fyber-signature'];
const webhookSecret = 'whsec_your_webhook_secret';
let event;
try {
event = Fyber.webhooks.verify(
req.body.toString(),
signature,
webhookSecret
);
} catch (err) {
console.error('Webhook verification failed:', err.message);
return res.status(400).send(`Webhook Error: ${err.message}`);
}
switch (event.type) {
case 'payment.succeeded':
console.log(`Payment ${event.data.object.id} succeeded!`);
// Fulfill the order
break;
case 'payment.failed':
console.log('Payment failed:', event.data.object.failureReason);
break;
case 'checkout.session.completed':
console.log(`Checkout session ${event.data.object.sessionId} completed`);
// Fulfill the order from checkout
break;
}
res.json({ received: true });
});6. Test Cards
Use these test card numbers in test mode:
| Card | Number | Result |
|---|---|---|
| Visa (Success) | 4242 4242 4242 4242 | Approved |
| Mastercard (Success) | 5555 5555 5555 4444 | Approved |
| Visa (Decline) | 4000 0000 0000 0002 | Declined |
| 3DS Required | 4000 0027 6000 3184 | Requires 3D Secure |
| Insufficient Funds | 4000 0000 0000 9995 | Insufficient funds |
Use any future expiry date and any 3-digit CVV.
API Reference
Full API documentation: docs.fyber.one
Base URLs
| Environment | URL |
|---|---|
| Sandbox | https://api.sandbox.fyber.one |
| Production | https://api.fyber.one |
Common Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /checkout/sessions | Create checkout session |
| GET | /checkout/sessions/:id | Retrieve checkout session |
| POST | /payments | Create a payment |
| GET | /payments/:id | Retrieve a payment |
| POST | /payments/:id/capture | Capture an authorized payment |
| POST | /refunds | Create a refund |
| GET | /customers | List customers |
| POST | /customers | Create a customer |
| POST | /tokens | Create a saved card token |
| POST | /subscriptions | Create subscription |
| POST | /installments | Create installment plan |
Error Handling
javascript
try {
const session = await fyber.checkout.sessions.create({...});
} catch (error) {
if (error.code === 'card_declined') {
console.log('Card was declined:', error.message);
} else if (error.code === 'validation_error') {
console.log('Invalid request:', error.message);
} else if (error.code === 'authentication_error') {
console.log('Invalid API key');
} else {
console.log('Error:', error.message);
}
}Error Codes
| Code | Description |
|---|---|
card_declined | Card was declined |
validation_error | Invalid request parameters |
authentication_error | Invalid API key |
rate_limit_error | Too many requests |
api_error | Server error |
Next Steps
- Hosted Checkout Guide - Accept payments securely
- Webhooks Guide - Handle payment events
- Subscriptions - Recurring billing
- Installments/BNPL - Buy Now Pay Later
- Card Tokenization - Save cards for future payments
Need help? Email support@fyber.one