Skip to content

Commit

Permalink
Merge pull request #93 from Sina-Soltani/bug/FixingTheConfigureOption…
Browse files Browse the repository at this point in the history
…sConfiguration

Bug/fixing the configure options configuration
  • Loading branch information
Sina-Soltani authored Jun 30, 2020
2 parents e351441 + 7826ea4 commit 253a32b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ public async Task<IActionResult> Pay(PayViewModel viewModel)
}
});

// Save the result.TrackingNumber in your database.

if (result.IsSucceed)
{
return result.GatewayTransporter.TransportToGateway();
}

// Note: This is just for development and testing.
// Don't show the actual result object to clients in production environment.
// Instead, show only the important information such as IsSucceed, Tracking Number and Transaction Code.
return View("PayRequestError", result);
}

Expand All @@ -67,7 +66,7 @@ public async Task<IActionResult> Verify()
return Content("The payment is already processed before.");
}

// An example of checking the invoice in your website.
// This is an example of cancelling an invoice when you think that the payment process must be stopped.
if (!Is_There_Still_Product_In_Shop(invoice.TrackingNumber))
{
var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason: "Sorry, We have no more products to sell.");
Expand Down
7 changes: 3 additions & 4 deletions samples/Parbad.Sample.Mvc/Controllers/PaymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ public async Task<ActionResult> Pay(RequestViewModel viewModel)
}
});

// Save the result.TrackingNumber in your database.

if (result.IsSucceed)
{
return result.GatewayTransporter.TransportToGateway();
}

// Note: This is just for development and testing.
// Don't show the actual result object to clients in production environment.
// Instead, show only the important information such as IsSucceed, Tracking Number and Transaction Code.
return View("PayRequestError", result);
}

Expand All @@ -72,7 +71,7 @@ public async Task<ActionResult> Verify()
return Content("The payment is already processed before.");
}

// An example of checking the invoice in your website.
// This is an example of cancelling an invoice when you think that the payment process must be stopped.
if (!Is_There_Still_Product_In_Shop(invoice.TrackingNumber))
{
var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason: "Sorry, We have no more products to sell.");
Expand Down
5 changes: 2 additions & 3 deletions samples/Parbad.Sample.WebForm/PayRequest.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ protected async void BtnPay_Click(object sender, EventArgs e)
}
});

// Save the result.TrackingNumber in your database.

if (result.IsSucceed)
{
await result.GatewayTransporter.TransportAsync();
Expand All @@ -46,9 +48,6 @@ protected async void BtnPay_Click(object sender, EventArgs e)
{
ResultPanel.Visible = true;

// Note: This is just for development and testing.
// Don't show the actual result object to clients in production environment.
// Instead, show only the important information such as IsSucceed, Tracking Number and Transaction Code.
LblTrackingNumber.Text = result.TrackingNumber.ToString();
LblAmount.Text = result.Amount.ToString();
LblGateway.Text = result.GatewayName;
Expand Down
1 change: 1 addition & 0 deletions samples/Parbad.Sample.WebForm/Verify.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ protected async void Page_Load(object sender, EventArgs e)

var invoice = await StaticOnlinePayment.Instance.FetchAsync();

// This is an example of cancelling an invoice when you think that the payment process must be stopped.
if (Is_There_Still_Product_In_Shop(invoice.TrackingNumber))
{
var verifyResult = await StaticOnlinePayment.Instance.VerifyAsync(invoice);
Expand Down
19 changes: 13 additions & 6 deletions src/Parbad/Options/ParbadOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ public static IParbadBuilder ConfigureOptions(this IParbadBuilder builder, Actio

builder.Services.Configure(setupOptions);

builder.Services.AddTransient<IOptions<MessagesOptions>>(provider =>
{
var messages = provider.GetRequiredService<IOptions<ParbadOptions>>().Value.Messages;
return new OptionsWrapper<MessagesOptions>(messages);
});
RegisterMessagesOptions(builder);

return builder;
}
Expand All @@ -45,6 +40,8 @@ public static IParbadBuilder ConfigureOptions(this IParbadBuilder builder, IConf

builder.Services.Configure<ParbadOptions>(configuration);

RegisterMessagesOptions(builder);

return builder;
}

Expand All @@ -69,5 +66,15 @@ public static IParbadBuilder ConfigureMessages(this IParbadBuilder builder, ICon

return builder;
}

private static void RegisterMessagesOptions(IParbadBuilder builder)
{
builder.Services.AddTransient<IOptions<MessagesOptions>>(provider =>
{
var messages = provider.GetRequiredService<IOptions<ParbadOptions>>().Value.Messages;
return new OptionsWrapper<MessagesOptions>(messages);
});
}
}
}
2 changes: 1 addition & 1 deletion src/Parbad/Parbad.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<VersionPrefix>3.5.0</VersionPrefix>
<VersionPrefix>3.5.1</VersionPrefix>
<Authors>Parbad Sina Soltani</Authors>
<Description>Parbad is a free, open-source, integrated and extensible library which connects your web applications to online payment gateways. Gateways can be added or developed by you.
The Virtual Gateway also simulates the online payment process, which helps the application development.
Expand Down

0 comments on commit 253a32b

Please sign in to comment.