예제 #1
0
        public PaymentResource CreateLocalPayment(string merchantAccountId, LocalPayment localPayment)
        {
            ValidateParameters(merchantAccountId, localPayment);

            var clientConfiguration = clientTokenGateway.GetClientConfiguration(merchantAccountId);
            var localPaymentRequest = RequestFactory.CreateLocalPaymentRequest(localPayment, clientConfiguration);

            var response = webClient.Post <PaymentResourceResponse, LocalPaymentRequest>($"{clientConfiguration.ClientApiUrl}{paymentCreateEnpoint}", localPaymentRequest);

            return(response.PaymentResource);
        }
예제 #2
0
        private static void ValidateParameters(string merchantAccountId, LocalPayment localPayment)
        {
            if (string.IsNullOrWhiteSpace(merchantAccountId))
            {
                throw new ArgumentException("The merchant account id cannot be null or whitespace.", nameof(merchantAccountId));
            }

            if (localPayment == null)
            {
                throw new ArgumentNullException(nameof(localPayment), "The local payment cannot be null.");
            }
        }
        public static LocalPaymentRequest CreateLocalPaymentRequest(LocalPayment localPayment, BraintreeClientConfiguration clientConfiguration)
        {
            var returnUrl     = GenerateReturnUrl(localPayment.Fallback, clientConfiguration);
            var requestObject = new LocalPaymentRequest
            {
                FundingSource     = localPayment.PaymentType,
                Intent            = GatewayConstants.Intent,
                Amount            = localPayment.Amount,
                ReturnUrl         = returnUrl,
                CancelUrl         = localPayment.Fallback.Url.ToString(),
                CurrencyCode      = localPayment.CurrencyCode,
                CountryCode       = localPayment.Address.CountryCode,
                ExperienceProfile = new ExperienceProfileRequest
                {
                    NoShipping = !localPayment.AddressEntryRequired
                },
                AddressLine1            = localPayment.Address.AddressLine1,
                AddressLine2            = localPayment.Address.AddressLine2,
                Locality                = localPayment.Address.Locality,
                Region                  = localPayment.Address.Region,
                PostalCode              = localPayment.Address.PostalCode,
                FirstName               = localPayment.Customer?.FirstName,
                LastName                = localPayment.Customer?.LastName,
                Email                   = localPayment.Customer?.Email,
                Phone                   = localPayment.Customer?.Phone,
                BraintreeLibraryVersion = $"braintree/web/{GatewayConstants.ApiVersion}", // Are custom strings ok here?
                MetaData                = new MetaData()
                {
                    MerchantAppId   = "Test", // TODO: Make configurable.
                    Platform        = "web",  // Should this be something else?
                    SdkVersion      = GatewayConstants.ApiVersion,
                    Source          = "client",
                    Integration     = "custom",
                    IntegrationType = "custom",
                    SessionId       = Guid.NewGuid()
                },
                AuthorizationFingerprint = clientConfiguration.AuthorizationFingerprint
            };

            return(requestObject);
        }
예제 #4
0
        public async Task <PaymentResource> CreateLocalPaymentAsync(string merchantAccountId, LocalPayment localPayment)
        {
            ValidateParameters(merchantAccountId, localPayment);

            var clientConfiguration = await clientTokenGateway.GetClientConfigurationAsync(merchantAccountId)
                                      .ConfigureAwait(false);

            var localPaymentRequest = RequestFactory.CreateLocalPaymentRequest(localPayment, clientConfiguration);
            var response            = await httpClient.PostAsync <PaymentResourceResponse, LocalPaymentRequest>($"{clientConfiguration.ClientApiUrl}{paymentCreateEnpoint}", localPaymentRequest)
                                      .ConfigureAwait(false);

            return(response.PaymentResource);
        }
        /// <summary>
        /// Creates a local payment transaction using the Braintree payment gateway.
        /// </summary>
        /// <param name="clientTokenGateway">The Braintree clinet token gateway.</param>
        /// <param name="merchantAccountId">The merchant account to use for the paymnt.</param>
        /// <param name="localPayment">Descriptor of the payment to be created on the brain tree server.</param>
        /// <returns>A payment resource that describes the newly created payment</returns>
        public static PaymentResource CreateLocalPayment(this IClientTokenGateway clientTokenGateway, string merchantAccountId, LocalPayment localPayment)
        {
            var service = new BraintreeLocalPaymentService(clientTokenGateway, httpClient, webClient);

            return(service.CreateLocalPayment(merchantAccountId, localPayment));
        }