Partilhar via


Exemplo do PinPad (documentação do SDK do PDV para .NET v1.14)

Este exemplo demonstra quais métodos devem ser implementados em um objeto de serviço PinPad .

Para implementar uma estrutura de objeto de serviço PinPad

  1. Adicione usando diretivas para Microsoft.PointofService, Microsoft.PointOfService.BaseServiceObjects.

  2. Adicione o atributo global PosAssembly.

  3. Escolha um nome de namespace apropriado para seu projeto.

  4. Crie uma classe Service Object derivada de PinPadBase.

  5. Adicione o atributo ServiceObject à sua classe Service Object, usando o valor DeviceType.PinPad como seu tipo de dispositivo.

Exemplo

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

using Microsoft.PointOfService.BaseServiceObjects;
using Microsoft.PointOfService;

[assembly: PosAssembly("Service Object Contractors, Inc")]

namespace SOSamples.PinPad
{
    [ServiceObject(
                DeviceType.PinPad,
                "SamplePinPad",
                "Sample PinPad Service Object",
                1,
                9)]
    public class SamplePinPad : PinPadBase
    {
        PinPadSystem pinPadSystemSupported = PinPadSystem.Dukpt;

        public SamplePinPad()
        {
        }

        #region Implement Abstract PinPadBase Members

        // These abstract protected methods are called from their
        // public, counterpart methods after error and state
        // validation checks are performed.

        protected override void BeginEftTransactionImpl(
                        PinPadSystem pinpadSystem,
                        int transactionHost)
        {
            // If pinpadSystem is not supported by this device,
            // throw a PosControlException.
            if (pinpadSystem != pinPadSystemSupported)
            {
                throw new PosControlException(
                            "PinPadSystem not supported",
                            ErrorCode.Illegal);
            }

            // Your code here. Perform any device-specific
            // initialization, such as computing session keys.
        }

        protected override string ComputeMacImpl(
                        string inMsg)
        {
            // Your code here. Depending on the selected PIN Pad
            // Management system, the PinPad Service Object may
            // insert additional fields into the message (inMsg).
            return inMsg;
        }

        protected override void EnablePinEntryImpl()
        {
            // PinPadBase sets PINEntryEnabled if this method
            // succeeds. After that, the Service Object may
            // send a DataEvent to the application.
        }

        protected override void EndEftTransactionImpl(
                        EftTransactionCompletion completionCode)
        {
            // Your code here. Perform any device or Service
            // Object cleanup such as computing the next
            // transaction keys.
        }

        protected override void UpdateKeyImpl(
                        int keyNumber,
                        string key)
        {
            // Your code here. Update the specified key
            // on your device.
        }

        protected override void VerifyMacImpl(
                        string message)
        {
            // Your code here. Verify the MAC value in a message
            // received from the EFT Transaction host.
        }
        #endregion Implement Abstract PinPadBase Members

        #region Implement Abstract PosCommon Members
        private string MyHealthText = "";

        // PosCommon.CheckHealthText.
        public override string CheckHealthText
        {
            get
            {
                // VerifyState(mustBeClaimed,
                // mustBeEnabled).
                VerifyState(false, false);
                return MyHealthText;
            }
        }

        //  PosCommon.CheckHealth.
        public override string CheckHealth(
                        HealthCheckLevel level)
        {
            // Verify that the device is open, claimed, and enabled.
            VerifyState(true, true);

            // Your code here:
            // check the health of the device and return a
            // descriptive string.

            // Cache result in the CheckHealthText property.
            MyHealthText = "Ok";
            return MyHealthText;
        }

        // PosCommon.DirectIOData.
        public override DirectIOData DirectIO(
                                int command,
                                int data,
                                object obj)
        {
            // Verify that the device is open.
            VerifyState(false, false);

            return new DirectIOData(data, obj);
        }
        #endregion  Implement Abstract PosCommon Members
    }
}

Consulte Também

Outros Recursos