Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust support as well as Batch Clear Support #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SecureSubmit/SecureSubmit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
<Compile Include="Terminals\Extensions\BinaryReaderExtensions.cs" />
<Compile Include="Terminals\Extensions\StringExtensions.cs" />
<Compile Include="Terminals\PAX\Fluent\CreditAuthBuilder.cs" />
<Compile Include="Terminals\PAX\Fluent\CreditAdjustBuilder.cs" />
<Compile Include="Terminals\PAX\Fluent\CreditCaptureBuilder.cs" />
<Compile Include="Terminals\PAX\Fluent\CreditReturnBuilder.cs" />
<Compile Include="Terminals\PAX\Fluent\CreditSaleBuilder.cs" />
Expand Down Expand Up @@ -240,6 +241,7 @@
<Compile Include="Terminals\PAX\Responses\InitializeResponse.cs" />
<Compile Include="Terminals\PAX\Responses\InputAccountResponse.cs" />
<Compile Include="Terminals\PAX\Responses\LoyaltyResponse.cs" />
<Compile Include="Terminals\PAX\Responses\BatchClearResponse.cs" />
<Compile Include="Terminals\PAX\Responses\ResetResponse.cs" />
<Compile Include="Terminals\PAX\SubGroups\AccountSubGroups.cs" />
<Compile Include="Terminals\PAX\SubGroups\AmountSubGroups.cs" />
Expand Down
64 changes: 64 additions & 0 deletions SecureSubmit/Terminals/PAX/Fluent/CreditAdjustBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using SecureSubmit.Entities;
using SecureSubmit.Fluent;
using SecureSubmit.Infrastructure;
using SecureSubmit.Terminals.Extensions;

namespace SecureSubmit.Terminals.PAX {
public class CreditAdjustBuilder : HpsBuilderAbstract<PaxDevice, CreditResponse> {
private int referenceNumber;
decimal? gratuity;
int? transactionId;

public CreditAdjustBuilder WithTransactionId(int? value) {
this.transactionId = value;
return this;
}

public CreditAdjustBuilder WithGratuity(decimal? value)
{
this.gratuity = value;
return this;
}

public CreditAdjustBuilder WithReferenceNumber(int referenceNumber) {
this.referenceNumber = referenceNumber;
return this;
}

public CreditAdjustBuilder(PaxDevice device)
: base(device) {
}

public override CreditResponse Execute() {
base.Execute();

var amounts = new AmountRequest();
if (gratuity.HasValue)
amounts.TransactionAmount = "{0:c}".FormatWith(gratuity).ToNumeric();

var trace = new TraceRequest {
ReferenceNumber = referenceNumber.ToString(),
TransactionNumber = referenceNumber.ToString()
};

var extData = new ExtDataSubGroup();
if (transactionId.HasValue)
extData[EXT_DATA.HOST_REFERENCE_NUMBER] = transactionId.Value.ToString();

var response = service.DoCredit(
PAX_TXN_TYPE.ADJUST,
amounts,
new AccountRequest(),
trace,
new AvsRequest(),
new CashierSubGroup(),
new CommercialRequest(),
new EcomSubGroup(),
extData
);

return response;
}
}
}
9 changes: 4 additions & 5 deletions SecureSubmit/Terminals/PAX/Fluent/CreditVoidBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public override CreditResponse Execute() {
base.Execute();

var extData = new ExtDataSubGroup();
extData[EXT_DATA.HOST_REFERENCE_NUMBER] = transactionId.Value.ToString();
if (transactionId.HasValue)
{
extData[EXT_DATA.HOST_REFERENCE_NUMBER] = transactionId.Value.ToString();
}

return service.DoCredit(PAX_TXN_TYPE.VOID,
new AmountRequest(),
Expand All @@ -38,9 +41,5 @@ public override CreditResponse Execute() {
extData
);
}

protected override void SetupValidations() {
AddValidation(() => { return transactionId.HasValue; }, "TransactionId is required.");
}
}
}
10 changes: 10 additions & 0 deletions SecureSubmit/Terminals/PAX/PaxDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public CreditCaptureBuilder CreditCapture(int referenceNumber, decimal? amount =
return new CreditCaptureBuilder(this).WithReferenceNumber(referenceNumber).WithAmount(amount);
}

public CreditAdjustBuilder CreditAdjust(int referenceNumber, decimal? gratuity = null)
{
return new CreditAdjustBuilder(this).WithReferenceNumber(referenceNumber).WithGratuity(gratuity);
}

public CreditEditBuilder CreditEdit(decimal? amount = null) {
if (!_settings.DeviceId.HasValue || !_settings.SiteId.HasValue || !_settings.LicenseId.HasValue || string.IsNullOrEmpty(_settings.UserName) || string.IsNullOrEmpty(_settings.Password))
throw new HpsConfigurationException("Device is not configured properly for Credit Edit. Please provide the device credentials in the ConnectionConfig.");
Expand Down Expand Up @@ -208,6 +213,11 @@ public BatchCloseResponse BatchClose() {
var response = _interface.Send(TerminalUtilities.BuildRequest(PAX_MSG_ID.B00_BATCH_CLOSE, DateTime.Now.ToString("YYYYMMDDhhmmss")));
return new BatchCloseResponse(response);
}
public BatchClearResponse BatchClear()
{
var response = _interface.Send(TerminalUtilities.BuildRequest(PAX_MSG_ID.B04_BATCH_CLEAR));
return new BatchClearResponse(response);
}
#endregion

#region Reporting Commands
Expand Down
7 changes: 7 additions & 0 deletions SecureSubmit/Terminals/PAX/Responses/BatchClearResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;

namespace SecureSubmit.Terminals.PAX {
public class BatchClearResponse : PaxDeviceResponse {
public BatchClearResponse(byte[] buffer) : base(buffer, PAX_MSG_ID.B05_RSP_BATCH_CLEAR) { }
}
}
11 changes: 7 additions & 4 deletions SecureSubmit/Terminals/PAX/Responses/BatchCloseResponse.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.IO;
using System.Linq;
using SecureSubmit.Terminals.Extensions;

namespace SecureSubmit.Terminals.PAX {
public class BatchCloseResponse : PaxDeviceResponse {
private HostResponse hostResponse;

public string TotalCount { get; set; }
public string TotalAmount { get; set; }
public int TotalCount { get; set; }
public decimal TotalAmount { get; set; }
public string TimeStamp { get; set; }
public string TID { get; set; }
public string MID { get; set; }
Expand All @@ -20,11 +21,13 @@ protected override void ParseResponse(BinaryReader br) {
base.ParseResponse(br);

this.hostResponse = new HostResponse(br);
this.TotalCount = br.ReadToCode(ControlCodes.FS);
this.TotalAmount = br.ReadToCode(ControlCodes.FS);
this.TotalCount = br.ReadToCode(ControlCodes.FS).Split('=').Sum(o => Convert.ToInt32(o));
this.TotalAmount = br.ReadToCode(ControlCodes.FS).Split('=').Sum(o => Convert.ToDecimal(o) / 100);
this.TimeStamp = br.ReadToCode(ControlCodes.FS);
this.TID = br.ReadToCode(ControlCodes.FS);
this.MID = br.ReadToCode(ControlCodes.ETX);

this.HostResponse = hostResponse;
}
}
}