コード例 #1
0
ファイル: GuardianApi.cs プロジェクト: tdonkor/SagePayPEDTest
        /// <summary>
        /// Payment
        /// </summary>
        public DiagnosticErrMsg Pay(int amount)
        {
            int intAmount;
            DiagnosticErrMsg isSuccessful = DiagnosticErrMsg.OK;

            //we only do sales
            transactiontype = TransactionHook.TRANSACTIONHOOK_TRANSACTIONTYPE.INT_TT_SALE;

            //check amount is valid
            intAmount = Utils.GetNumericAmountValue(amount);

            if (intAmount == 0)
            {
                throw new Exception("Error in Amount value");
            }

            Console.WriteLine($"Valid payment amount: {intAmount}");

            //add the address of the store for the reciept
            AddAddress();

            //Use a non GUI transaction - if transaction is true proceed to the CardEnquiry stage.
            if (nonGuiTransactionHook.StartTransaction(ref tillInformation) == true)
            {
                Console.WriteLine("Transaction Started....");

                //check the card enquiry returns: RETURNCODE_SUCCESS or RETURNCODE_CASHBACKALLOWED
                if (nonGuiTransactionHook.CardEnquiry(transactiontype,
                                                      intAmount,
                                                      NonGuiTransactionHook.NONGUITRANSACTION_DATAENTRY.DATAENTRY_CHIPORSWIPEORTAP) == NonGuiTransactionHook.NONGUITRANSACTION_RETURNCODE.RETURNCODE_SUCCESS)
                {
                    //authorise the transaction
                    Console.WriteLine("Transaction Authorisation Started....");

                    if (nonGuiTransactionHook.AuthoriseTransaction(TransactionHook.TRANSACTIONHOOK_TRANSACTIONTYPE.INT_TT_SALE, intAmount, 0, "SALE", ref transactionInfo) == NonGuiTransactionHook.NONGUITRANSACTION_RETURNCODE.RETURNCODE_SUCCESS)
                    {
                        if (transactionInfo.DataEntryMethod == TransactionInfo.TRANSINFO_DATAENTRYMETHOD.TRANSINFO_DE_SWIPED)
                        {
                            Console.WriteLine("Swipe transaction - CANCEL the transaction.");
                            confirmationType = NonGuiTransactionHook.NONGUITRANSACTION_CONFIRMTYPE.CONFIRMTYPE_CANCELLED;
                            isSuccessful     = DiagnosticErrMsg.NOTOK;
                        }


                        // confirm the transaction
                        if (nonGuiTransactionHook.ConfirmTransaction(confirmationType,
                                                                     nonGuiTransactionHook.TransactionReference,
                                                                     transactionInfo.AuthorisationCode,
                                                                     ref transactionInfo) == true)
                        {
                            //display transactionInfo
                            Console.WriteLine("\nTransaction Information");
                            Console.WriteLine("-----------------------\n");
                            Console.WriteLine($" AuthCode: {transactionInfo.AuthorisationCode}");
                            Console.WriteLine($" CardHolder Name: {transactionInfo.CardHolderName}");
                            Console.WriteLine($" Currency Code: {transactionInfo.CurrencyCode}");
                            Console.WriteLine($" Data Entry Method: {transactionInfo.DataEntryMethod}");
                            Console.WriteLine($" Merchant Number: {transactionInfo.MerchantNo}");
                            Console.WriteLine($" Response Code: {transactionInfo.ResponseCode}");
                            Console.WriteLine($" Scheme Number.: {transactionInfo.SchemeName}");
                            Console.WriteLine($" Transaction Amount: {transactionInfo.TransactionAmount}");
                            Console.WriteLine($" Transaction Ref Number: {transactionInfo.TransactionRefNo.ToString()}");
                            Console.WriteLine($" TerminalId: {transactionInfo.TerminalId}");


                            //customer receipt
                            Console.WriteLine("\n\nCustomer Receipt");
                            Console.WriteLine("===================\n");

                            Console.WriteLine($" Customer Reciept: {transactionInfo.CustomerReceipt}");
                        }
                    }
                }
            }

            //end the transaction
            nonGuiTransactionHook.EndTransaction();
            Console.WriteLine("SagePay Driver Transaction Finished.....");

            return(isSuccessful);
        }
コード例 #2
0
        /// <summary>
        /// Payment
        /// </summary>
        public DiagnosticErrMsg Pay(int amount, out TransactionInfo result)
        {
            int intAmount;
            DiagnosticErrMsg isSuccessful = DiagnosticErrMsg.OK;



            //initialise the result - fill this with the customer reciept to display
            result = null;

            //we only do sales
            transactiontype = TransactionHook.TRANSACTIONHOOK_TRANSACTIONTYPE.INT_TT_SALE;

            //check amount is valid
            intAmount = Utils.GetNumericAmountValue(amount);

            if (intAmount == 0)
            {
                throw new Exception("Error in Amount value...");
            }

            Log.Info($"Valid payment amount: {intAmount}");

            //add the address of the store for the reciept - address will be on the main reciept just populate this to stop it failing
            AddAddress();

            //Use a non GUI transaction - if transaction is true proceed to the CardEnquiry stage.
            if (nonGuiTransactionHook.StartTransaction(ref tillInformation) == true)
            {
                Log.Info("Transaction Started....");


                //check the card enquiry returns: RETURNCODE_SUCCESS or RETURNCODE_CASHBACKALLOWED
                if (nonGuiTransactionHook.CardEnquiry(transactiontype,
                                                      intAmount,
                                                      NonGuiTransactionHook.NONGUITRANSACTION_DATAENTRY.DATAENTRY_CHIPORSWIPEORTAP) != NonGuiTransactionHook.NONGUITRANSACTION_RETURNCODE.RETURNCODE_FAILED)
                {
                    //authorise the transaction
                    Log.Info("Transaction Authorisation Started....");

                    if (nonGuiTransactionHook.AuthoriseTransaction(transactiontype, intAmount, 0, "SALE", ref transactionInfo) != NonGuiTransactionHook.NONGUITRANSACTION_RETURNCODE.RETURNCODE_FAILED)
                    {
                        if (transactionInfo.DataEntryMethod == TransactionInfo.TRANSINFO_DATAENTRYMETHOD.TRANSINFO_DE_SWIPED)
                        {
                            Log.Info("Swipe transaction - Cancel the transaction....");
                            confirmationType = NonGuiTransactionHook.NONGUITRANSACTION_CONFIRMTYPE.CONFIRMTYPE_CANCELLED;
                            isSuccessful     = DiagnosticErrMsg.SwipeCardUsedError;
                        }


                        // confirm the transaction
                        if (nonGuiTransactionHook.ConfirmTransaction(confirmationType,
                                                                     nonGuiTransactionHook.TransactionReference,
                                                                     transactionInfo.AuthorisationCode,
                                                                     ref transactionInfo) == true)
                        {
                            result = transactionInfo;
                        }
                        else
                        {
                            //transaction not Confirmed
                            Log.Error("Transaction not Confirmed...");
                            isSuccessful = DiagnosticErrMsg.TransactionNotConfirmedError;
                        }
                    }
                    else
                    {
                        //transaction not Authorised
                        Log.Error("Authorisation Error...Ending Transaction.");
                        isSuccessful = DiagnosticErrMsg.NotAuthorisedError;
                    }
                }
                else
                {
                    //Card Enquiry Error - result will be null
                    Log.Error("CardEnquiry Error...Ending Transaction.");
                    isSuccessful = DiagnosticErrMsg.CardEnquiryError;
                }
            }
            else
            {
                //Start Transaction Failure
                Log.Error("Start Transaction Failure...");
                isSuccessful = DiagnosticErrMsg.StartTransactionError;
            }

            Log.Info("SagePay Driver Transaction Finished...");
            nonGuiTransactionHook.EndTransaction();
            return(isSuccessful);
        }