Udostępnij przez


Przykład kodu PinPad (poS dla zestawu SDK platformy .NET w wersji 1.14)

W tym przykładzie pokazano, które metody należy zaimplementować w obiekcie usługi PinPad .

Aby zaimplementować strukturę obiektów usługi PinPad

  1. Dodaj dyrektywy using dla microsoft.PointofService, Microsoft.PointOfService.BaseServiceObjects.

  2. Dodaj atrybut globalny PosAssembly.

  3. Wybierz odpowiednią nazwę przestrzeni nazw dla projektu.

  4. Utwórz klasę obiektu usługi pochodzącą z klasy PinPadBase.

  5. ServiceObject Dodaj atrybut do klasy Obiekt usługi przy użyciu wartości DeviceType.PinPad jako typu urządzenia.

Example

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
    }
}

Zobacz też

Inne zasoby