Skip to main content
Version: 4.0

Configuration

Registering Parbad​

With Microsoft dependency injection (ASP.NET Core)​

builder.Services.AddParbad()
.ConfigureGateways(gateways => { /* ... */ })
.ConfigureHttpContext(httpContext => httpContext.UseDefaultAspNetCore())
.ConfigureStorage(storage => { /* ... */ });

Then inject IOnlinePayment wherever you need it.

With another container (such as Autofac)​

var parbad = ParbadBuilder.CreateDefaultBuilder()
.ConfigureGateways(gateways => { /* ... */ })
.ConfigureHttpContext(httpContext => httpContext.UseOwinFromCurrentHttpContext())
.ConfigureStorage(storage => { /* ... */ });

containerBuilder.Populate(parbad.Services);

Without dependency injection​

Build Parbad once when the application starts:

ParbadBuilder.CreateDefaultBuilder()
.ConfigureGateways(gateways => { /* ... */ })
.ConfigureHttpContext(httpContext => httpContext.UseOwinFromCurrentHttpContext())
.ConfigureStorage(storage => { /* ... */ })
.Build();

Then create one scope per web request and dispose it at the end of the request:

using (var scope = StaticOnlinePayment.CreateScope())
{
var result = await scope.OnlinePayment.RequestAsync(invoice => { /* ... */ });
}

Gateway accounts​

One account​

.ConfigureGateways(gateways =>
{
gateways
.AddMellat()
.WithAccounts(accounts =>
{
accounts.AddInMemory(account =>
{
account.TerminalId = 123;
account.UserName = "<Your username>";
account.UserPassword = "<Your password>";
});
});
})

Several accounts for one gateway​

Give each account a name, and choose it per invoice with UseAccount("..."):

gateways
.AddMellat()
.WithAccounts(accounts =>
{
accounts.AddInMemory(account =>
{
account.Name = "Shop";
// ...
});

accounts.AddInMemory(account =>
{
account.Name = "Donations";
// ...
});
});

Accounts from a database or a service​

Implement IGatewayAccountSource<TAccount>. Parbad asks the source for the accounts each time it processes a payment, so changes take effect immediately. The source can inject your own services:

public class MellatAccounts : IGatewayAccountSource<MellatGatewayAccount>
{
private readonly ISettingsService _settings;

public MellatAccounts(ISettingsService settings) => _settings = settings;

public async Task AddAccountsAsync(IGatewayAccountCollection<MellatGatewayAccount> accounts)
{
var settings = await _settings.GetMellatSettingsAsync();

accounts.Add(new MellatGatewayAccount
{
TerminalId = settings.TerminalId,
UserName = settings.UserName,
UserPassword = settings.UserPassword
});
}
}
gateways
.AddMellat()
.WithAccounts(accounts => accounts.Add<MellatAccounts>(ServiceLifetime.Transient));

Web application integration​

ApplicationPackageConfiguration
ASP.NET CoreParbad.AspNetCore.ConfigureHttpContext(builder => builder.UseDefaultAspNetCore())
ASP.NET MVC 5Parbad.Mvc5.ConfigureHttpContext(builder => builder.UseOwinFromCurrentHttpContext())
ASP.NET WebFormsParbad.Owin.ConfigureHttpContext(builder => builder.UseOwinFromCurrentHttpContext())

Options​

.ConfigureOptions(options =>
{
// The messages of the results.
options.Messages.PaymentSucceed = "Thank you for your payment.";

// Parbad logs with ILogger; this turns it off.
options.EnableLogging = false;

// The timeout of every call to a gateway (default: 30 seconds).
options.GatewayTimeout = TimeSpan.FromSeconds(20);

// With a Content-Security-Policy nonce: the nonce of the current request, used by the pages that send the
// customer to the bank and by the Virtual Gateway.
options.NonceFactory = httpContext => (string)httpContext.Items["csp-nonce"]!;
})

Tracking numbers​

UseAutoIncrementTrackingNumber() and UseAutoRandomTrackingNumber() give each invoice a tracking number. Their options:

.ConfigureAutoIncrementTrackingNumber(options =>
{
options.MinimumValue = 1000;
options.Increment = 1;
})
.ConfigureAutoRandomTrackingNumber(options => options.MinimumValue = 1000)