A transaction returned by the Braintree Gateway
        public Payment CreatePaymentTransaction(Braintree.Transaction transaction)
        {
            var payment = new Payment()
            {
                CardholderName             = transaction.CreditCard.CardholderName,
                CardLastFour               = transaction.CreditCard.LastFour,
                CardType                   = Convert.ToString(transaction.CreditCard.CardType),
                ExpirationMonth            = transaction.CreditCard.ExpirationMonth,
                ExpirationYear             = transaction.CreditCard.ExpirationYear,
                PostalCode                 = transaction.CreditCard.BillingAddress.PostalCode,
                Amount                     = Convert.ToDouble(QuoteHelper.NormalizeValue(transaction.Amount)),
                TransactionId              = transaction.Id,
                MerchantAccountId          = transaction.MerchantAccountId,
                ProcessorAuthorizationCode = transaction.ProcessorAuthorizationCode
            };

            return(payment);
        }
        public TransactionResult Pay(
            string paymentMethodNonce,
            decimal amount,
            Dictionary <string, string> customFields)
        {
            var config = _orchardServices.WorkContext
                         .CurrentSite.As <BraintreeSiteSettingsPart>();
            string            merchant = config?.MerchantAccountId;
            TransactionResult result   = new TransactionResult();
            var request = new Bt.TransactionRequest {
                Amount             = amount,
                PaymentMethodNonce = paymentMethodNonce,
                MerchantAccountId  = merchant
            };

            if (customFields != null)
            {
                request.CustomFields = customFields;
            }
            var gateway = GetGateway();

            Bt.Result <Bt.Transaction> payResult = gateway.Transaction.Sale(request);
            Bt.Transaction             tran      = null;
            result.Success = payResult.IsSuccess();
            if (payResult.Target != null)
            {
                // caso success == true
                tran = payResult.Target;
            }
            else if (payResult.Transaction != null)
            {
                // caso success == false
                tran = payResult.Transaction;
            }
            if (tran != null)
            {
                result.Amount            = tran.Amount.Value;
                result.AuthorizationCode = tran.ProcessorAuthorizationCode;
                if (tran.BillingAddress != null)
                {
                    result.BillingAddress = string.Format("{0} - {1} {2} - {3} {4} - {5} {6} {7} - {8}",
                                                          tran.BillingAddress.Company,
                                                          tran.BillingAddress.FirstName,
                                                          tran.BillingAddress.LastName,
                                                          tran.BillingAddress.StreetAddress,
                                                          tran.BillingAddress.ExtendedAddress,
                                                          tran.BillingAddress.PostalCode,
                                                          tran.BillingAddress.Locality,
                                                          tran.BillingAddress.Region,
                                                          tran.BillingAddress.CountryName);
                }
                result.CurrencyIsoCode = tran.CurrencyIsoCode;
                if (tran.Customer != null)
                {
                    result.Customer = string.Format("{0} {1}, {2}, ({3})",
                                                    tran.Customer.FirstName,
                                                    tran.Customer.LastName,
                                                    tran.Customer.Company,
                                                    tran.Customer.Email);
                }
                result.MerchantAccountId   = tran.MerchantAccountId;
                result.OrderId             = tran.OrderId;
                result.PurchaseOrderNumber = tran.PurchaseOrderNumber;
                result.ResponseCode        = tran.ProcessorResponseCode;
                result.ResponseText        = tran.ProcessorResponseText;
                result.Status        = tran.Status.ToString();
                result.TransactionId = tran.Id;
                result.Type          = tran.Type.ToString();
            }
            result.Details = JsonConvert.SerializeObject(payResult);
            return(result);
        }
        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");
            }
        }
Exemplo n.º 4
0
        public ActionResult Create()
        {
            var     gateway     = config.GetGateway();
            Decimal amount      = 0;
            int     total       = 0;
            int     shippingFee = 0;
            int     offerId     = 0;
            string  buyerId     = "";
            string  travlerId   = "";

            try
            {
                amount = Convert.ToDecimal(Request["amount"]);
            }
            catch (FormatException)
            {
                TempData["Flash"] = "Error: 81503: Amount is an invalid format.";
                //   return RedirectToAction("New");
            }
            total       = int.Parse(Request["total"].Replace(",", "").Replace("VND", ""));
            shippingFee = int.Parse(Request["shippingFee"]);
            offerId     = Convert.ToUInt16(Request["OfferId"]);
            buyerId     = Request["Id"].ToString();
            travlerId   = Request["TravelerId"].ToString();
            var nonce   = Request["payment_method_nonce"];
            var request = new TransactionRequest
            {
                Amount             = amount,
                PaymentMethodNonce = nonce,
                Options            = new TransactionOptionsRequest
                {
                    SubmitForSettlement = true
                }
            };

            Result <Braintree.Transaction> result = gateway.Transaction.Sale(request);

            if (result.IsSuccess())
            {
                Braintree.Transaction transaction = result.Target;
                //   return RedirectToAction("Show", new { id = transaction.Id });
                string respone = Json(new { success = true, transactionAmount = transaction.Amount, transactionId = transaction.Id }).Data.ToString();
                ViewBag.respone = respone;
                Order order = new Order()
                {
                    IsActive     = true,
                    IsDelete     = false,
                    BuyerId      = buyerId,
                    TravellerId  = travlerId,
                    Total        = total,
                    ShippingFee  = shippingFee,
                    DateCreated  = DateTime.UtcNow.AddHours(7),
                    DeliveryDate = DateTime.UtcNow.AddHours(7),
                    DateUpdated  = DateTime.UtcNow.AddHours(7),
                    OfferId      = 1,
                };

                orderService.CreateOrder(order);
                orderService.SaveOrder();

                /*     Model.Models.Transaction tra = new Model.Models.Transaction()
                 *   {
                 *       DateCreated = DateTime.UtcNow.AddHours(7),
                 *       IsActive = true,
                 *       IsDelete = false,
                 *       IsSuccess = 1,
                 *       OrderId = order.Id,
                 *
                 *   }*/
                return(View());
            }
            return(View("ResponeTransaction.cshtml"));
        }
        public WebhookNotification(NodeWrapper node, IBraintreeGateway gateway)
        {
            Timestamp = node.GetDateTime("timestamp");
            Kind      = (WebhookKind)CollectionUtil.Find(WebhookKind.ALL, node.GetString("kind"), WebhookKind.UNRECOGNIZED);

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

            if (node.GetString("source-merchant-id") != null)
            {
                SourceMerchantId = node.GetString("source-merchant-id");
            }

            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("oauth-application-revocation") != null)
            {
                OAuthAccessRevocation = new OAuthAccessRevocation(WrapperNode.GetNode("oauth-application-revocation"));
            }

            if (WrapperNode.GetNode("connected-merchant-status-transitioned") != null)
            {
                ConnectedMerchantStatusTransitioned = new ConnectedMerchantStatusTransitioned(WrapperNode.GetNode("connected-merchant-status-transitioned"));
            }

            if (WrapperNode.GetNode("connected-merchant-paypal-status-changed") != null)
            {
                ConnectedMerchantPayPalStatusChanged = new ConnectedMerchantPayPalStatusChanged(WrapperNode.GetNode("connected-merchant-paypal-status-changed"));
            }

            if (WrapperNode.GetNode("account-updater-daily-report") != null)
            {
                AccountUpdaterDailyReport = new AccountUpdaterDailyReport(WrapperNode.GetNode("account-updater-daily-report"));
            }

            // NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
            // DEPRECATED If you're looking to accept iDEAL as a payment method contact [email protected] for a solution.
            if (WrapperNode.GetNode("ideal-payment") != null)
            {
                IdealPayment = new IdealPayment(WrapperNode.GetNode("ideal-payment"));
            }

            if (WrapperNode.GetNode("granted-payment-instrument-update") != null)
            {
                GrantedPaymentInstrumentUpdate = new GrantedPaymentInstrumentUpdate(WrapperNode.GetNode("granted-payment-instrument-update"));
            }

            if (Kind == WebhookKind.GRANTED_PAYMENT_METHOD_REVOKED || Kind == WebhookKind.PAYMENT_METHOD_REVOKED_BY_CUSTOMER)
            {
                RevokedPaymentMethodMetadata = new RevokedPaymentMethodMetadata(WrapperNode, gateway);
            }

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

            if (WrapperNode.GetNode("message") != null)
            {
                Message = WrapperNode.GetString("message");
            }

            if (WrapperNode.GetNode("local-payment") != null)
            {
                LocalPaymentCompleted = new LocalPaymentCompleted(WrapperNode.GetNode("local-payment"), gateway);
            }
        }