Fyber 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Fyber --version 1.0.0
NuGet\Install-Package Fyber -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fyber" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fyber" Version="1.0.0" />
<PackageReference Include="Fyber" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Fyber --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Fyber, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Fyber@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fyber&version=1.0.0
#tool nuget:?package=Fyber&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Fyber .NET SDK
Official .NET SDK for the Fyber Payment API.
Requirements
- .NET 8.0 or higher
Installation
dotnet add package Fyber
Or via the NuGet Package Manager:
Install-Package Fyber
Quick Start
using Fyber;
using Fyber.Models;
// Initialize the client
var fyber = new FyberClient("sk_test_your_api_key", new FyberClientOptions
{
Environment = "test" // or "live" for production
});
// Create a payment
var payment = await fyber.Payments.CreateAsync(new CreatePaymentRequest
{
Amount = 1000, // Amount in cents ($10.00)
Currency = "USD",
Source = new CardSource
{
Number = "4111111111111111",
ExpMonth = 12,
ExpYear = 2025,
Cvv = "123",
Name = "John Doe"
},
Description = "Order #12345"
});
Console.WriteLine($"Payment created: {payment.Id}");
Console.WriteLine($"Status: {payment.Status}");
Hosted Checkout (Recommended)
The easiest way to accept payments. Redirect customers to a Fyber-hosted checkout page that handles card input, validation, and 3DS authentication.
// Create a checkout session
var session = await fyber.Checkout.Sessions.CreateAsync(new CreateCheckoutSessionRequest
{
Mode = "payment",
Amount = 5000, // $50.00 in cents
Currency = "JMD",
SuccessUrl = "https://yoursite.com/success?session_id={SESSION_ID}",
CancelUrl = "https://yoursite.com/cancel",
LineItems = new List<LineItem>
{
new LineItem { Name = "Pro Plan", Quantity = 1, UnitAmount = 5000 }
},
CustomerEmail = "customer@example.com",
Metadata = new Dictionary<string, object>
{
{ "orderId", "1234" }
}
});
// Redirect customer to checkout
return Redirect(session.Url);
After payment, the customer is redirected to your success URL. Use webhooks to confirm payment:
// Retrieve the session to verify payment
var session = await fyber.Checkout.Sessions.GetBySessionIdAsync("cs_test_...");
if (session.Status == "complete")
{
// Payment successful, fulfill the order
Console.WriteLine($"Payment ID: {session.PaymentId}");
}
Checkout modes:
payment- One-time payment (default)setup- Save card for future use without chargingsubscription- Start a recurring subscription
Payment intents:
sale- Charge immediately (default)authorize- Authorize only, capture laterverify- Validate card with $0 auth
// Expire a session manually
await fyber.Checkout.Sessions.ExpireAsync(session.Id);
// List all sessions
var sessions = await fyber.Checkout.Sessions.ListAsync(new ListCheckoutSessionsOptions
{
Status = "complete",
Limit = 20
});
Payments
Create a Payment
var payment = await fyber.Payments.CreateAsync(new CreatePaymentRequest
{
Amount = 5000,
Currency = "USD",
Source = new CardSource
{
Number = "4111111111111111",
ExpMonth = 12,
ExpYear = 2025,
Cvv = "123"
},
Customer = new CustomerInput
{
Email = "customer@example.com",
Name = "John Doe"
},
Capture = true, // Capture immediately (default)
Metadata = new Dictionary<string, object>
{
{ "orderId", "12345" }
}
});
Authorize and Capture Separately
// Authorize only
var payment = await fyber.Payments.CreateAsync(new CreatePaymentRequest
{
Amount = 5000,
Currency = "USD",
Source = new CardSource { /* ... */ },
Capture = false
});
// Capture later
var captured = await fyber.Payments.CaptureAsync(payment.Id);
// Or capture a partial amount
var captured = await fyber.Payments.CaptureAsync(payment.Id, new CapturePaymentRequest
{
Amount = 3000 // Capture $30 of the $50 authorized
});
Retrieve a Payment
var payment = await fyber.Payments.GetAsync("pay_abc123");
List Payments
var payments = await fyber.Payments.ListAsync(new ListPaymentsOptions
{
Limit = 10,
Status = "succeeded"
});
foreach (var payment in payments.Data)
{
Console.WriteLine($"{payment.Id}: {payment.Amount}");
}
Cancel a Payment
await fyber.Payments.CancelAsync("pay_abc123");
Refunds
Create a Refund
// Full refund
var refund = await fyber.Refunds.CreateAsync(new CreateRefundRequest
{
PaymentId = "pay_abc123"
});
// Partial refund
var refund = await fyber.Refunds.CreateAsync(new CreateRefundRequest
{
PaymentId = "pay_abc123",
Amount = 500, // Refund $5.00
Reason = "Customer request"
});
Retrieve a Refund
var refund = await fyber.Refunds.GetAsync("ref_abc123");
List Refunds
var refunds = await fyber.Refunds.ListAsync(new ListRefundsOptions
{
PaymentId = "pay_abc123"
});
Customers
Create a Customer
var customer = await fyber.Customers.CreateAsync(new CreateCustomerRequest
{
Email = "customer@example.com",
Name = "John Doe",
Phone = "+1234567890",
Address = new Address
{
Line1 = "123 Main St",
City = "Kingston",
PostalCode = "12345",
Country = "JM"
}
});
Update a Customer
var customer = await fyber.Customers.UpdateAsync("cus_abc123", new UpdateCustomerRequest
{
Name = "Jane Doe",
Phone = "+0987654321"
});
Delete a Customer
await fyber.Customers.DeleteAsync("cus_abc123");
List Customers
var customers = await fyber.Customers.ListAsync(new ListCustomersOptions
{
Limit = 20,
Email = "customer@example.com"
});
Webhooks
Verify Webhook Signature
using Fyber;
using Fyber.Models;
// In your webhook handler (e.g., ASP.NET Core controller)
[HttpPost("webhook")]
public IActionResult HandleWebhook()
{
var payload = new StreamReader(Request.Body).ReadToEnd();
var signature = Request.Headers["fyber-signature"].ToString();
var secret = "whsec_your_webhook_secret";
try
{
var webhookEvent = FyberClient.VerifyWebhook(payload, signature, secret);
// Handle the event
switch (webhookEvent.Type)
{
case "checkout.session.completed":
// Checkout payment successful - fulfill order
break;
case "payment.succeeded":
// Handle successful payment
break;
case "payment.failed":
// Handle failed payment
break;
case "refund.created":
// Handle refund
break;
}
return Ok();
}
catch (Fyber.Exceptions.FyberException ex)
{
// Invalid signature
return BadRequest("Invalid signature");
}
}
Error Handling
using Fyber.Exceptions;
try
{
var payment = await fyber.Payments.CreateAsync(request);
}
catch (FyberException ex)
{
Console.WriteLine($"Error: {ex.Message}");
Console.WriteLine($"Type: {ex.Type}");
Console.WriteLine($"Code: {ex.ErrorCode}");
Console.WriteLine($"Status: {ex.StatusCode}");
}
Configuration
var fyber = new FyberClient("sk_test_xxx", new FyberClientOptions
{
Environment = "live", // "test" or "live"
BaseUrl = "https://...", // Custom API URL (optional)
Timeout = 60 // Request timeout in seconds
});
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- System.Text.Json (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release of the Fyber .NET SDK