public string DoBrainTreeRefund(string TransCode, decimal Amnt, out string message, out string Refundid) { int OrganizationID; string OrganizationName; string MerchantAccountID = string.Empty; string MerchantID = string.Empty; string PublicKey = string.Empty; string PrivateKey = string.Empty; SqlConnection connection = mySQLConnection.Open(); using (SqlDataReader dr = new EnterpriseDA().GetOrganizationCredentialByID(connection, UserInfo.OrganizationID)) { while (dr.Read()) { OrganizationID = Convert.ToInt32(dr["OrganizationID"].ToString()); OrganizationName = dr["OrganizationName"].ToString(); MerchantAccountID = dr["MerchantAccountID"].ToString(); MerchantID = dr["MerchantID"].ToString(); PublicKey = dr["PublicKey"].ToString(); PrivateKey = dr["PrivateKey"].ToString(); } } bool isExecute = true; if (String.IsNullOrEmpty(MerchantAccountID) || String.IsNullOrEmpty(MerchantID) || String.IsNullOrEmpty(PublicKey) || String.IsNullOrEmpty(PrivateKey)) { isExecute = false; } message = string.Empty; Refundid = string.Empty; string TransactionId = ""; if (isExecute) { var gateway = new BraintreeGateway { Environment = Braintree.Environment.SANDBOX, MerchantId = MerchantID, PublicKey = PublicKey, PrivateKey = PrivateKey }; var request = new TransactionRequest { Amount = Amnt, MerchantAccountId = MerchantAccountID, //CreditCard = new TransactionCreditCardRequest //{ // CVV = CVV2, // Number = CCNumber, // ExpirationDate = expiryDate //}, //Options = new TransactionOptionsRequest //{ // SubmitForSettlement = true //} }; Result <Transaction> result = gateway.Transaction.Refund(TransCode, Amnt); if (result.IsSuccess()) { Transaction transaction = result.Target; message = result.Message; Refundid = result.Transaction.RefundId; TransactionId = "Refunded"; } else if (result.Transaction != null) { Transaction transaction = result.Transaction; message = result.Message + " | status : " + transaction.Status + " | code : " + transaction.ProcessorResponseCode + " | Text : " + transaction.ProcessorResponseText; TransactionId = "-1"; } else { result = gateway.Transaction.Void(TransCode); if (result.IsSuccess()) { TransactionId = "Voided"; } else { message = result.Message; TransactionId = "-1"; } } } else { message = "Merchant account credential is missing for this transaction"; TransactionId = "-1"; } return(TransactionId); }
public string DoBrainTreeTransaction(decimal Amnt, string CardType, string CCNumber, string expiryDate, string CVV2, out string message) { int OrganizationID; string OrganizationName; string MerchantAccountID = string.Empty; string MerchantID = string.Empty; string PublicKey = string.Empty; string PrivateKey = string.Empty; SqlConnection connection = mySQLConnection.Open(); using (SqlDataReader dr = new EnterpriseDA().GetOrganizationCredentialByID(connection, UserInfo.OrganizationID)) { while (dr.Read()) { OrganizationID = Convert.ToInt32(dr["OrganizationID"].ToString()); OrganizationName = dr["OrganizationName"].ToString(); MerchantAccountID = dr["MerchantAccountID"].ToString(); MerchantID = dr["MerchantID"].ToString(); PublicKey = dr["PublicKey"].ToString(); PrivateKey = dr["PrivateKey"].ToString(); } } bool isExecute = true; if (String.IsNullOrEmpty(MerchantAccountID) || String.IsNullOrEmpty(MerchantID) || String.IsNullOrEmpty(PublicKey) || String.IsNullOrEmpty(PrivateKey)) { isExecute = false; } message = string.Empty; string TransactionId = ""; if (isExecute) { var gateway = new BraintreeGateway { Environment = Braintree.Environment.SANDBOX, MerchantId = MerchantID, PublicKey = PublicKey, PrivateKey = PrivateKey }; var request = new TransactionRequest { Amount = Amnt, MerchantAccountId = MerchantAccountID, CreditCard = new TransactionCreditCardRequest { CVV = CVV2, Number = CCNumber, ExpirationDate = expiryDate }, Options = new TransactionOptionsRequest { SubmitForSettlement = true } }; Result <Transaction> result = gateway.Transaction.Sale(request); if (result.IsSuccess()) { Transaction transaction = result.Target; TransactionId = transaction.Id; } else if (result.Transaction != null) { Transaction transaction = result.Transaction; message = result.Message + " | status : " + transaction.Status + " | code : " + transaction.ProcessorResponseCode + " | Text : " + transaction.ProcessorResponseText; TransactionId = "-1"; } else { message = result.Message; TransactionId = "-1"; //foreach (ValidationError error in result.Errors.DeepAll()) //{ //Console.WriteLine("Attribute: " + error.Attribute); // Console.WriteLine(" Code: " + error.Code); //Console.WriteLine(" Message: " + error.Message); //} } } else { message = "Merchant account credential is missing for this transaction"; TransactionId = "-1"; } return(TransactionId); }