public void Create_HandlesRequiredValidationErrors() { var request = new MerchantAccountRequest { TosAccepted = true, MasterMerchantAccountId = "sandbox_master_merchant_account" }; Result <MerchantAccount> result = gateway.MerchantAccount.Create(request); Assert.IsFalse(result.IsSuccess()); ValidationErrors errors = result.Errors.ForObject("merchant-account"); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_REQUIRED, errors.ForObject("individual").OnField("first-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_REQUIRED, errors.ForObject("individual").OnField("last-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_REQUIRED, errors.ForObject("individual").OnField("date-of-birth")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_REQUIRED, errors.ForObject("individual").OnField("email")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_REQUIRED, errors.ForObject("individual").ForObject("address").OnField("street-address")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_LOCALITY_IS_REQUIRED, errors.ForObject("individual").ForObject("address").OnField("locality")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_REQUIRED, errors.ForObject("individual").ForObject("address").OnField("postal-code")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_REQUIRED, errors.ForObject("individual").ForObject("address").OnField("region")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_REQUIRED, errors.ForObject("funding").OnField("destination")[0].Code); }
public void Create_HandlesInvalidValidationErrors() { var request = new MerchantAccountRequest { Individual = new IndividualRequest { FirstName = "<>", LastName = "<>", Email = "bad", Phone = "999", Address = new AddressRequest { StreetAddress = "nope", PostalCode = "1", Region = "QQ", }, DateOfBirth = "hah", Ssn = "12345", }, Business = new BusinessRequest { LegalName = "``{}", DbaName = "{}``", TaxId = "bad", Address = new AddressRequest { StreetAddress = "nope", PostalCode = "1", Region = "QQ", }, }, Funding = new FundingRequest { Destination = FundingDestination.UNRECOGNIZED, Email = "BILLFOLD", MobilePhone = "TRIFOLD", RoutingNumber = "LEATHER", AccountNumber = "BACK POCKET", }, TosAccepted = true, MasterMerchantAccountId = "sandbox_master_merchant_account" }; Result<MerchantAccount> result = gateway.MerchantAccount.Create(request); Assert.IsFalse(result.IsSuccess()); ValidationErrors errors = result.Errors.ForObject("merchant-account"); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_INVALID, errors.ForObject("individual").OnField("first-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_INVALID, errors.ForObject("individual").OnField("last-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_INVALID, errors.ForObject("individual").OnField("date-of-birth")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_PHONE_IS_INVALID, errors.ForObject("individual").OnField("phone")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_SSN_IS_INVALID, errors.ForObject("individual").OnField("ssn")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_INVALID, errors.ForObject("individual").OnField("email")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_INVALID, errors.ForObject("individual").ForObject("address").OnField("street-address")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_INVALID, errors.ForObject("individual").ForObject("address").OnField("postal-code")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_INVALID, errors.ForObject("individual").ForObject("address").OnField("region")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_DBA_NAME_IS_INVALID, errors.ForObject("business").OnField("dba-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_INVALID, errors.ForObject("business").OnField("legal-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_INVALID, errors.ForObject("business").OnField("tax-id")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_ADDRESS_STREET_ADDRESS_IS_INVALID, errors.ForObject("business").ForObject("address").OnField("street-address")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_ADDRESS_POSTAL_CODE_IS_INVALID, errors.ForObject("business").ForObject("address").OnField("postal-code")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_ADDRESS_REGION_IS_INVALID, errors.ForObject("business").ForObject("address").OnField("region")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_INVALID, errors.ForObject("funding").OnField("destination")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_ACCOUNT_NUMBER_IS_INVALID, errors.ForObject("funding").OnField("account-number")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_ROUTING_NUMBER_IS_INVALID, errors.ForObject("funding").OnField("routing-number")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_INVALID, errors.ForObject("funding").OnField("email")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_INVALID, errors.ForObject("funding").OnField("mobile-phone")[0].Code); }
public void Create_HandlesRequiredValidationErrors() { var request = new MerchantAccountRequest { TosAccepted = true, MasterMerchantAccountId = "sandbox_master_merchant_account" }; Result<MerchantAccount> result = gateway.MerchantAccount.Create(request); Assert.IsFalse(result.IsSuccess()); ValidationErrors errors = result.Errors.ForObject("merchant-account"); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_REQUIRED, errors.ForObject("individual").OnField("first-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_REQUIRED, errors.ForObject("individual").OnField("last-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_REQUIRED, errors.ForObject("individual").OnField("date-of-birth")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_REQUIRED, errors.ForObject("individual").OnField("email")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_REQUIRED, errors.ForObject("individual").ForObject("address").OnField("street-address")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_LOCALITY_IS_REQUIRED, errors.ForObject("individual").ForObject("address").OnField("locality")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_REQUIRED, errors.ForObject("individual").ForObject("address").OnField("postal-code")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_REQUIRED, errors.ForObject("individual").ForObject("address").OnField("region")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_REQUIRED, errors.ForObject("funding").OnField("destination")[0].Code); }
public void Create_HandlesInvalidValidationErrors() { var request = new MerchantAccountRequest { Individual = new IndividualRequest { FirstName = "<>", LastName = "<>", Email = "bad", Phone = "999", Address = new AddressRequest { StreetAddress = "nope", PostalCode = "1", Region = "QQ", }, DateOfBirth = "hah", Ssn = "12345", }, Business = new BusinessRequest { LegalName = "``{}", DbaName = "{}``", TaxId = "bad", Address = new AddressRequest { StreetAddress = "nope", PostalCode = "1", Region = "QQ", }, }, Funding = new FundingRequest { Destination = FundingDestination.UNRECOGNIZED, Email = "BILLFOLD", MobilePhone = "TRIFOLD", RoutingNumber = "LEATHER", AccountNumber = "BACK POCKET", }, TosAccepted = true, MasterMerchantAccountId = "sandbox_master_merchant_account" }; Result <MerchantAccount> result = gateway.MerchantAccount.Create(request); Assert.IsFalse(result.IsSuccess()); ValidationErrors errors = result.Errors.ForObject("merchant-account"); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_INVALID, errors.ForObject("individual").OnField("first-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_INVALID, errors.ForObject("individual").OnField("last-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_INVALID, errors.ForObject("individual").OnField("date-of-birth")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_PHONE_IS_INVALID, errors.ForObject("individual").OnField("phone")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_SSN_IS_INVALID, errors.ForObject("individual").OnField("ssn")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_INVALID, errors.ForObject("individual").OnField("email")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_INVALID, errors.ForObject("individual").ForObject("address").OnField("street-address")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_INVALID, errors.ForObject("individual").ForObject("address").OnField("postal-code")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_INVALID, errors.ForObject("individual").ForObject("address").OnField("region")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_DBA_NAME_IS_INVALID, errors.ForObject("business").OnField("dba-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_INVALID, errors.ForObject("business").OnField("legal-name")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_INVALID, errors.ForObject("business").OnField("tax-id")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_ADDRESS_STREET_ADDRESS_IS_INVALID, errors.ForObject("business").ForObject("address").OnField("street-address")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_ADDRESS_POSTAL_CODE_IS_INVALID, errors.ForObject("business").ForObject("address").OnField("postal-code")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_BUSINESS_ADDRESS_REGION_IS_INVALID, errors.ForObject("business").ForObject("address").OnField("region")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_INVALID, errors.ForObject("funding").OnField("destination")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_ACCOUNT_NUMBER_IS_INVALID, errors.ForObject("funding").OnField("account-number")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_ROUTING_NUMBER_IS_INVALID, errors.ForObject("funding").OnField("routing-number")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_INVALID, errors.ForObject("funding").OnField("email")[0].Code); Assert.AreEqual(ValidationErrorCode.MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_INVALID, errors.ForObject("funding").OnField("mobile-phone")[0].Code); }
/// <summary> /// Create or update the payment account for the provider at the payment gateway (Braintree) given /// that user information. /// On Braintree Marketplace, this is called 'Create a Sub Merchant' /// </summary> /// <param name="user"></param> /// <param name="address"></param> /// <param name="bank"></param> /// <param name="gateway"></param> /// <returns>It returns the result of the Braintree transaction (check for IsSuccess to know the result), /// or null when there Braintree doesn't authorize the operation (AuthorizationException catched), /// it means the details are not complete or malformed.</returns> public static dynamic CreateProviderPaymentAccount(dynamic user, LcData.Address address, dynamic bank, DateTime BirthDate, string Ssn, BraintreeGateway gateway = null) { gateway = NewBraintreeGateway(gateway); // We need to detect what FundingDestination notify depending on the provided // information // Analizing source bank information: asterisks means 'not to set -- preseve previous value', other value is send being // null or empty to clear/remove previous value // Next variables will have null for 'not to set' or any other to be udpated. string routingNumber = null; string accountNumber = null; FundingDestination fundingDest = FundingDestination.EMAIL; if (bank != null) { // Null and asterisks values are not set if (bank.RoutingNumber != null && !bank.RoutingNumber.Contains("*")) { routingNumber = bank.RoutingNumber; } if (bank.AccountNumber != null && !bank.AccountNumber.Contains("*")) { accountNumber = bank.AccountNumber; } // We check against the bank object because has the original values. // Here, we allow an asterisks value as valid, because is a previous one // that will be preserved, or any new value to be set just different // from empty or null if (!String.IsNullOrEmpty(bank.AccountNumber) && !String.IsNullOrEmpty(bank.RoutingNumber)) { fundingDest = FundingDestination.BANK; } else if (!String.IsNullOrWhiteSpace(user.MobilePhone)) { fundingDest = FundingDestination.MOBILE_PHONE; } } var updateBankInfo = bank != null; var btAccount = GetProviderPaymentAccount((int)user.UserID); MerchantAccountRequest request = new MerchantAccountRequest { Individual = new IndividualRequest { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Phone = user.MobilePhone, Address = new AddressRequest { StreetAddress = address.AddressLine1, // NOTE: We set the ExtendedAddress, but was communicated by Braintree on 2014-03-12 // that field is not being stored (support messages copies at #454). // On the interface, we rely on our db for the copied version of that address part as fallback. ExtendedAddress = address.AddressLine2, PostalCode = address.PostalCode, Locality = address.City, Region = address.StateProvinceCode, //CountryCodeAlpha2 = address.CountryCodeAlpha2 }, DateOfBirth = BirthDate.ToString("yyyy-MM-dd") }, TosAccepted = true, MasterMerchantAccountId = BraintreeMerchantAccountId, Id = LcPayment.GetProviderPaymentAccountId((int)user.UserID) }; if (btAccount == null || String.IsNullOrWhiteSpace(Ssn) || !Ssn.Contains("*")) { // Braintree require pass an empty string to remove the value of SSN in case of // user remove it from the form field: request.Individual.Ssn = String.IsNullOrWhiteSpace(Ssn) ? "" : Ssn; } // Set payment/funding information only on creation or explicitely // asked for update of its data if (btAccount == null || updateBankInfo) { request.Funding = new FundingRequest { Destination = fundingDest, Email = user.Email, MobilePhone = user.MobilePhone }; // On null, we don't set the values, empty to remove or value to set if (routingNumber != null) { request.Funding.RoutingNumber = routingNumber; } if (accountNumber != null) { request.Funding.AccountNumber = accountNumber; } } try{ Result <MerchantAccount> ret = null; if (btAccount == null) { ret = gateway.MerchantAccount.Create(request); } else { ret = gateway.MerchantAccount.Update(request.Id, request); } // All Ok, register on database if (ret.IsSuccess()) { LcData.SetProviderPaymentAccount( user.UserID, request.Id, btAccount == null ? "pending" : null, null, null, null ); } return(ret); } catch (Braintree.Exceptions.AuthorizationException ex) { throw ex; //return null; } }
/// <summary> /// Creates the sub-merchant account in Braintree /// </summary> /// <param name="individual">The individual merchant info</param> /// <param name="business">The business merchant info</param> /// <param name="funding">The funding merchant info</param> /// <param name="isTosAccepted">The TOS accepted flag</param> /// <param name="merchantAccountId">The existing merchant account Id</param> public CreateSubMerchantResponse CreateOrUpdateSubMerchant(IndividualMerchantInfo individual, BusinessMerchantInfo business, FundingMerchantInfo funding, Boolean isTosAccepted, String merchantAccountId = null) { var request = new MerchantAccountRequest(); request.Individual = new IndividualRequest { FirstName = individual.FirstName, LastName = individual.LastName, Email = individual.Email, Phone = individual.Phone, DateOfBirth = individual.DateOfBirth.ToString("yyyy-MM-dd"), Ssn = individual.Ssn, Address = new AddressRequest { StreetAddress = individual.StreetAddress, Locality = individual.Locality, Region = individual.Region, PostalCode = individual.PostalCode } }; if (business != null) { request.Business = new BusinessRequest { LegalName = business.LegalName, DbaName = business.DbaName, TaxId = business.TaxId, Address = new AddressRequest { StreetAddress = business.StreetAddress, Locality = business.Locality, Region = business.Region, PostalCode = business.PostalCode } }; } request.Funding = new FundingRequest { Descriptor = funding.Descriptor, Destination = FundingDestination.BANK, //TODO: check this logic Email = funding.Email, MobilePhone = funding.MobilePhone, AccountNumber = funding.AccountNumber, RoutingNumber = funding.RoutingNumber }; request.TosAccepted = isTosAccepted; request.MasterMerchantAccountId = _configurationProvider["BraintreeMerchantAccountId"]; var result = String.IsNullOrEmpty(merchantAccountId) ? _gateway.MerchantAccount.Create(request) : _gateway.MerchantAccount.Update(merchantAccountId, request); var response = new CreateSubMerchantResponse { IsSuccess = result.IsSuccess(), }; if (response.IsSuccess) { response.SubMerchantId = result.Target.Id; response.AccountStatus = result.Target.Status.ToString(); } else { response.Errors = CollectResponseErrors(result.Errors, result.Message); } return(response); }
public ActionResult CreateMerchant() { //var request = new AddressRequest //{ // FirstName = "Jenna", // LastName = "Smith", // Company = "Braintree", // StreetAddress = "1 E Main St", // ExtendedAddress = "Suite 403", // Locality = "Chicago", // Region = "Illinois", // PostalCode = "60622", // CountryCodeAlpha2 = "US" //}; BraintreeGateway gateway = new BraintreeGateway( Braintree.Environment.SANDBOX, "2jy7ybdh4h7j4dtc", "ks38q8k5b8637njx", "e9bcaf74b68c95e35d4d92b339801d5b" ); MerchantAccountRequest request = new MerchantAccountRequest { Individual = new IndividualRequest { FirstName = "Jane", LastName = "Doe", Email = "*****@*****.**", Phone = "5553334444", DateOfBirth = "1981-11-19", Ssn = "456-45-4567", Address = new AddressRequest { StreetAddress = "111 Main St", Locality = "Chicago", Region = "IL", PostalCode = "60622" } }, Business = new BusinessRequest { LegalName = "Jane's Ladders", DbaName = "Jane's Ladders", TaxId = "98-7654321", Address = new AddressRequest { StreetAddress = "111 Main St", Locality = "Chicago", Region = "IL", PostalCode = "60622" } }, Funding = new FundingRequest { Descriptor = "Blue Ladders", Destination = FundingDestination.BANK, Email = "*****@*****.**", MobilePhone = "5555555555", AccountNumber = "1123581321", RoutingNumber = "071101307" }, TosAccepted = true, MasterMerchantAccountId = "14ladders_marketplace", Id = "blue_ladders_store" }; Result <MerchantAccount> result = gateway.MerchantAccount.Create(request); //TransactionCreditCardRequest creditCardRequest = new TransactionCreditCardRequest(); //creditCardRequest.CardholderName = "Ahmet Mehmet"; //creditCardRequest.Number = "4444-5555-6666-7777"; //creditCardRequest.ExpirationDate = "04/21"; //creditCardRequest.CVV = "233"; //TransactionOptionsRequest optionsRequest = new TransactionOptionsRequest(); //optionsRequest.SubmitForSettlement = true; if (result.IsSuccess()) { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("google.com")); }