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

Fix signature image width #51

Open
wants to merge 2 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: 1 addition & 1 deletion src/GlobalPayments.Api/Terminals/PAX/PaxInterface.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override ISignatureResponse PromptForSignature(string transactionId = nul
ControlCodes.FS,
300
));
var signatureResponse = new SignatureResponse(response);
var signatureResponse = new SignatureResponse(response, _controller.DeviceType.Value);
if (signatureResponse.DeviceResponseCode == "000000")
return GetSignatureFile();
return signatureResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,46 @@ public class SignatureResponse : PaxTerminalResponse, ISignatureResponse {
private DeviceType _deviceType;

public int TotalLength { get; set; }
public int ResponseLegth { get; set; }
public int ResponseLength { get; set; }
public string UnparsedSignature { get; set; }



public SignatureResponse(byte[] response, DeviceType deviceType = DeviceType.PAX_S300) : base(response, PAX_MSG_ID.A09_RSP_GET_SIGNATURE, PAX_MSG_ID.A21_RSP_DO_SIGNATURE) {
_deviceType = deviceType;
ProcessImage(); // must be called AFTER setting device type
}

protected override void ParseResponse(BinaryReader br) {
base.ParseResponse(br);

if (DeviceResponseCode == "000000" && Command == PAX_MSG_ID.A09_RSP_GET_SIGNATURE) {
if (DeviceResponseCode == "000000" && Command == PAX_MSG_ID.A09_RSP_GET_SIGNATURE)
{
TotalLength = int.Parse(br.ReadToCode(ControlCodes.FS));
ResponseLegth = int.Parse(br.ReadToCode(ControlCodes.FS));
ResponseLength = int.Parse(br.ReadToCode(ControlCodes.FS));

var signatureData = br.ReadToCode(ControlCodes.ETX);
UnparsedSignature = br.ReadToCode(ControlCodes.ETX);
}

}

/// <summary>
/// call this to convert string data to a BMP image and store it
/// </summary>
private void ProcessImage()
{
if (UnparsedSignature != null)
{
int imageWidth = 150;
switch (_deviceType) {
switch (_deviceType)
{
case DeviceType.PAX_PX5:
case DeviceType.PAX_PX7: {
case DeviceType.PAX_PX7:
{
imageWidth = 350;
} break;
}
break;
}
SignatureData = TerminalUtilities.BuildSignatureImage(signatureData, imageWidth);
SignatureData = TerminalUtilities.BuildSignatureImage(UnparsedSignature, imageWidth);
}
}
}
Expand Down