This is the primary interface to the Braintree Gateway.
This class interact with:
  • Addresses
  • CreditCards
  • Customers
  • Subscriptions
  • Transactions
Inheritance: IBraintreeGateway
Esempio n. 1
0
 public void Generate_RaisesExceptionIfFailOnDuplicatePaymentMethodIsIncludedWithoutCustomerId()
 {
     BraintreeGateway gateway = new BraintreeGateway
     {
         Environment = Environment.DEVELOPMENT,
         MerchantId = "integration_merchant_id",
         PublicKey = "integration_public_key",
         PrivateKey = "integration_private_key"
     };
     try {
         gateway.ClientToken.generate(
             new ClientTokenRequest
             {
                 Options = new ClientTokenOptionsRequest
                 {
                     FailOnDuplicatePaymentMethod = true
                 }
             }
         );
         Assert.Fail("Should raise ArgumentException");
     } catch (ArgumentException e) {
         Match match = Regex.Match(e.Message, @"FailOnDuplicatePaymentMethod");
         Assert.IsTrue(match.Success);
     }
 }
 public void Setup()
 {
     gateway = new BraintreeGateway(
         "client_id$development$integration_client_id",
         "client_secret$development$integration_client_secret"
     );
 }
Esempio n. 3
0
        protected internal AndroidPayCard(NodeWrapper node, BraintreeGateway gateway)
        {
            CardType = node.GetString("virtual-card-type");
            VirtualCardType = node.GetString("virtual-card-type");
            SourceCardType = node.GetString("source-card-type");
            Last4 = node.GetString("virtual-card-last-4");
            SourceCardLast4 = node.GetString("source-card-last-4");
            VirtualCardLast4 = node.GetString("virtual-card-last-4");
            Bin = node.GetString("bin");
            ExpirationMonth = node.GetString("expiration-month");
            ExpirationYear = node.GetString("expiration-year");
            GoogleTransactionId = node.GetString("google-transaction-id");
            Token = node.GetString("token");
            IsDefault = node.GetBoolean("default");
            ImageUrl = node.GetString("image-url");

            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var subscriptionXmlNodes = node.GetList("subscriptions/subscription");
            Subscriptions = new Subscription[subscriptionXmlNodes.Count];
            for (int i = 0; i < subscriptionXmlNodes.Count; i++)
            {
                Subscriptions[i] = new Subscription(subscriptionXmlNodes[i], gateway);
            }
        }
Esempio n. 4
0
 public static string GenerateDecodedClientToken(BraintreeGateway gateway, ClientTokenRequest request = null)
 {
   var encodedClientToken = gateway.ClientToken.generate(request);
   var decodedClientToken = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(encodedClientToken));
   var unescapedClientToken = System.Text.RegularExpressions.Regex.Unescape(decodedClientToken);
   return unescapedClientToken;
 }
        // GET api/<controller>
        public IEnumerable<SimpleTransaction> Get(string pub, string priv, string merchant, long from, long to)
        {
            var gateway = new BraintreeGateway
            {
                Environment = Braintree.Environment.SANDBOX,
                MerchantId = merchant,
                PublicKey = pub,
                PrivateKey = priv
            };

            var fromDate = FromUnixTime(from);
            var toDate = FromUnixTime(to).AddDays(1);

            var request = new TransactionSearchRequest().SubmittedForSettlementAt.Between(fromDate, toDate);

            ResourceCollection<Transaction> collection = gateway.Transaction.Search(request);

            return (from Transaction transaction in collection
                    select new SimpleTransaction
                    {
                        Id = transaction.Id,
                        MerchantAccountId = transaction.MerchantAccountId,
                        Status = transaction.Status.ToString(),
                        Amount = transaction.Amount,
                        TaxAmount = transaction.TaxAmount,
                        CreatedAt = transaction.CreatedAt,
                        CurrencyIsoCode = transaction.CurrencyIsoCode
                    }).ToList();
        }
 public AccountController(SignInManager <TCPUser> signInManager, EmailService emailService, BraintreeGateway braintreeGateway, TCPDbContext context)
 {
     this._signInManager    = signInManager;
     this._emailService     = emailService;
     this._braintreeGateway = braintreeGateway;
     this._context          = context;
 }
Esempio n. 7
0
        private void GetSavedPayMethodInfo(string paymentNonce, out string customerId, out string token, out string type) {
            using(var ctx = new Data.FitathonDataEntities()) {
                var user = Common.GetUserFromEmail(ctx, Context.User.Identity.Name);
                var sponsor = user.sponsors.SingleOrDefault();
                var evt = sponsor.participant.fitevent;

                var gateway = new Braintree.BraintreeGateway {
                    Environment = Braintree.Environment.SANDBOX,
                    MerchantId = evt.braintreeClientID,
                    PublicKey = evt.braintreePublicKey,
                    PrivateKey = evt.braintreePrivateKey
                };

                //create request with just the payment nonce (empty customer)
                var custRequest = new Braintree.CustomerRequest {
                    PaymentMethodNonce = paymentNonce
                };
                Braintree.Result<Braintree.Customer> custResult = gateway.Customer.Create(custRequest);

                if(custResult.IsSuccess()) {
                    Braintree.Customer customer = custResult.Target;
                    customerId = customer.Id;
                    token = customer.PaymentMethods[0].Token;
                    type = GetPMType(customer.PaymentMethods[0]);
                    return;
                }
            }
            customerId = null;
            token = null;
            type = null;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var gateway = new BraintreeGateway
            {
                Environment = Braintree.Environment.SANDBOX,
                MerchantId = "78c2hsmmg73s6sdg",
                PublicKey = "jsyrqbxq2fqv456k",
                PrivateKey = "004b6691b796db322c57c71343ecf592"
            };

            if (!IsPostBack)
            {
                var clientToken = gateway.ClientToken.generate();
                String clientTK = clientToken;
                cTK.Value = clientToken;
            }
            else
            {
                var nonceFromTheClient = Request.Form["payment_method_nonce"];

                var request = new TransactionRequest
                {
                    Amount = 100.00M,
                    PaymentMethodNonce = nonceFromTheClient
                };

                Result<Transaction> result = gateway.Transaction.Sale(request);
                var id = result.Transaction.Id;
                var amount = result.Transaction.Amount;
                var date = result.Transaction.UpdatedAt;
                var status = result.Transaction.ProcessorResponseCode;
            }
        }
        public CreditCardVerification(NodeWrapper node, BraintreeGateway gateway)
        {
            if (node == null) return;

            AvsErrorResponseCode = node.GetString("avs-error-response-code");
            AvsPostalCodeResponseCode = node.GetString("avs-postal-code-response-code");
            AvsStreetAddressResponseCode = node.GetString("avs-street-address-response-code");
            CvvResponseCode = node.GetString("cvv-response-code");
            GatewayRejectionReason = (TransactionGatewayRejectionReason)CollectionUtil.Find(
                TransactionGatewayRejectionReason.ALL,
                node.GetString("gateway-rejection-reason"),
                null
            );
            ProcessorResponseCode = node.GetString("processor-response-code");
            ProcessorResponseText = node.GetString("processor-response-text");
            MerchantAccountId = node.GetString("merchant-account-id");
            Status = (VerificationStatus)CollectionUtil.Find(VerificationStatus.ALL, node.GetString("status"), VerificationStatus.UNRECOGNIZED);
            Id = node.GetString("id");
            BillingAddress = new Address(node.GetNode("billing"));
            CreditCard = new CreditCard(node.GetNode("credit-card"), gateway);
            CreatedAt = node.GetDateTime("created-at");

            var riskDataNode = node.GetNode("risk-data");
            if (riskDataNode != null) {
                RiskData = new RiskData(riskDataNode);
            }
        }
Esempio n. 10
0
        public Subscription(NodeWrapper node, BraintreeGateway gateway)
        {
            Balance                = node.GetDecimal("balance");
            BillingDayOfMonth      = node.GetInteger("billing-day-of-month");
            BillingPeriodEndDate   = node.GetDateTime("billing-period-end-date");
            BillingPeriodStartDate = node.GetDateTime("billing-period-start-date");
            CurrentBillingCycle    = node.GetInteger("current-billing-cycle");
            DaysPastDue            = node.GetInteger("days-past-due");
            Descriptor             = new Descriptor(node.GetNode("descriptor"));
            FailureCount           = node.GetInteger("failure-count");
            FirstBillingDate       = node.GetDateTime("first-billing-date");
            CreatedAt              = node.GetDateTime("created-at");
            UpdatedAt              = node.GetDateTime("updated-at");
            Id                      = node.GetString("id");
            NextBillAmount          = node.GetDecimal("next-bill-amount");
            NextBillingDate         = node.GetDateTime("next-billing-date");
            NextBillingPeriodAmount = node.GetDecimal("next-billing-period-amount");
            NeverExpires            = node.GetBoolean("never-expires");
            NumberOfBillingCycles   = node.GetInteger("number-of-billing-cycles");
            PaymentMethodToken      = node.GetString("payment-method-token");
            PaidThroughDate         = node.GetDateTime("paid-through-date");
            PlanId                  = node.GetString("plan-id");
            Price                   = node.GetDecimal("price");
            Status                  = (SubscriptionStatus)CollectionUtil.Find(SubscriptionStatus.STATUSES, node.GetString("status"), SubscriptionStatus.UNRECOGNIZED);
            List <NodeWrapper> statusNodes = node.GetList("status-history/status-event");

            StatusHistory = new SubscriptionStatusEvent[statusNodes.Count];
            for (int i = 0; i < statusNodes.Count; i++)
            {
                StatusHistory[i] = new SubscriptionStatusEvent(statusNodes[i]);
            }
            HasTrialPeriod = node.GetBoolean("trial-period");
            TrialDuration  = node.GetInteger("trial-duration");
            var trialDurationUnitStr = node.GetString("trial-duration-unit");

            if (trialDurationUnitStr != null)
            {
                TrialDurationUnit = (SubscriptionDurationUnit)CollectionUtil.Find(SubscriptionDurationUnit.ALL, trialDurationUnitStr, SubscriptionDurationUnit.UNRECOGNIZED);
            }
            MerchantAccountId = node.GetString("merchant-account-id");

            AddOns = new List <AddOn> ();
            foreach (var addOnResponse in node.GetList("add-ons/add-on"))
            {
                AddOns.Add(new AddOn(addOnResponse));
            }
            Discounts = new List <Discount> ();
            foreach (var discountResponse in node.GetList("discounts/discount"))
            {
                Discounts.Add(new Discount(discountResponse));
            }
            Transactions = new List <Transaction> ();
            foreach (var transactionResponse in node.GetList("transactions/transaction"))
            {
                Transactions.Add(new Transaction(transactionResponse, gateway));
            }
        }
        public PAAPaymentService()
        {
            string merchantId  = System.Configuration.ConfigurationManager.AppSettings["Braintree.MerchantId"];
            string environment = System.Configuration.ConfigurationManager.AppSettings["Braintree.Environment"];
            string publicKey   = System.Configuration.ConfigurationManager.AppSettings["Braintree.PublicKey"];
            string privateKey  = System.Configuration.ConfigurationManager.AppSettings["Braintree.PrivateKey"];

            gateway = new Braintree.BraintreeGateway(environment, merchantId, publicKey, privateKey);
        }
 public PaymentManager()
 {
     _gateway = new BraintreeGateway
     {
         Environment = Environment.SANDBOX,
         MerchantId = "t5n73yh25jb5sxxf",
         PublicKey = "5srydbsj263fpy7d",
         PrivateKey = "eab6d68d548b38a7fcf052a755b5cf2e"
     };
 }
        protected internal PaymentMethodNonce(NodeWrapper node, BraintreeGateway gateway)
        {
            Nonce = node.GetString("nonce");
            Type = node.GetString("type");

            var threeDSecureInfoNode = node.GetNode("three-d-secure-info");
            if (threeDSecureInfoNode != null && !threeDSecureInfoNode.IsEmpty()){
                ThreeDSecureInfo = new ThreeDSecureInfo(threeDSecureInfoNode);
            }
        }
 public void Setup()
 {
     gateway = new BraintreeGateway
     {
         Environment = Environment.DEVELOPMENT,
         MerchantId = "integration_merchant_id",
         PublicKey = "integration_public_key",
         PrivateKey = "integration_private_key"
     };
 }
        public void SetConfigurationEnvironment_WithString()
        {
            BraintreeGateway gateway = new BraintreeGateway(
                "development",
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            );

            Assert.AreEqual(gateway.Environment, Environment.DEVELOPMENT);
        }
Esempio n. 16
0
 public CheckOutController(BoatChartersDbContext oContext,
                           EmailService emailService,
                           SignInManager <BoatChartesUser> signInManager,
                           Braintree.BraintreeGateway braintreeGateway, SmartyStreets.USStreetApi.Client usStreetApiClient)
 {
     _oContext          = oContext;
     _emailService      = emailService;
     _signInManager     = signInManager;
     _braintreeGateway  = braintreeGateway;
     _usStreetApiClient = usStreetApiClient;
 }
 public CheckOutController(TCPDbContext context,
                           SignInManager <TCPUser> signInManager,
                           Braintree.BraintreeGateway braintreeGateway,
                           EmailService emailService,
                           SmartyStreets.USStreetApi.Client usStreetApiClient)
 {
     this._context           = context;
     this._signInManager     = signInManager;
     this._brainTreeGateway  = braintreeGateway;
     this._usStreetApiClient = usStreetApiClient;
     this._emailService      = emailService;
 }
        protected internal PaymentMethodNonce(NodeWrapper node, BraintreeGateway gateway)
        {
            Nonce = node.GetString("nonce");
            Type  = node.GetString("type");

            var threeDSecureInfoNode = node.GetNode("three-d-secure-info");

            if (threeDSecureInfoNode != null && !threeDSecureInfoNode.IsEmpty())
            {
                ThreeDSecureInfo = new ThreeDSecureInfo(threeDSecureInfoNode);
            }
        }
Esempio n. 19
0
        public WebhookNotification(NodeWrapper node, BraintreeGateway gateway)
        {
            Timestamp = node.GetDateTime("timestamp");
            Kind      = (WebhookKind)CollectionUtil.Find(WebhookKind.ALL, node.GetString("kind"), WebhookKind.UNRECOGNIZED);

            NodeWrapper WrapperNode = node.GetNode("subject");

            if (WrapperNode.GetNode("api-error-response") != null)
            {
                WrapperNode = WrapperNode.GetNode("api-error-response");
            }

            if (WrapperNode.GetNode("subscription") != null)
            {
                Subscription = new Subscription(WrapperNode.GetNode("subscription"), gateway);
            }

            if (WrapperNode.GetNode("merchant-account") != null)
            {
                MerchantAccount = new MerchantAccount(WrapperNode.GetNode("merchant-account"));
            }

            if (WrapperNode.GetNode("dispute") != null)
            {
                Dispute = new Dispute(WrapperNode.GetNode("dispute"));
            }

            if (WrapperNode.GetNode("transaction") != null)
            {
                Transaction = new Transaction(WrapperNode.GetNode("transaction"), gateway);
            }

            if (WrapperNode.GetNode("disbursement") != null)
            {
                Disbursement = new Disbursement(WrapperNode.GetNode("disbursement"), gateway);
            }

            if (WrapperNode.GetNode("partner-merchant") != null)
            {
                PartnerMerchant = new PartnerMerchant(WrapperNode.GetNode("partner-merchant"));
            }

            if (WrapperNode.GetNode("errors") != null)
            {
                Errors = new ValidationErrors(WrapperNode.GetNode("errors"));
            }

            if (WrapperNode.GetNode("message") != null)
            {
                Message = WrapperNode.GetString("message");
            }
        }
Esempio n. 20
0
        public void Setup()
        {
            gateway = new BraintreeGateway
            {
                Environment = Environment.DEVELOPMENT,
                MerchantId = "integration_merchant_id",
                PublicKey = "integration_public_key",
                PrivateKey = "integration_private_key"
            };

            XmlDocument attributesXml = CreateAttributesXml();
            attributes = new NodeWrapper(attributesXml).GetNode("//disbursement");
        }
Esempio n. 21
0
        protected internal PayPalAccount(NodeWrapper node, BraintreeGateway gateway)
        {
            Email = node.GetString("email");
            Token = node.GetString("token");
            IsDefault = node.GetBoolean("default");
            ImageUrl = node.GetString("image-url");
            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var subscriptionXmlNodes = node.GetList("subscriptions/subscription");
            Subscriptions = new Subscription[subscriptionXmlNodes.Count];
            for (int i = 0; i < subscriptionXmlNodes.Count; i++)
            {
                Subscriptions[i] = new Subscription(subscriptionXmlNodes[i], gateway);
            }
        }
Esempio n. 22
0
 public Disbursement(NodeWrapper node, BraintreeGateway gateway)
 {
     Id               = node.GetString("id");
     Amount           = node.GetDecimal("amount");
     ExceptionMessage = node.GetString("exception-message");
     DisbursementDate = node.GetDateTime("disbursement-date");
     FollowUpAction   = node.GetString("follow-up-action");
     MerchantAccount  = new MerchantAccount(node.GetNode("merchant-account"));
     TransactionIds   = new List <string>();
     foreach (var stringNode in node.GetList("transaction-ids/item"))
     {
         TransactionIds.Add(stringNode.GetString("."));
     }
     Success      = node.GetBoolean("success");
     Retry        = node.GetBoolean("retry");
     this.gateway = gateway;
 }
Esempio n. 23
0
        protected internal PayPalAccount(NodeWrapper node, BraintreeGateway gateway)
        {
            Email     = node.GetString("email");
            Token     = node.GetString("token");
            IsDefault = node.GetBoolean("default");
            ImageUrl  = node.GetString("image-url");
            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var subscriptionXmlNodes = node.GetList("subscriptions/subscription");

            Subscriptions = new Subscription[subscriptionXmlNodes.Count];
            for (int i = 0; i < subscriptionXmlNodes.Count; i++)
            {
                Subscriptions[i] = new Subscription(subscriptionXmlNodes[i], gateway);
            }
        }
Esempio n. 24
0
 public Disbursement(NodeWrapper node, BraintreeGateway gateway)
 {
     Id = node.GetString("id");
     Amount = node.GetDecimal("amount");
     ExceptionMessage = node.GetString("exception-message");
     DisbursementDate = node.GetDateTime("disbursement-date");
     FollowUpAction = node.GetString("follow-up-action");
     MerchantAccount = new MerchantAccount(node.GetNode("merchant-account"));
     TransactionIds = new List<string>();
     foreach (var stringNode in node.GetList("transaction-ids/item")) 
     {
         TransactionIds.Add(stringNode.GetString("."));
     }
     Success = node.GetBoolean("success");
     Retry = node.GetBoolean("retry");
     this.gateway = gateway;
 }
Esempio n. 25
0
        protected internal CreditCard(NodeWrapper node, BraintreeGateway gateway)
        {
            if (node == null)
            {
                return;
            }

            Bin                    = node.GetString("bin");
            CardholderName         = node.GetString("cardholder-name");
            CardType               = (CreditCardCardType)CollectionUtil.Find(CreditCardCardType.ALL, node.GetString("card-type"), CreditCardCardType.UNRECOGNIZED);
            CustomerId             = node.GetString("customer-id");
            IsDefault              = node.GetBoolean("default");
            IsVenmoSdk             = node.GetBoolean("venmo-sdk");
            ExpirationMonth        = node.GetString("expiration-month");
            ExpirationYear         = node.GetString("expiration-year");
            IsExpired              = node.GetBoolean("expired");
            CustomerLocation       = (CreditCardCustomerLocation)CollectionUtil.Find(CreditCardCustomerLocation.ALL, node.GetString("customer-location"), CreditCardCustomerLocation.UNRECOGNIZED);
            LastFour               = node.GetString("last-4");
            UniqueNumberIdentifier = node.GetString("unique-number-identifier");
            Token                  = node.GetString("token");
            CreatedAt              = node.GetDateTime("created-at");
            UpdatedAt              = node.GetDateTime("updated-at");
            BillingAddress         = new Address(node.GetNode("billing-address"));
            Prepaid                = (CreditCardPrepaid)CollectionUtil.Find(CreditCardPrepaid.ALL, node.GetString("prepaid"), CreditCardPrepaid.UNKNOWN);
            Payroll                = (CreditCardPayroll)CollectionUtil.Find(CreditCardPayroll.ALL, node.GetString("payroll"), CreditCardPayroll.UNKNOWN);
            DurbinRegulated        = (CreditCardDurbinRegulated)CollectionUtil.Find(CreditCardDurbinRegulated.ALL, node.GetString("durbin-regulated"), CreditCardDurbinRegulated.UNKNOWN);
            Debit                  = (CreditCardDebit)CollectionUtil.Find(CreditCardDebit.ALL, node.GetString("debit"), CreditCardDebit.UNKNOWN);
            Commercial             = (CreditCardCommercial)CollectionUtil.Find(CreditCardCommercial.ALL, node.GetString("commercial"), CreditCardCommercial.UNKNOWN);
            Healthcare             = (CreditCardHealthcare)CollectionUtil.Find(CreditCardHealthcare.ALL, node.GetString("healthcare"), CreditCardHealthcare.UNKNOWN);
            _CountryOfIssuance     = node.GetString("country-of-issuance");
            _IssuingBank           = node.GetString("issuing-bank");
            ImageUrl               = node.GetString("image-url");

            var subscriptionXmlNodes = node.GetList("subscriptions/subscription");

            Subscriptions = new Subscription[subscriptionXmlNodes.Count];
            for (int i = 0; i < subscriptionXmlNodes.Count; i++)
            {
                Subscriptions[i] = new Subscription(subscriptionXmlNodes[i], gateway);
            }

            var verificationNodes = node.GetList("verifications/verification");

            Verification = FindLatestVerification(verificationNodes, gateway);
        }
        public WebhookNotification(NodeWrapper node, BraintreeGateway gateway)
        {
            Timestamp = node.GetDateTime("timestamp");
            Kind = (WebhookKind)CollectionUtil.Find(WebhookKind.ALL, node.GetString("kind"), WebhookKind.UNRECOGNIZED);

            NodeWrapper WrapperNode = node.GetNode("subject");

            if (WrapperNode.GetNode("api-error-response") != null) {
                WrapperNode = WrapperNode.GetNode("api-error-response");
            }

            if (WrapperNode.GetNode("subscription") != null) {
                Subscription = new Subscription(WrapperNode.GetNode("subscription"), gateway);
            }

            if (WrapperNode.GetNode("merchant-account") != null) {
                MerchantAccount = new MerchantAccount(WrapperNode.GetNode("merchant-account"));
            }

            if (WrapperNode.GetNode("dispute") != null) {
                Dispute = new Dispute(WrapperNode.GetNode("dispute"));
            }

            if (WrapperNode.GetNode("transaction") != null) {
                Transaction = new Transaction(WrapperNode.GetNode("transaction"), gateway);
            }

            if (WrapperNode.GetNode("disbursement") != null) {
                Disbursement = new Disbursement(WrapperNode.GetNode("disbursement"), gateway);
            }

            if (WrapperNode.GetNode("partner-merchant") != null) {
                PartnerMerchant = new PartnerMerchant(WrapperNode.GetNode("partner-merchant"));
            }

            if (WrapperNode.GetNode("errors") != null) {
                Errors = new ValidationErrors(WrapperNode.GetNode("errors"));
            }

            if (WrapperNode.GetNode("message") != null) {
                Message = WrapperNode.GetString("message");
            }
        }
Esempio n. 27
0
        // GET: Checkout
        public ActionResult Index()
        {
            CheckoutDetails details = new CheckoutDetails();
            Guid            cartId  = Guid.Parse(Request.Cookies["cartId"].Value);

            details.CurrentCart = db.Carts.Find(cartId);

            details.Addresses = new Braintree.Address[0];

            if (User.Identity.IsAuthenticated)
            {
                string merchantId  = System.Configuration.ConfigurationManager.AppSettings["Braintree.MerchantId"];
                string environment = System.Configuration.ConfigurationManager.AppSettings["Braintree.Environment"];
                string publicKey   = System.Configuration.ConfigurationManager.AppSettings["Braintree.PublicKey"];
                string privateKey  = System.Configuration.ConfigurationManager.AppSettings["Braintree.PrivateKey"];
                Braintree.BraintreeGateway gateway = new Braintree.BraintreeGateway(environment, merchantId, publicKey, privateKey);

                var customerGateway = gateway.Customer;

                Braintree.CustomerSearchRequest query = new Braintree.CustomerSearchRequest();
                query.Email.Is(User.Identity.Name);
                var matchedCustomers        = customerGateway.Search(query);
                Braintree.Customer customer = null;
                if (matchedCustomers.Ids.Count == 0)
                {
                    Braintree.CustomerRequest newCustomer = new Braintree.CustomerRequest();
                    newCustomer.Email = User.Identity.Name;

                    var result = customerGateway.Create(newCustomer);
                    customer = result.Target;
                }
                else
                {
                    customer = matchedCustomers.FirstItem;
                }

                details.Addresses = customer.Addresses;
            }

            return(View(details));
        }
        protected internal VenmoAccount(NodeWrapper node, BraintreeGateway gateway)
        {
            Token = node.GetString("token");
            Username = node.GetString("username");
            VenmoUserId = node.GetString("venmo-user-id");
            SourceDescription = node.GetString("source-description");
            ImageUrl = node.GetString("image-url");

            IsDefault = node.GetBoolean("default");
            CustomerId = node.GetString("customer-id");

            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var subscriptionXmlNodes = node.GetList("subscriptions/subscription");
            Subscriptions = new Subscription[subscriptionXmlNodes.Count];
            for (int i = 0; i < subscriptionXmlNodes.Count; i++)
            {
                Subscriptions[i] = new Subscription(subscriptionXmlNodes[i], gateway);
            }
        }
Esempio n. 29
0
        protected internal ApplePayCard(NodeWrapper node, BraintreeGateway gateway)
        {
            CardType = node.GetString("card-type");
            Last4 = node.GetString("last-4");
            ExpirationMonth = node.GetString("expiration-month");
            ExpirationYear = node.GetString("expiration-year");
            Token = node.GetString("token");
            PaymentInstrumentName = node.GetString("payment-instrument-name");
            IsDefault = node.GetBoolean("default");
            ImageUrl = node.GetString("image-url");

            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var subscriptionXmlNodes = node.GetList("subscriptions/subscription");
            Subscriptions = new Subscription[subscriptionXmlNodes.Count];
            for (int i = 0; i < subscriptionXmlNodes.Count; i++)
            {
                Subscriptions[i] = new Subscription(subscriptionXmlNodes[i], gateway);
            }
        }
Esempio n. 30
0
        protected internal ApplePayCard(NodeWrapper node, BraintreeGateway gateway)
        {
            CardType              = node.GetString("card-type");
            Last4                 = node.GetString("last-4");
            ExpirationMonth       = node.GetString("expiration-month");
            ExpirationYear        = node.GetString("expiration-year");
            Token                 = node.GetString("token");
            PaymentInstrumentName = node.GetString("payment-instrument-name");
            IsDefault             = node.GetBoolean("default");
            ImageUrl              = node.GetString("image-url");

            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var subscriptionXmlNodes = node.GetList("subscriptions/subscription");

            Subscriptions = new Subscription[subscriptionXmlNodes.Count];
            for (int i = 0; i < subscriptionXmlNodes.Count; i++)
            {
                Subscriptions[i] = new Subscription(subscriptionXmlNodes[i], gateway);
            }
        }
Esempio n. 31
0
        public void Setup()
        {
            gateway = new BraintreeGateway
            {
                Environment = Environment.DEVELOPMENT,
                MerchantId = "integration_merchant_id",
                PublicKey = "integration_public_key",
                PrivateKey = "integration_private_key"
            };

            CustomerRequest request = new CustomerRequest
            {
                CreditCard = new CreditCardRequest
                {
                    CardholderName = "Fred Jones",
                    Number = "5105105105105100",
                    ExpirationDate = "05/12"
                }
            };

            customer = gateway.Customer.Create(request).Target;
            creditCard = customer.CreditCards[0];
        }
Esempio n. 32
0
        protected void Page_Load(object sender, EventArgs e) {
            //handle form-submission which includes paymethod nonce
            if(Request.Form["payment_method_nonce"] != null) {
                Submission(Request.Form["payment_method_nonce"]);
                return;
            }

            using(var ctx = new Data.FitathonDataEntities()) {
                var user = Common.GetUserFromEmail(ctx, Context.User.Identity.Name);
                var sponsor = user.sponsors.SingleOrDefault();
                var evt = sponsor.participant.fitevent;
                
                var gateway = new Braintree.BraintreeGateway {
                    Environment = Braintree.Environment.SANDBOX,
                    MerchantId = evt.braintreeClientID,  
                    PublicKey = evt.braintreePublicKey,
                    PrivateKey = evt.braintreePrivateKey
                };

                var btToken = gateway.ClientToken.generate();
                litBTClientToken.Text = string.Format("<script type='text/javascript'>var clientToken = '{0}';</script>", btToken);
            }
        }
        protected internal AmexExpressCheckoutCard(NodeWrapper node, BraintreeGateway gateway)
        {
            Token = node.GetString("token");
            CardType = node.GetString("card-type");
            Bin = node.GetString("bin");
            ExpirationMonth = node.GetString("expiration-month");
            ExpirationYear = node.GetString("expiration-year");
            CardMemberNumber = node.GetString("card-member-number");
            CardMemberExpiryDate = node.GetString("card-member-expiry-date");
            SourceDescription = node.GetString("source-description");
            IsDefault = node.GetBoolean("default");
            ImageUrl = node.GetString("image-url");
            CustomerId = node.GetString("customer-id");

            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var subscriptionXmlNodes = node.GetList("subscriptions/subscription");
            Subscriptions = new Subscription[subscriptionXmlNodes.Count];
            for (int i = 0; i < subscriptionXmlNodes.Count; i++)
            {
                Subscriptions[i] = new Subscription(subscriptionXmlNodes[i], gateway);
            }
        }
Esempio n. 34
0
        private T newInstanceFromResponse(NodeWrapper node, BraintreeGateway gateway)
        {
            if (typeof(T) == typeof(Address))
            {
                return(new Address(node) as T);
            }
            else if (typeof(T) == typeof(ApplePayCard))
            {
                return(new ApplePayCard(node, gateway) as T);
            }
            else if (typeof(T) == typeof(AndroidPayCard))
            {
                return(new AndroidPayCard(node, gateway) as T);
            }
            else if (typeof(T) == typeof(CreditCard))
            {
                return(new CreditCard(node, gateway) as T);
            }
            else if (typeof(T) == typeof(CoinbaseAccount))
            {
                return(new CoinbaseAccount(node, gateway) as T);
            }
            else if (typeof(T) == typeof(Customer))
            {
                return(new Customer(node, gateway) as T);
            }
            else if (typeof(T) == typeof(Transaction))
            {
                return(new Transaction(node, gateway) as T);
            }
            else if (typeof(T) == typeof(Subscription))
            {
                return(new Subscription(node, gateway) as T);
            }
            else if (typeof(T) == typeof(SettlementBatchSummary))
            {
                return(new SettlementBatchSummary(node) as T);
            }
            else if (typeof(T) == typeof(MerchantAccount))
            {
                return(new MerchantAccount(node) as T);
            }
            else if (typeof(T) == typeof(PayPalAccount))
            {
                return(new PayPalAccount(node, gateway) as T);
            }
            else if (typeof(T) == typeof(UnknownPaymentMethod))
            {
                return(new UnknownPaymentMethod(node) as T);
            }
            else if (typeof(T) == typeof(PaymentMethodNonce))
            {
                return(new PaymentMethodNonce(node, gateway) as T);
            }
            else if (typeof(T) == typeof(OAuthCredentials))
            {
                return(new OAuthCredentials(node) as T);
            }
            else if (typeof(T) == typeof(Merchant))
            {
                return(new Merchant(node) as T);
            }

            throw new Exception("Unknown T: " + typeof(T).ToString());
        }
Esempio n. 35
0
 public UsBankAccountGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service      = gateway.Service;
 }
 protected internal WebhookTestingGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     service = new BraintreeService(gateway.Configuration);
 }
 protected internal SettlementBatchSummaryGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service      = new BraintreeService(gateway.Configuration);
 }
 public ThreeDSecureGateway(BraintreeGateway gateway)
 {
     this.gateway = gateway;
     service      = new BraintreeService(gateway.Configuration);
 }
Esempio n. 39
0
 public OAuthGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasClientCredentials();
     this.gateway = gateway;
     service = new BraintreeService(gateway.Configuration);
 }
 protected internal ClientTokenGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     Service = new BraintreeService(gateway.Configuration);
 }
 protected internal CreditCardVerificationGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service = new BraintreeService(gateway.Configuration);
 }
 protected internal SettlementBatchSummaryGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service = new BraintreeService(gateway.Configuration);
 }
Esempio n. 43
0
        protected internal Customer(NodeWrapper node, BraintreeGateway gateway)
        {
            if (node == null) return;

            Id = node.GetString("id");
            FirstName = node.GetString("first-name");
            LastName = node.GetString("last-name");
            Company = node.GetString("company");
            Email = node.GetString("email");
            Phone = node.GetString("phone");
            Fax = node.GetString("fax");
            Website = node.GetString("website");
            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var creditCardXmlNodes = node.GetList("credit-cards/credit-card");
            CreditCards = new CreditCard[creditCardXmlNodes.Count];
            for (int i = 0; i < creditCardXmlNodes.Count; i++)
            {
                CreditCards[i] = new CreditCard(creditCardXmlNodes[i], gateway);
            }

            var paypalXmlNodes = node.GetList("paypal-accounts/paypal-account");
            PayPalAccounts = new PayPalAccount[paypalXmlNodes.Count];
            for (int i = 0; i < paypalXmlNodes.Count; i++)
            {
                PayPalAccounts[i] = new PayPalAccount(paypalXmlNodes[i], gateway);
            }

            var applePayXmlNodes = node.GetList("apple-pay-cards/apple-pay-card");
            ApplePayCards = new ApplePayCard[applePayXmlNodes.Count];
            for (int i = 0; i < applePayXmlNodes.Count; i++)
            {
                ApplePayCards[i] = new ApplePayCard(applePayXmlNodes[i], gateway);
            }

            var androidPayCardXmlNodes = node.GetList("android-pay-cards/android-pay-card");
            AndroidPayCards = new AndroidPayCard[androidPayCardXmlNodes.Count];
            for (int i = 0; i < androidPayCardXmlNodes.Count; i++)
            {
                AndroidPayCards[i] = new AndroidPayCard(androidPayCardXmlNodes[i], gateway);
            }

            var amexExpressCheckoutCardXmlNodes = node.GetList("amex-express-checkout-cards/amex-express-checkout-card");
            AmexExpressCheckoutCards = new AmexExpressCheckoutCard[amexExpressCheckoutCardXmlNodes.Count];
            for (int i = 0; i < amexExpressCheckoutCardXmlNodes.Count; i++)
            {
                AmexExpressCheckoutCards[i] = new AmexExpressCheckoutCard(amexExpressCheckoutCardXmlNodes[i], gateway);
            }

            var coinbaseXmlNodes = node.GetList("coinbase-accounts/coinbase-account");
            CoinbaseAccounts = new CoinbaseAccount[coinbaseXmlNodes.Count];
            for (int i = 0; i < coinbaseXmlNodes.Count; i++)
            {
                CoinbaseAccounts[i] = new CoinbaseAccount(coinbaseXmlNodes[i], gateway);
            }

            var venmoAccountXmlNodes = node.GetList("venmo-accounts/venmo-account");
            VenmoAccounts = new VenmoAccount[venmoAccountXmlNodes.Count];
            for (int i = 0; i < venmoAccountXmlNodes.Count; i++)
            {
                VenmoAccounts[i] = new VenmoAccount(venmoAccountXmlNodes[i], gateway);
            }

            PaymentMethods = new PaymentMethod[
                CreditCards.Length
                + PayPalAccounts.Length
                + ApplePayCards.Length
                + CoinbaseAccounts.Length
                + AndroidPayCards.Length
                + AmexExpressCheckoutCards.Length
                + VenmoAccounts.Length
            ];

            CreditCards.CopyTo(PaymentMethods, 0);
            PayPalAccounts.CopyTo(PaymentMethods, CreditCards.Length);
            ApplePayCards.CopyTo(PaymentMethods, CreditCards.Length + PayPalAccounts.Length);
            CoinbaseAccounts.CopyTo(PaymentMethods, CreditCards.Length + PayPalAccounts.Length + ApplePayCards.Length);
            AndroidPayCards.CopyTo(PaymentMethods, CreditCards.Length + PayPalAccounts.Length + ApplePayCards.Length + CoinbaseAccounts.Length);
            AmexExpressCheckoutCards.CopyTo(PaymentMethods, CreditCards.Length + PayPalAccounts.Length + ApplePayCards.Length + CoinbaseAccounts.Length + AndroidPayCards.Length);
            VenmoAccounts.CopyTo(PaymentMethods, CreditCards.Length + PayPalAccounts.Length + ApplePayCards.Length + CoinbaseAccounts.Length + AndroidPayCards.Length + AmexExpressCheckoutCards.Length);

            var addressXmlNodes = node.GetList("addresses/address");
            Addresses = new Address[addressXmlNodes.Count];
            for (int i = 0; i < addressXmlNodes.Count; i++)
            {
                Addresses[i] = new Address(addressXmlNodes[i]);
            }

            CustomFields = node.GetDictionary("custom-fields");
        }
Esempio n. 44
0
        public void Search_OnGatewayRejectedAt()
        {
            BraintreeGateway processingRulesGateway = new BraintreeGateway
            {
                Environment = Environment.DEVELOPMENT,
                MerchantId = "processing_rules_merchant_id",
                PublicKey = "processing_rules_public_key",
                PrivateKey = "processing_rules_private_key"
            };

            TransactionRequest request = new TransactionRequest
            {
                Amount = SandboxValues.TransactionAmount.AUTHORIZE,
                CreditCard = new TransactionCreditCardRequest
                {
                    Number = SandboxValues.CreditCardNumber.VISA,
                    ExpirationDate = "05/2010",
                    CVV = "200"
                }
            };

            Transaction transaction = processingRulesGateway.Transaction.Sale(request).Transaction;

            DateTime threeDaysEarlier = DateTime.Now.AddDays(-3);
            DateTime oneDayEarlier = DateTime.Now.AddDays(-1);
            DateTime oneDayLater = DateTime.Now.AddDays(1);

            TransactionSearchRequest searchRequest = new TransactionSearchRequest().
                Id.Is(transaction.Id).
                GatewayRejectedAt.Between(oneDayEarlier, oneDayLater);

            Assert.AreEqual(1, processingRulesGateway.Transaction.Search(searchRequest).MaximumCount);

            searchRequest = new TransactionSearchRequest().
                Id.Is(transaction.Id).
                GatewayRejectedAt.GreaterThanOrEqualTo(oneDayEarlier);

            Assert.AreEqual(1, processingRulesGateway.Transaction.Search(searchRequest).MaximumCount);

            searchRequest = new TransactionSearchRequest().
                Id.Is(transaction.Id).
                GatewayRejectedAt.LessThanOrEqualTo(oneDayLater);

            Assert.AreEqual(1, processingRulesGateway.Transaction.Search(searchRequest).MaximumCount);

            searchRequest = new TransactionSearchRequest().
                Id.Is(transaction.Id).
                GatewayRejectedAt.Between(threeDaysEarlier, oneDayEarlier);

            Assert.AreEqual(0, processingRulesGateway.Transaction.Search(searchRequest).MaximumCount);
        }
 public PayPalAccountGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service      = new BraintreeService(gateway.Configuration);
 }
 protected internal MerchantAccountGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service      = new BraintreeService(gateway.Configuration);
 }
Esempio n. 47
0
 protected internal TestTransactionGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service      = new BraintreeService(gateway.Configuration);
 }
 protected internal TransparentRedirectGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service = new BraintreeService(gateway.Configuration);
 }
Esempio n. 49
0
        protected internal Customer(NodeWrapper node, BraintreeGateway gateway)
        {
            if (node == null)
            {
                return;
            }

            Id        = node.GetString("id");
            FirstName = node.GetString("first-name");
            LastName  = node.GetString("last-name");
            Company   = node.GetString("company");
            Email     = node.GetString("email");
            Phone     = node.GetString("phone");
            Fax       = node.GetString("fax");
            Website   = node.GetString("website");
            CreatedAt = node.GetDateTime("created-at");
            UpdatedAt = node.GetDateTime("updated-at");

            var creditCardXmlNodes = node.GetList("credit-cards/credit-card");

            CreditCards = new CreditCard[creditCardXmlNodes.Count];
            for (int i = 0; i < creditCardXmlNodes.Count; i++)
            {
                CreditCards[i] = new CreditCard(creditCardXmlNodes[i], gateway);
            }

            var paypalXmlNodes = node.GetList("paypal-accounts/paypal-account");

            PayPalAccounts = new PayPalAccount[paypalXmlNodes.Count];
            for (int i = 0; i < paypalXmlNodes.Count; i++)
            {
                PayPalAccounts[i] = new PayPalAccount(paypalXmlNodes[i], gateway);
            }

            var applePayXmlNodes = node.GetList("apple-pay-cards/apple-pay-card");

            ApplePayCards = new ApplePayCard[applePayXmlNodes.Count];
            for (int i = 0; i < applePayXmlNodes.Count; i++)
            {
                ApplePayCards[i] = new ApplePayCard(applePayXmlNodes[i], gateway);
            }

            var androidPayCardXmlNodes = node.GetList("android-pay-cards/android-pay-card");

            AndroidPayCards = new AndroidPayCard[androidPayCardXmlNodes.Count];
            for (int i = 0; i < androidPayCardXmlNodes.Count; i++)
            {
                AndroidPayCards[i] = new AndroidPayCard(androidPayCardXmlNodes[i], gateway);
            }

            var coinbaseXmlNodes = node.GetList("coinbase-accounts/coinbase-account");

            CoinbaseAccounts = new CoinbaseAccount[coinbaseXmlNodes.Count];
            for (int i = 0; i < coinbaseXmlNodes.Count; i++)
            {
                CoinbaseAccounts[i] = new CoinbaseAccount(coinbaseXmlNodes[i], gateway);
            }

            PaymentMethods = new PaymentMethod[CreditCards.Length + PayPalAccounts.Length + ApplePayCards.Length + CoinbaseAccounts.Length + AndroidPayCards.Length];
            CreditCards.CopyTo(PaymentMethods, 0);
            PayPalAccounts.CopyTo(PaymentMethods, CreditCards.Length);
            ApplePayCards.CopyTo(PaymentMethods, CreditCards.Length + PayPalAccounts.Length);
            CoinbaseAccounts.CopyTo(PaymentMethods, CreditCards.Length + PayPalAccounts.Length + ApplePayCards.Length);
            AndroidPayCards.CopyTo(PaymentMethods, CreditCards.Length + PayPalAccounts.Length + ApplePayCards.Length + CoinbaseAccounts.Length);

            var addressXmlNodes = node.GetList("addresses/address");

            Addresses = new Address[addressXmlNodes.Count];
            for (int i = 0; i < addressXmlNodes.Count; i++)
            {
                Addresses[i] = new Address(addressXmlNodes[i]);
            }

            CustomFields = node.GetDictionary("custom-fields");
        }
Esempio n. 50
0
 public OAuthGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasClientCredentials();
     this.gateway = gateway;
     service      = new BraintreeService(gateway.Configuration);
 }
 protected internal UsBankAccountVerificationGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service      = gateway.Service;
 }
 public DiscountGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     service = new BraintreeService(gateway.Configuration);
 }
 public PaymentMethodGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     this.service = new BraintreeService(gateway.Configuration);
 }
Esempio n. 54
0
 protected internal CreditCardVerificationGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     service      = new BraintreeService(gateway.Configuration);
 }
Esempio n. 55
0
 public ThreeDSecureGateway(BraintreeGateway gateway)
 {
     this.gateway = gateway;
     service      = gateway.Service;
 }
 public DiscountGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     service = new BraintreeService(gateway.Configuration);
 }
 protected internal WebhookNotificationGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     this.service = gateway.Service;
 }
Esempio n. 58
0
 public PlanGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     service = gateway.Service;
 }
 protected internal ClientTokenGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     Service = new BraintreeService(gateway.Configuration);
 }
Esempio n. 60
0
 public PaymentMethodGateway(BraintreeGateway gateway)
 {
     gateway.Configuration.AssertHasAccessTokenOrKeys();
     this.gateway = gateway;
     this.service = new BraintreeService(gateway.Configuration);
 }