Ejemplo n.º 1
0
        public async Task <IActionResult> FinPaypalCart([FromBody] PaymentTransactionDto payment)
        {
            if (payment.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var cartItems = await _repo.GetCartItems(payment.UserId);

            //var returnCart = _mapper.Map<IEnumerable<PayPalCart>>(cartItems);
            PaypalTransaction transaction = new PaypalTransaction();

            transaction.Intent       = payment.Info.Intent;
            transaction.OrderID      = payment.Info.OrderID;
            transaction.PayerID      = payment.Info.PayerID;
            transaction.PaymentID    = payment.Info.PaymentID;
            transaction.PaymentToken = payment.Info.PaymentToken;
            transaction.UserId       = payment.UserId;
            transaction.User         = await _repo.GetUser(payment.UserId);

            transaction.Items = _repo.GetItemsFormCart(payment.UserId);
            _repo.Add(transaction);

            foreach (Cart cart in cartItems)
            {
                var item = _repo.GetItem(cart.Item.Id);
                item.Result.Quantity = item.Result.Quantity - cart.Quantity;
                _repo.Delete(cart);
            }
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception("Failed to delete item from your cart.");
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            PaypalTransaction paypalTransaction = db.PaypalTransactions.Find(id);

            db.PaypalTransactions.Remove(paypalTransaction);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "Id,TrxId,JobId,TrxDate,DatePosted,Status,Remarks,Amount")] PaypalTransaction paypalTransaction)
 {
     if (ModelState.IsValid)
     {
         db.Entry(paypalTransaction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(paypalTransaction));
 }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "Id,TrxId,JobId,TrxDate,DatePosted,Status,Remarks,Amount")] PaypalTransaction paypalTransaction)
        {
            if (ModelState.IsValid)
            {
                db.PaypalTransactions.Add(paypalTransaction);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(paypalTransaction));
        }
Ejemplo n.º 5
0
        public List <PaypalTransaction> Test()
        {
            var p1 = new PaypalTransaction {
                OrderId = 10, PaidAmount = 500
            };

            _repository.Insert(p1);

            var x = _repository.Table.Where(t => t.PaidAmount > 10).ToList();

            return(x);
        }
Ejemplo n.º 6
0
        // GET: PaypalTransactions/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PaypalTransaction paypalTransaction = db.PaypalTransactions.Find(id);

            if (paypalTransaction == null)
            {
                return(HttpNotFound());
            }
            return(View(paypalTransaction));
        }
        public async Task <IActionResult> CreatePayment([FromBody] PaypalTransaction transaction)
        {
            if (string.IsNullOrEmpty(transaction.InternalReference))
            {
                return(NotFound("InternalReference is null or empty!"));
            }

            // Saving transaction.InternalReference to db here...
            var payment = await paypalService.CreatePaymentAsync(transaction);

            if (payment == null)
            {
                return(BadRequest("InternalReference is invalid"));
            }
            else
            {
                return(Ok(payment));
            }
        }