Skip to content

Commit

Permalink
Merge pull request #63 from Sina-Soltani/feature/62_ZarinPalBug
Browse files Browse the repository at this point in the history
Feature/62 zarin pal bug and Status for each request.
  • Loading branch information
Sina-Soltani authored Feb 5, 2020
2 parents 75daf41 + 46e2fd7 commit e91f6e4
Show file tree
Hide file tree
Showing 50 changed files with 578 additions and 358 deletions.
23 changes: 15 additions & 8 deletions samples/Parbad.Sample.AspNetCore/Controllers/PaymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,30 @@ public async Task<IActionResult> Pay(PayViewModel viewModel)
}

// It's better to set no HttpMethods(HttpGet, HttpPost, etc.) for the Verify action,
// because the banks send their information with different http methods
// درگاه‌های بانکی، اطلاعات خود را با متد‌های مختلفی ارسال میکنند
// بنابراین بهتر است هیچگونه خصوصیتی برای این اکشن متد در نظر گرفته نشود
// because the banks send their information with different HTTP methods
public async Task<IActionResult> Verify()
{
var invoice = await _onlinePayment.FetchAsync();

if (Is_There_Still_Product_In_Shop(invoice.TrackingNumber))
// Check if the invoice is new or it's already processed before.
if (invoice.Status == PaymentFetchResultStatus.AlreadyProcessed)
{
var verifyResult = await _onlinePayment.VerifyAsync(invoice);
// You can also see if the invoice is already verified before.
var isAlreadyVerified = invoice.IsAlreadyVerified;
return Content("The payment is already processed before.");
}

// An example of checking the invoice in your website.
if (!Is_There_Still_Product_In_Shop(invoice.TrackingNumber))
{
var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason: "Sorry, We have no more products to sell.");

return View(verifyResult);
return View("CancelResult", cancelResult);
}

var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason: "Sorry, We have no more products to sell.");
var verifyResult = await _onlinePayment.VerifyAsync(invoice);

return View("CancelResult", cancelResult);
return View(verifyResult);
}

[HttpGet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<td>Is succeed</td>
<td>@Model.IsSucceed</td>
</tr>
<tr>
<td>Status</td>
<td>@Model.Status</td>
</tr>
<tr>
<td>Message</td>
<td class="text-lg">@Model.Message</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<td>Is succeed</td>
<td>@Model.IsSucceed</td>
</tr>
<tr>
<td>Status</td>
<td>@Model.Status</td>
</tr>
<tr>
<td>Message</td>
<td class="text-lg">@Model.Message</td>
Expand Down
4 changes: 4 additions & 0 deletions samples/Parbad.Sample.AspNetCore/Views/Payment/Verify.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<td>Is succeed</td>
<td>@Model.IsSucceed</td>
</tr>
<tr>
<td>Status</td>
<td>@Model.Status</td>
</tr>
<tr>
<td>Message</td>
<td class="text-lg">@Model.Message</td>
Expand Down
23 changes: 15 additions & 8 deletions samples/Parbad.Sample.Mvc/Controllers/PaymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,30 @@ public async Task<ActionResult> Pay(RequestViewModel viewModel)
}

// It's better to set no HttpMethods(HttpGet, HttpPost, etc.) for the Verify action,
// because the banks send their information with different http methods
// درگاه‌های بانکی، اطلاعات خود را با متد‌های مختلفی ارسال میکنند
// بنابراین بهتر است هیچگونه خصوصیتی برای این اکشن متد در نظر گرفته نشود
// because the banks send their information with different HTTP methods
public async Task<ActionResult> Verify()
{
var invoice = await _onlinePayment.FetchAsync();

if (Is_There_Still_Product_In_Shop(invoice.TrackingNumber))
// Check if the invoice is new or it's already processed before.
if (invoice.Status == PaymentFetchResultStatus.AlreadyProcessed)
{
var verifyResult = await _onlinePayment.VerifyAsync(invoice);
// You can also see if the invoice is already verified before.
var isAlreadyVerified = invoice.IsAlreadyVerified;
return Content("The payment is already processed before.");
}

// An example of checking the invoice in your website.
if (!Is_There_Still_Product_In_Shop(invoice.TrackingNumber))
{
var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason: "Sorry, We have no more products to sell.");

return View(verifyResult);
return View("CancelResult", cancelResult);
}

var cancelResult = await _onlinePayment.CancelAsync(invoice, cancellationReason: "Sorry, We have no more products to sell.");
var verifyResult = await _onlinePayment.VerifyAsync(invoice);

return View("CancelResult", cancelResult);
return View(verifyResult);
}

[HttpGet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<td>Is succeed</td>
<td>@Model.IsSucceed</td>
</tr>
<tr>
<td>Status</td>
<td>@Model.Status</td>
</tr>
<tr>
<td>Message</td>
<td>@Model.Message</td>
Expand Down
4 changes: 4 additions & 0 deletions samples/Parbad.Sample.Mvc/Views/Payment/RefundResult.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<td>Is succeed</td>
<td>@Model.IsSucceed</td>
</tr>
<tr>
<td>Status</td>
<td>@Model.Status</td>
</tr>
<tr>
<td>Message</td>
<td>@Model.Message</td>
Expand Down
4 changes: 4 additions & 0 deletions samples/Parbad.Sample.Mvc/Views/Payment/Verify.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<td>Is succeed</td>
<td>@Model.IsSucceed</td>
</tr>
<tr>
<td>Status</td>
<td>@Model.Status</td>
</tr>
<tr>
<td>Message</td>
<td>@Model.Message</td>
Expand Down
4 changes: 4 additions & 0 deletions samples/Parbad.Sample.WebForm/PayRequest.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<td>Is succeed</td>
<td><asp:Label ID="LblIsSucceed" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>Status</td>
<td><asp:Label ID="LblStatus" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>Message</td>
<td class="text-lg"><asp:Label ID="LblMessage" runat="server" Text=""></asp:Label></td>
Expand Down
1 change: 1 addition & 0 deletions samples/Parbad.Sample.WebForm/PayRequest.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected void BtnPay_Click(object sender, EventArgs e)
LblGateway.Text = result.GatewayName;
LblGatewayAccountName.Text = result.GatewayAccountName;
LblIsSucceed.Text = result.IsSucceed.ToString();
LblStatus.Text = result.Status.ToString();
LblMessage.Text = result.Message;
}
}
Expand Down
9 changes: 9 additions & 0 deletions samples/Parbad.Sample.WebForm/PayRequest.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions samples/Parbad.Sample.WebForm/Refund.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<td>Is succeed</td>
<td><asp:Label ID="LblIsSucceed" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>Status</td>
<td><asp:Label ID="LblStatus" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>Message</td>
<td class="text-lg"><asp:Label ID="LblMessage" runat="server" Text=""></asp:Label></td>
Expand Down
1 change: 1 addition & 0 deletions samples/Parbad.Sample.WebForm/Refund.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ protected void BtnRefund_Click(object sender, EventArgs e)
LblAmount.Text = result.Amount.ToString();
LblGateway.Text = result.GatewayName;
LblIsSucceed.Text = result.IsSucceed.ToString();
LblStatus.Text = result.Status.ToString();
LblMessage.Text = result.Message;
}
}
Expand Down
35 changes: 23 additions & 12 deletions samples/Parbad.Sample.WebForm/Refund.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions samples/Parbad.Sample.WebForm/Verify.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<td>Is succeed</td>
<td><asp:Label ID="LblIsSucceed" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>Status</td>
<td><asp:Label ID="LblStatus" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td>Message</td>
<td class="text-lg"><asp:Label ID="LblMessage" runat="server" Text=""></asp:Label></td>
Expand Down
3 changes: 3 additions & 0 deletions samples/Parbad.Sample.WebForm/Verify.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ protected void Page_Load(object sender, EventArgs e)
{
IPaymentResult result;
var transactionCode = "";
var status = "";

var invoice = StaticOnlinePayment.Instance.Fetch();

Expand All @@ -16,6 +17,7 @@ protected void Page_Load(object sender, EventArgs e)
var verifyResult = StaticOnlinePayment.Instance.Verify(invoice);
result = verifyResult;
transactionCode = verifyResult.TransactionCode;
status = verifyResult.Status.ToString();
}
else
{
Expand All @@ -28,6 +30,7 @@ protected void Page_Load(object sender, EventArgs e)
LblGatewayAccountName.Text = result.GatewayAccountName;
LblTransactionCode.Text = transactionCode;
LblIsSucceed.Text = result.IsSucceed.ToString();
LblStatus.Text = status;
LblMessage.Text = result.Message;
}

Expand Down
Loading

0 comments on commit e91f6e4

Please sign in to comment.