Пример #1
0
        public ResponseModel RetrieveTransaction(TransactionModel model)
        {
            ArgumentValidator.ThrowOnNull("model", model);
            TransactionCommand command;
            bool success       = false;
            var  responseValue = new PayFabricResponseModel();

            _payFabricCommands.TryGetValue(Command.RetrieveTrans, out command);

            //Replace with actual key for the transaction
            var url     = string.Format(command.Url, model.Key);
            var client  = new RestClient(url);
            var request = new RestRequest(command.HttpVerb);

            request.AddHeader("authorization", _auth);
            IRestResponse response    = client.Execute(request);
            var           keyResponse = response.Content;

            if (Helpers.ResponseStatus(response.StatusCode))
            {
                success       = true;
                responseValue = GetResult(keyResponse);
            }
            else
            {
                success = false;
            }
            return(ConvertToResponseModel(response, success, responseValue, new List <PayfabricCustomerResponseModel>(),
                                          new PayfabricTransactionResponse()));
        }
Пример #2
0
 public ResponseModel CreateSecurityToken(string deviceId, string payfabricGatewayAccountProfile,
                                          string payfabricUrl)
 {
     //
     var responseValue = new PayFabricResponseModel();
     {
         var success = false;
         TransactionCommand command;
         _payFabricCommands.TryGetValue(Command.CreateToken, out command);
         var client  = new RestClient(command.Url);
         var request = new RestRequest(command.HttpVerb);
         request.AddHeader("authorization", _auth);
         var response    = client.Execute(request);
         var keyResponse = response.Content;
         if (Helpers.ResponseStatus(response.StatusCode))
         {
             success       = true;
             responseValue = GetResult(keyResponse);
         }
         else
         {
             success = false;
         }
         return(ConvertToResponseModel(response, success, responseValue, new List <PayfabricCustomerResponseModel>(),
                                       new PayfabricTransactionResponse()));
     }
 }
Пример #3
0
        public PayFabricResponseModel CreateSecurityToken()
        {
            var responseValue = new PayFabricResponseModel();
            {
                var success = false;
                TransactionCommand command;
                _payFabricCommands.TryGetValue(Command.CreateToken, out command);
                var url = "https://sandbox.payfabric.com/Payment/Web";

                var client  = new RestClient(command.Url);
                var request = new RestRequest(command.HttpVerb);
                request.AddHeader("authorization", _auth);
                var response    = client.Execute(request);
                var keyResponse = response.Content;
                if (Helpers.ResponseStatus(response.StatusCode))
                {
                    success = true;
                    responseValue.StatusCode = response.StatusCode.ToString();
                    //responseValue = GetResult(keyResponse);
                }
                else
                {
                    success = false;
                }
                return(responseValue);
            }
        }
Пример #4
0
        public ResponseModel CreatePreAuthTrans(TransactionModel model)
        {
            ArgumentValidator.ThrowOnNull("model", model);
            TransactionCommand command;
            bool success       = false;
            var  responseValue = new PayFabricResponseModel();

            _payFabricCommands.TryGetValue(Command.PreAuthTrans, out command);
            var url     = command.Url.Replace("{key}", model.Key);
            var client  = new RestClient(url);
            var request = new RestRequest(command.HttpVerb);

            request.AddHeader("authorization", _auth);

            request.AddHeader("content-type", "application/json");
            var encodedTrans = Json.Encode(model);

            request.AddParameter("application/json", encodedTrans, ParameterType.RequestBody);
            var response    = client.Execute(request);
            var keyResponse = response.Content;

            if (Helpers.ResponseStatus(response.StatusCode))
            {
                success       = true;
                responseValue = GetResult(keyResponse);
            }
            else
            {
                success = false;
            }
            return(ConvertToResponseModel(response, success, responseValue, new List <PayfabricCustomerResponseModel>(),
                                          new PayfabricTransactionResponse()));
        }
Пример #5
0
        public ResponseModel UpdateWallet(PayfabricWalletRequestModel model)
        {
            //PayFabric cannot update the card number of an existing card. To update a card number,
            //delete the old card record and create a new one.
            ArgumentValidator.ThrowOnNull("model", model);
            var success       = false;
            var responseValue = new PayFabricResponseModel();
            List <PayfabricCustomerResponseModel> customerPaymentDetails = new List <PayfabricCustomerResponseModel>();
            IRestResponse      response = new RestResponse();
            TransactionCommand command;
            var message = string.Empty;

            try
            {
                _payFabricCommands.TryGetValue(Command.UpdateWallet, out command);
                var client  = new RestClient(command.Url);
                var request = new RestRequest(command.HttpVerb);
                request.AddHeader("authorization", _auth);
                request.AddHeader("content-type", "application/json");
                var encodedTrans = Json.Encode(model);
                request.AddParameter("application/json", encodedTrans, ParameterType.RequestBody);
                //https://www.payfabric.com/Payment/Web//profile/WalletDetails?id=d46a5b27-06a9-480b-b79b-ff126c575520&ServiceInstanceId=1f2ccbe2-dc9e-497b-81d0-f11efbf79bc5&InstFlag=1&NavFlag=0&DCN=1
                response = client.Execute(request);
                var keyResponse = response.Content;
                if (Helpers.ResponseStatus(response.StatusCode) && !string.IsNullOrEmpty(response.Content))
                {
                    customerPaymentDetails = _serializer.Deserialize <List <PayfabricCustomerResponseModel> >(response.Content);
                    success = true;
                    responseValue.Message = "Wallet was saved with the updated billing information";
                }
                else
                {
                    success = false;
                    responseValue.Message = "Wallet was not saved with the updated billing information";
                }
                //_logger.Log(LogLevel.Info, response.Content);
                return(ConvertToResponseModel(response, success, responseValue, new List <PayfabricCustomerResponseModel>(), new PayfabricTransactionResponse()));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //_logger.Log(LogLevel.Error, ex, ex.StackTrace);
                throw (ex);
            }
        }
Пример #6
0
        public ResponseModel ProcessTransaction(TransactionModel model)
        {
            ArgumentValidator.ThrowOnNull("model", model);
            TransactionCommand command;
            bool          success       = false;
            var           responseValue = new PayFabricResponseModel();
            var           payfabricTransactionResponse = new PayfabricTransactionResponse();
            IRestResponse response    = new RestResponse();
            var           keyResponse = string.Empty;

            try
            {
                _payFabricCommands.TryGetValue(Command.ProcessTrans, out command);
                var url     = command.Url.Replace("{key}", model.Key);
                var client  = new RestClient(url);
                var request = new RestRequest(command.HttpVerb);
                //request.AddHeader("authorization", _auth);
                var token = CreateSecurityToken();
                request.AddHeader("authorization", token.Token);
                request.AddHeader("content-type", "application/json");
                response    = client.Execute(request);
                keyResponse = response.Content;
                if (Helpers.ResponseStatus(response.StatusCode))
                {
                    success       = true;
                    responseValue = GetResult(keyResponse);
                    payfabricTransactionResponse = _serializer.Deserialize <PayfabricTransactionResponse>(response.Content);
                    //write the response to the logs, for debugging
                    //_logger.Log(LogLevel.Info, response.Content);
                }
                else
                {
                    success = false;
                }
                return(ConvertToResponseModel(response, success, responseValue, new List <PayfabricCustomerResponseModel>(), payfabricTransactionResponse));
            }
            catch (Exception ex)
            {
                //_logger.Log(LogLevel.Error, ex, response.Content);
                //_logger.Log(LogLevel.Error, ex, ex.StackTrace);
                throw new Exception(response.Content, ex);
            }
        }
Пример #7
0
        public ResponseModel CreateTrans(TransactionModel model)
        {
            ArgumentValidator.ThrowOnNull("model", model);
            bool success = false;
            TransactionCommand command;
            var           responseValue = new PayFabricResponseModel();
            IRestResponse response      = new RestResponse();
            var           keyResponse   = string.Empty;

            try
            {
                _payFabricCommands.TryGetValue(Command.CreateTrans, out command);
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var client  = new RestClient(command.Url);
                var request = new RestRequest(command.HttpVerb);
                request.AddHeader("authorization", _auth);
                request.AddHeader("content-type", "application/json");
                var encodedTrans = Json.Encode(model);
                request.AddParameter("application/json", encodedTrans, ParameterType.RequestBody);
                response    = client.Execute(request);
                keyResponse = response.Content;
                dynamic decodedResult = Json.Decode(keyResponse);
                var     authKey       = decodedResult.Key;
                //_logger.Log(LogLevel.Info, response.Content);
            }
            catch (Exception ex)
            {
                throw new Exception(response.Content, ex);
            }
            if (Helpers.ResponseStatus(response.StatusCode))
            {
                success       = true;
                responseValue = GetResult(keyResponse);
            }
            else
            {
                success = false;
            }
            return(ConvertToResponseModel(response, success, responseValue, new List <PayfabricCustomerResponseModel>(),
                                          new PayfabricTransactionResponse()));
        }
Пример #8
0
        public ResponseModel CreateWallet(PayfabricWalletCreateModel model)
        {
            ArgumentValidator.ThrowOnNull("model", model);
            var                success       = false;
            var                responseValue = new PayFabricResponseModel();
            IRestResponse      response      = new RestResponse();
            TransactionCommand command;

            try
            {
                _payFabricCommands.TryGetValue(Command.CreateWallet, out command);
                var client  = new RestClient(command.Url);
                var request = new RestRequest(command.HttpVerb);
                request.AddHeader("authorization", _auth);
                request.AddHeader("content-type", "application/json");
                var json = _serializer.Serialize(model);
                //var json = ConvertToTransactionalModelAsString();
                request.AddParameter("application/json", json, ParameterType.RequestBody);
                response = client.Execute(request);
                var keyResponse = response.Content;

                if (Helpers.ResponseStatus(response.StatusCode))
                {
                    success       = true;
                    responseValue = GetResult(keyResponse);
                }
                else
                {
                    success = false;
                }
                //_logger.Log(LogLevel.Info, keyResponse);

                return(ConvertToResponseModel(response, success, responseValue, new List <PayfabricCustomerResponseModel>(), new PayfabricTransactionResponse()));
            }
            catch (Exception ex)
            {
                //_logger.Log(LogLevel.Error, ex, ex.StackTrace);
                throw (ex);
            }
        }
Пример #9
0
        public ResponseModel DeleteWallet(TransactionModel model)
        {
            ArgumentValidator.ThrowOnNull("model", model);
            TransactionCommand command;
            var responseValue = new PayFabricResponseModel();
            var success       = false;
            var walletId      = Guid.Empty;

            _payFabricCommands.TryGetValue(Command.DeleteWallet, out command);
            var client  = new RestClient(command.Url + model.Value);
            var request = new RestRequest(command.HttpVerb);

            request.AddHeader("authorization", _auth);
            request.AddHeader("content-type", "application/json");
            var json        = _serializer.Serialize(model);
            var response    = client.Execute(request);
            var keyResponse = response.Content;

            if (Helpers.ResponseStatus(response.StatusCode))
            {
                success = true;
                if (keyResponse != null)
                {
                    responseValue = GetResult(keyResponse);
                }
            }
            else
            {
                success = false;
            }
            //walletId
            return(ConvertToResponseModel(response, success, new PayFabricResponseModel()
            {
                Result = walletId.ToString()
            },
                                          new List <PayfabricCustomerResponseModel>(), new PayfabricTransactionResponse()));
        }
Пример #10
0
 private ResponseModel ConvertToResponseModel(IRestResponse response, bool success, PayFabricResponseModel responseValue, List <PayfabricCustomerResponseModel> customerPaymentDetails, PayfabricTransactionResponse transactionalResponse)
 {
     return(new ResponseModel()
     {
         Success = success,
         Message = response.Content,
         ResponseValue = responseValue,
         CustomerPaymentDetails = customerPaymentDetails,
         TransactionResponse = transactionalResponse
     });
 }