示例#1
0
        public ActionResult HandleDonationForm(DonationFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }


            string key = Guid.NewGuid().ToString();

            model.Amount = model.Amount * 100;
            Money money = new Money(model.Amount, Money.CurrencyEnum.USD);

            try
            {
                var            customerId     = CreateCustomer(model);
                ChargeRequest  body           = new ChargeRequest(key, money, model.Nonce, null, null, null, null, customerId);
                TransactionApi transactionApi = new TransactionApi();
                var            response       = transactionApi.Charge(squareAuthorization, squareLocationId, body);
                var            confirm        = response;
            }
            catch (Exception)
            {
                TempData["DonationError"] = true;
                return(RedirectToCurrentUmbracoPage());
            }

            TempData["DonationSuccessful"] = true;
            return(RedirectToCurrentUmbracoPage());
        }
示例#2
0
        public static string Charge(string nonce)
        {
            // Every payment you process with the SDK must have a unique idempotency key.
            // If you're unsure whether a particular payment succeeded, you can reattempt
            // it with the same idempotency key without worrying about double charging
            // the buyer.
            string uuid = NewIdempotencyKey();

            // Monetary amounts are specified in the smallest unit of the applicable currency.
            // This amount is in cents. It's also hard-coded for $1.00,
            // which isn't very useful.
            Money amount = new Money(100, Money.CurrencyEnum.USD);

            ChargeRequest body = new ChargeRequest(AmountMoney: amount, IdempotencyKey: uuid, CardNonce: nonce);

            try
            {
                var response = _transactionApi.Charge(_accessToken, _locationId, body);
                return("Transaction complete\n" + response.ToJson());
            }
            catch (ApiException e)
            {
                return(e.Message);
            }
        }
示例#3
0
        public JsonResult Charge(string nonce, int orderId)
        {
            // Every payment you process with the SDK must have a unique idempotency key.
            // If you're unsure whether a particular payment succeeded, you can reattempt
            // it with the same idempotency key without worrying about double charging
            // the buyer.

            Order  order = context.Orders.Find(orderId);
            string uuid;

            if (order == null)
            {
                return(Json(null));
            }
            else
            {
                uuid = string.IsNullOrWhiteSpace(order.PaymentRef) ?
                       NewIdempotencyKey() :
                       order.PaymentRef;
            }

            double totalPayment = order.TotalAmount + order.TaxAmount + order.DeliveryCharge;

            totalPayment *= 100;
            // Monetary amounts are specified in the smallest unit of the applicable currency.
            // This amount is in cents. It's also hard-coded for $1.00,
            // which isn't very useful.
            Money amount = NewMoney((int)totalPayment, "USD");

            ChargeRequest body     = new ChargeRequest(AmountMoney: amount, IdempotencyKey: uuid, CardNonce: nonce);
            var           response = _transactionApi.Charge(_accessToken, _locationId, body);

            if (response.Errors == null)
            {
                order.PaymentRef = uuid;
                context.SaveChanges();
                return(Json(uuid));
            }

            return(Json(null));
        }