Ejemplo n.º 1
0
        /// <summary>
        /// Performs a Braintree sales transaction.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="paymentMethodNonce">
        /// The payment method nonce.
        /// </param>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <param name="billingAddress">
        /// The billing address.
        /// </param>
        /// <param name="shippingAddress">
        /// The shipping address.
        /// </param>
        /// <param name="option">
        /// The option.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentResult"/>.
        /// </returns>
        public Result <Transaction> Sale(IInvoice invoice, string paymentMethodNonce, ICustomer customer, IAddress billingAddress, IAddress shippingAddress, TransactionOption option = TransactionOption.SubmitForSettlement)
        {
            var request = RequestFactory.CreateTransactionRequest(invoice, paymentMethodNonce, customer, option);

            if (billingAddress != null)
            {
                request.BillingAddress = RequestFactory.CreateAddressRequest(billingAddress);
            }
            if (shippingAddress != null)
            {
                request.ShippingAddress = RequestFactory.CreateAddressRequest(shippingAddress);
            }

            var attempt = TryGetApiResult(() => BraintreeGateway.Transaction.Sale(request));

            return(attempt.Success ? attempt.Result : null);
        }