示例#1
0
        //-----------------------------------------------------------------------------------------
        // CardCredit - Credits a card with an amount.  This is used to to activate or add to a card.
        //  Returns the tranactionCode for the request.
        //-----------------------------------------------------------------------------------------
        public string CardCredit(string cardNumber, string tenderCode, string transExternalId, decimal amount, System.Windows.Forms.TextBox tbResults, Guid?customerUid = null)
        {
            var transCode = "";
            var svc       = GetPaymentEngineService();

            try
            {
                CardCreditRequest request = new CardCreditRequest();

                // Build up the card credit request based on what the user/cashier entered.
                request.CardNumber  = cardNumber;
                request.CustomerUid = customerUid ?? Guid.Empty;                                       // Optionally provide the bLoyal customer uid if you have it.
                //                request.CardPin = "";   // Some clients require a PIN.
                request.Swiped                = false;                                                 // Set to true when a card is swiped and false if manually keyed.
                request.Amount                = amount;
                request.TenderCode            = tenderCode;                                            // This is optional.  Fill in if you have it to validate the card type with the tender.
                request.TransactionExternalId = transExternalId;                                       // Provide either your transaction number or the bLoyal TransactionToken.

                CardResponse  response = svc.CardCredit(_accessKey, _storeCode, _deviceCode, request); // StoreCode and DeviceCode are not required if you are using a device AccessKey.
                List <string> msg      = new List <string>();
                if (response.Status == CardRequestStatus.Approved)
                {
                    transCode = response.TransactionCode;

                    msg.Add(string.Format("CardCredit() succeeded.  Transaction Code:{0}", response.TransactionCode));
                    msg.Add(string.Format("    Current Balance={0}, Available Balance={1} ", response.CurrentBalance, response.AvailableBalance));
                }
                else
                {
                    msg.Add(string.Format("CardCredit() FAILED.  Status={0} ", response.Status));
                    msg.Add(string.Format("    Message:{0} ", response.Message));
                }
                tbResults.Lines = msg.ToArray();

                svc.Close(); // Closes the transport channel.
                svc = null;
            }
            catch (System.Exception ex)
            {
                tbResults.Text = string.Format("CardCredit() failed.  Exception: {0}", ex.ToString());
            }
            finally
            {
                if (svc != null)
                {
                    svc.Abort();
                }
            }
            return(transCode);
        }
        //-----------------------------------------------------------------------------------------
        // CardCredit - Credits a card with an amount.  This is used to to activate or add to a card.
        //  Returns the tranactionCode for the request.
        //-----------------------------------------------------------------------------------------
        public string CardCredit(string cardNumber, string tenderCode, string transExternalId, decimal amount, Guid?customerUid = null)
        {
            var transCode = "";
            var svc       = GetPaymentEngineService();

            try
            {
                CardCreditRequest request = new CardCreditRequest
                {
                    // Build up the card credit request based on what the user/cashier entered.
                    CardNumber  = cardNumber,
                    CustomerUid = customerUid ?? Guid.Empty, // Optionally provide the bLoyal customer uid if you have it.
                    //request.CardPin = "";   // Some clients require a PIN.
                    Swiped                = false,           // Set to true when a card is swiped and false if manually keyed.
                    Amount                = amount,
                    TenderCode            = tenderCode,      // This is optional.  Fill in if you have it to validate the card type with the tender.
                    TransactionExternalId = transExternalId, // Provide either your transaction number or the bLoyal TransactionToken.
                    ReferenceNumber       = transExternalId
                                                             //request.CartSourceExternalId = transExternalId;
                };

                CardResponse response = svc.CardCredit(_accessKey, _storeCode, _deviceCode, request);   // StoreCode and DeviceCode are not required if you are using a device AccessKey.

                List <string> msg = new List <string>();
                if (response.Status == CardRequestStatus.Approved)
                {
                    transCode = response.TransactionCode;

                    msg.Add(string.Format("CardCredit() succeeded.  Transaction Code:{0}", response.TransactionCode));
                    msg.Add(string.Format("    Current Balance={0}, Available Balance={1} ", response.CurrentBalance, response.AvailableBalance));
                }
                else
                {
                    msg.Add(string.Format("CardCredit() FAILED.  Status={0} ", response.Status));
                    msg.Add(string.Format("    Message:{0} ", response.Message));
                }
                //tbResults.Lines = msg.ToArray();

                svc.Close(); // Closes the transport channel.
                svc = null;
            }
            catch (bLoyal.Connectors.ApiException ex)
            {
                if (ex != null && !string.IsNullOrWhiteSpace(ex.Code) && ex.Code == "ServiceRedirect")
                {
                    ServiceURLHelper.IsbLoyalServiceUrlDown = true;
                }
                _logger.WriteLogError(ex, "CardCredit in PaymentEngineConnector");
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "CardCredit in PaymentEngineConnector");
            }
            finally
            {
                if (svc != null)
                {
                    svc.Abort();
                }
            }
            return(transCode);
        }