Exemple #1
0
        public TransactionResponse PayWithCheck(int peopleId, decimal amt, string routing, string acct, string description, int tranid, string email, string first, string middle, string last, string suffix, string addr, string addr2, string city, string state, string country, string zip, string phone)
        {
            var achCharge = new AchCharge(
                _isTesting,
                _apiKey,
                _merch_ach_id,
                new Ach
            {
                AchAccNum     = acct,
                AchRoutingNum = routing
            },
                new Payer
            {
                LastName  = last,
                FirstName = first,
                Address   = addr,
                Address2  = addr2,
                City      = city,
                State     = UPSStateCodes.FromStateCountry(state, country, db) ?? state,
                Country   = ISO3166.Alpha3FromName(country) ?? country,
                Zip       = zip,
                Email     = email,
                Phone     = phone
            },
                amt,
                tranid.ToString(CultureInfo.InvariantCulture),
                description,
                peopleId.ToString(CultureInfo.InvariantCulture));

            var response = achCharge.Execute();

            var transactionResponse = new TransactionResponse
            {
                Approved      = response.Response.Status == "success" ? true : false,
                AuthCode      = response.Response.TransStatus,
                Message       = $"{response.Response.TransStatusMsg}#{response.Response.Items.First().IdString}",
                TransactionId = response.Response.TransIdStr
            };

            if (_automaticSettle && transactionResponse.Approved)
            {
                SettleTransaction(response.Response.TransIdStr);
            }

            return(transactionResponse);
        }
        private void StorePayerData(Person person, PaymentInfo paymentInfo, string cardNumber, string expires, string account, string routing)
        {
            //var creditCard = new CreditCard();
            //creditCard.CardNum = cardNumber;
            //creditCard.CardExpiration = expires;
            //var storePayer = new StorePayer();

            var storePayer = new StorePayer(
                _isTesting,
                _apiKey,
                new Payer
            {
                LastName  = paymentInfo.LastName ?? person.LastName,
                FirstName = paymentInfo.FirstName ?? person.LastName,
                Address   = paymentInfo.Address ?? person.AddressLineOne,
                Address2  = paymentInfo.Address2 ?? person.AddressLineTwo,
                City      = paymentInfo.City ?? person.CityName,
                State     = UPSStateCodes.FromStateCountry(paymentInfo.State ?? null, paymentInfo.Country, db) ?? paymentInfo.State,
                Country   = ISO3166.Alpha3FromName(paymentInfo.Country ?? person.CountryName) ?? null,
                Zip       = paymentInfo.Zip ?? person.PrimaryZip,
                Email     = person.EmailAddress,
                Phone     = paymentInfo.Phone ?? person.HomePhone ?? person.CellPhone
            },
                paymentInfo.AcceptivaPayerId,
                new CreditCard
            {
                CardNum        = cardNumber,
                CardExpiration = expires
            },
                new Ach
            {
                AchAccNum     = account,
                AchRoutingNum = routing
            });

            var response = storePayer.Execute();

            if (response.Response.Status != "success")
            {
                throw new Exception(
                          $"Acceptiva failed to update the credit card for people id: {person.PeopleId}, responseCode: {response.Response.Errors.FirstOrDefault()?.ErrorNo}, responseText: {response.Response.Errors.FirstOrDefault()?.ErrorMsg}");
            }
        }
        //private methods
        private TransactionResponse CreditCardCharge(int peopleId, decimal amt, string cardnumber, string expires, string description, int tranid, string cardcode, string email, string first, string last, string addr, string addr2, string city, string state, string country, string zip, string phone)
        {
            var cardCharge = new CreditCardCharge(
                _isTesting,
                _apiKey,
                _merch_cc_id,
                new CreditCard
            {
                CardNum        = cardnumber,
                CardExpiration = expires,
                CardCvv        = cardcode
            },
                new Payer
            {
                LastName  = last,
                FirstName = first,
                Address   = addr,
                Address2  = addr2,
                City      = city,
                State     = UPSStateCodes.FromStateCountry(state, country, db) ?? state,
                Country   = ISO3166.Alpha3FromName(country) ?? country,
                Zip       = zip,
                Email     = email,
                Phone     = phone
            },
                amt,
                tranid.ToString(CultureInfo.InvariantCulture),
                description);

            var response = cardCharge.Execute();

            return(new TransactionResponse
            {
                Approved = response.Response.Status == "success" ? true : false,
                AuthCode = response.Response.ProcessorResponseCode,
                Message = $"{response.Response.TransStatusMsg}#{response.Response.Items.First().IdString}",
                TransactionId = response.Response.TransIdStr
            });
        }