コード例 #1
0
        protected PayfirmaTransactionResponse ProcessTransaction(String type, PayfirmaCredentials credentials, Double amount, String transactionId, Boolean isTest)
        {
            PayfirmaTransactionResponse payfirmaResponse = new PayfirmaTransactionResponse();
            var webClient = new WebClient();

            NameValueCollection requestData = new NameValueCollection();

            requestData.Add("key", credentials.APIKey);
            requestData.Add("merchant_id", credentials.MerchantID);
            requestData.Add("amount", amount.ToString());
            if (isTest)
            {
                requestData.Add("test_mode", "true");
            }

            if (type.ToLower() != "refund" && type.ToLower() != "capture")
            {
                payfirmaResponse.Error = "Payfirma Invalid Transaction Type : " + type;
                return(payfirmaResponse);
            }

            if (String.IsNullOrEmpty(transactionId))
            {
                payfirmaResponse.Error = "Payfirma Invalid Transaction ID";
                return(payfirmaResponse);
            }

            String url = this.GetPayfirmaURL() + "/" + type.ToLower() + "/" + transactionId;

            try
            {
                var webResponseByte = webClient.UploadValues(url, "POST", requestData);
                var webResponse     = Encoding.ASCII.GetString(webResponseByte);

                if (!String.IsNullOrEmpty(webResponse))
                {
                    payfirmaResponse = this.HandleTransacitonResponse(webResponse);
                }
                else
                {
                    payfirmaResponse.Error = "Payfirma unknown error";
                }
            }
            catch (Exception e)
            {
                payfirmaResponse.Error = "Payfirma Error: " + e.Message;
            }

            return(payfirmaResponse);
        }
コード例 #2
0
        protected PayfirmaTransactionResponse ProcessTransaction(String type, PayfirmaCredentials credentials, PayfirmaCreditCard cc, PayfirmaMetaData metaData, Double amount, Boolean isTest)
        {
            PayfirmaTransactionResponse payfirmaResponse = new PayfirmaTransactionResponse();
            var webClient = new WebClient();

            NameValueCollection requestData = new NameValueCollection();

            this.GenerateMetaData(metaData, requestData);
            requestData.Add("key", credentials.APIKey);
            requestData.Add("merchant_id", credentials.MerchantID);
            requestData.Add("amount", amount.ToString());
            requestData.Add("card_number", cc.Number);
            requestData.Add("card_expiry_month", cc.ExpMonth.ToString());
            requestData.Add("card_expiry_year", cc.ExpYear.ToString());
            requestData.Add("cvv2", cc.CVV2);
            if (isTest)
            {
                requestData.Add("test_mode", "true");
            }

            requestData.Add("do_not_store", "true");

            if (type.ToLower() != "sale" && type.ToLower() != "authorize")
            {
                // Default to sale transaction type.
                type = "sale";
            }
            String url = this.GetPayfirmaURL() + "/" + type.ToLower();;

            try
            {
                var webResponseByte = webClient.UploadValues(url, "POST", requestData);
                var webResponse     = Encoding.ASCII.GetString(webResponseByte);

                if (!String.IsNullOrEmpty(webResponse))
                {
                    payfirmaResponse = this.HandleTransacitonResponse(webResponse);
                }
                else
                {
                    payfirmaResponse.Error = "Payfirma unknown error";
                }
            }
            catch (Exception e)
            {
                payfirmaResponse.Error = "Payfirma Error: " + e.Message;
            }

            return(payfirmaResponse);
        }
コード例 #3
0
        protected PayfirmaTransactionResponse ProcessTransaction(String type, PayfirmaCredentials credentials, Double amount, String transactionId, Boolean isTest)
        {
            PayfirmaTransactionResponse payfirmaResponse = new PayfirmaTransactionResponse();
            var webClient = new WebClient();

            NameValueCollection requestData = new NameValueCollection();
            requestData.Add("key", credentials.APIKey);
            requestData.Add("merchant_id", credentials.MerchantID);
            requestData.Add("amount", amount.ToString());
            requestData.Add("test_mode", isTest.ToString().ToLower());
            requestData.Add("do_not_store", "true");

            if (type.ToLower() != "refund" && type.ToLower() != "capture")
            {
                payfirmaResponse.Error = "Payfirma Invalid Transaction Type : " + type;
                return payfirmaResponse;
            }

            if (String.IsNullOrEmpty(transactionId))
            {
                payfirmaResponse.Error = "Payfirma Invalid Transaction ID";
                return payfirmaResponse;
            }

            String url = this.GetPayfirmaURL() + "/" + type.ToLower() + "/" + transactionId;

            try
            {
                var webResponseByte = webClient.UploadValues(url, "POST", requestData);
                var webResponse = Encoding.ASCII.GetString(webResponseByte);

                if (!String.IsNullOrEmpty(webResponse))
                {
                    payfirmaResponse = this.HandleTransacitonResponse(webResponse);
                }
                else
                {
                    payfirmaResponse.Error = "Payfirma unknown error";
                }
            }
            catch (Exception e)
            {
                payfirmaResponse.Error = "Payfirma Error: " + e.Message;
            }

            return payfirmaResponse;
        }
コード例 #4
0
        protected PayfirmaTransactionResponse ProcessTransaction(String type, PayfirmaCredentials credentials, PayfirmaCreditCard cc, PayfirmaMetaData metaData, Double amount, Boolean isTest)
        {
            PayfirmaTransactionResponse payfirmaResponse = new PayfirmaTransactionResponse();
            var webClient = new WebClient();

            NameValueCollection requestData = new NameValueCollection();
            this.GenerateMetaData(metaData, requestData);
            requestData.Add("key", credentials.APIKey);
            requestData.Add("merchant_id", credentials.MerchantID);
            requestData.Add("amount", amount.ToString());
            requestData.Add("card_number", cc.Number);
            requestData.Add("card_expiry_month", cc.ExpMonth.ToString());
            requestData.Add("card_expiry_year", cc.ExpYear.ToString());
            requestData.Add("cvv2", cc.CVV2);
            if (isTest) { requestData.Add("test_mode", "true"); }

            requestData.Add("do_not_store", "true");

            if (type.ToLower() != "sale" && type.ToLower() != "authorize")
            {
                // Default to sale transaction type.
                type = "sale";
            }
            String url = this.GetPayfirmaURL() + "/" + type.ToLower(); ;

            try
            {
                var webResponseByte = webClient.UploadValues(url, "POST", requestData);
                var webResponse = Encoding.ASCII.GetString(webResponseByte);

                if (!String.IsNullOrEmpty(webResponse))
                {
                    payfirmaResponse = this.HandleTransacitonResponse(webResponse);
                }
                else
                {
                    payfirmaResponse.Error = "Payfirma unknown error";
                }
            }
            catch (Exception e)
            {
                payfirmaResponse.Error = "Payfirma Error: " + e.Message;
            }

            return payfirmaResponse;
        }
コード例 #5
0
        protected PayfirmaTransactionResponse HandleTransacitonResponse(String webResponse)
        {
            PayfirmaTransactionResponse payfirmaResponse = new PayfirmaTransactionResponse();

            var responseObj = JsonConvert.DeserializeObject <dynamic>(webResponse);

            if (webResponse.Contains("\"error\""))
            {
                // Transaction Failed
                payfirmaResponse.Error = responseObj.error;
            }
            else
            {
                payfirmaResponse.Type          = responseObj.type;
                payfirmaResponse.ResultMessage = responseObj.result;
                payfirmaResponse.Result        = responseObj.result_bool;
                payfirmaResponse.CardType      = responseObj.card_type;
                payfirmaResponse.Amount        = responseObj.amount;
                payfirmaResponse.TransactionId = responseObj.transaction_id;
                payfirmaResponse.Suffix        = responseObj.suffix;
                payfirmaResponse.AVS           = responseObj.avs;
                payfirmaResponse.CVV2          = responseObj.cvv2;
                payfirmaResponse.AuthCode      = responseObj.auth_code;
                payfirmaResponse.Email         = responseObj.email;
                payfirmaResponse.Firstname     = responseObj.first_name;
                payfirmaResponse.Lastname      = responseObj.last_name;
                payfirmaResponse.Address1      = responseObj.address1;
                payfirmaResponse.Address2      = responseObj.address2;
                payfirmaResponse.City          = responseObj.city;
                payfirmaResponse.Province      = responseObj.province;
                payfirmaResponse.Country       = responseObj.country;
                payfirmaResponse.PostalCode    = responseObj.postal_code;
                payfirmaResponse.Company       = responseObj.company;
                payfirmaResponse.Telephone     = responseObj.telephone;
                payfirmaResponse.Description   = responseObj.description;
                payfirmaResponse.OrderId       = responseObj.order_id;
                payfirmaResponse.InvoiceId     = responseObj.invoice_id;
                payfirmaResponse.CustomId      = responseObj.custom_id;
            }

            return(payfirmaResponse);
        }
コード例 #6
0
        protected PayfirmaTransactionResponse HandleTransacitonResponse(String webResponse)
        {
            PayfirmaTransactionResponse payfirmaResponse = new PayfirmaTransactionResponse();

            var responseObj = JsonConvert.DeserializeObject<dynamic>(webResponse);
            if (webResponse.Contains("\"error\""))
            {
                // Transaction Failed                    
                payfirmaResponse.Error = responseObj.error;
            }
            else
            {
                payfirmaResponse.Type = responseObj.type;
                payfirmaResponse.ResultMessage = responseObj.result;
                payfirmaResponse.Result = responseObj.result_bool;
                payfirmaResponse.CardType = responseObj.card_type;
                payfirmaResponse.Amount = responseObj.amount;
                payfirmaResponse.TransactionId = responseObj.transaction_id;
                payfirmaResponse.Suffix = responseObj.suffix;
                payfirmaResponse.AVS = responseObj.avs;
                payfirmaResponse.CVV2 = responseObj.cvv2;
                payfirmaResponse.AuthCode = responseObj.auth_code;
                payfirmaResponse.Email = responseObj.email;
                payfirmaResponse.Firstname = responseObj.first_name;
                payfirmaResponse.Lastname = responseObj.last_name;
                payfirmaResponse.Address1 = responseObj.address1;
                payfirmaResponse.Address2 = responseObj.address2;
                payfirmaResponse.City = responseObj.city;
                payfirmaResponse.Province = responseObj.province;
                payfirmaResponse.Country = responseObj.country;
                payfirmaResponse.PostalCode = responseObj.postal_code;
                payfirmaResponse.Company = responseObj.company;
                payfirmaResponse.Telephone = responseObj.telephone;
                payfirmaResponse.Description = responseObj.description;
                payfirmaResponse.OrderId = responseObj.order_id;
                payfirmaResponse.InvoiceId = responseObj.invoice_id;
                payfirmaResponse.CustomId = responseObj.custom_id;
            }

            return payfirmaResponse;
        }