Example #1
0
        public async Task<ITransactionResponse> AuthorizeAsync(AuthorizeRequest authorizeRequest)
        {
            #region Validate request

            if (string.IsNullOrEmpty(authorizeRequest.Language)) throw new AsyncPosException(Language.Get("language_error", _languageCode));
            _languageCode = authorizeRequest.Language;

            if (authorizeRequest.Amount == 0) throw new AsyncPosException(Language.Get("amount_error", _languageCode));
            if (authorizeRequest.Cash < 0) throw new AsyncPosException(Language.Get("cash_error", _languageCode));
            if (authorizeRequest.Currency == 0) throw new AsyncPosException(Language.Get("currency_error", _languageCode));

            #endregion

            TransactionState transactionState = GetTransactionState(authorizeRequest.TransactionId, true);
            transactionState.Language = _languageCode;

            if (transactionState.State != TransactionStates.NotStarted)
                throw new AsyncPosException(Language.Get("docnum_error", transactionState.Language));

            using (transactionState.CreateAutoSaveContext())
            {
                try
                {
                    transactionState.Amount = authorizeRequest.Amount;
                    transactionState.Cash = authorizeRequest.Cash;
                    transactionState.Currency = authorizeRequest.Currency;
                    transactionState.Last4CardNumberDigits = authorizeRequest.Last4CardNumberDigits;
                    transactionState.PreAuthorize = authorizeRequest.PreAuthorize;

                    await SendLoginRequest(transactionState.Language, Language.Get("pinpad_welcome", transactionState.Language));
                    await GetCardToken(transactionState);
                    await ProcessAuthorization(transactionState);
                }
                catch (AsyncPosException ex)
                {
                    transactionState.InformationText = ex.Message;
                }
            }

            AuthorizeResponse response = new AuthorizeResponse
            {
                TransactionId = authorizeRequest.TransactionId,
                Result = transactionState.State == TransactionStates.Approved ? ResponseResults.Ok : ResponseResults.Error,
                Amount = transactionState.Amount,
                Text = (transactionState.State == TransactionStates.Approved) ? transactionState.InformationText : (transactionState.InformationText ?? "System error"),
                AuthorizationCode = transactionState.AuthorizationCode,
                Rrn = transactionState.Rrn,
                Stan = transactionState.Stan,
                CardType = transactionState.CardType
            };

            FillReceipts(transactionState, response, false);

            return response;
        }
Example #2
0
        public async Task<IResponse> AuthorizeAsync(AuthorizeRequest authorizeRequest)
        {
            Ensure.NotNull(authorizeRequest, nameof(authorizeRequest));

            AuthorizeResponse result = await _ped.AuthorizeAsync(authorizeRequest) as AuthorizeResponse;
            if (result == null)
                throw new Exception("Cannot authorize payment");

            try
            {
                if (!string.IsNullOrEmpty(result.MerchantReceipt))
                    await _printer.PrintMerchantReceipt(result.MerchantReceipt);

                if (!string.IsNullOrEmpty(result.ClientReceipt))
                    await _printer.PrintMerchantReceipt(result.ClientReceipt);
            }
            catch
            {
                await _ped.ReversalAsync(new ReversalRequest { TransactionId = authorizeRequest.TransactionId });
                throw;
            }

            return result;
        }