public async Task <IActionResult> RequestPayment([FromBody] PaypalPaymentRequest request) { try { request.Order.OrderId = request.OrderID; request.Order.PayerId = request.PayerID; var userId = await GetUserIdAsync(); var purchaseVM = await _dal.CreatePurchaseAsync(request.Order, userId); if (purchaseVM != null) { var purchaseConfirmed = new PurchaseConfirmedUpdateRequest { Purchase = purchaseVM, WasChargeAccepted = true }; return(Ok(purchaseConfirmed)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(BadRequest()); }
public IActionResult ExtendSubscriptionPaypal([FromBody] PaypalPaymentRequest paymentRequest) { Console.WriteLine(paymentRequest.paymentNonce); Braintree.TransactionRequest request = new Braintree.TransactionRequest() { PaymentMethodNonce = paymentRequest.paymentNonce, Amount = (decimal)(paymentRequest.amount) }; Braintree.Result <Braintree.Transaction> result = gateway.Transaction.Sale(request); if (result.IsSuccess()) { TransactionDto transaction = new TransactionDto(); transaction.Amount = (decimal)(paymentRequest.amount); transaction.Status = "succeeded"; transaction.CustomerId = 1; transaction.PaymentGatewayId = 2; transaction.PricingPackageId = paymentRequest.packageId; transaction.DateCreated = DateTime.Now; _transactionManipulation.SaveTransaction(transaction); SubscriptionDto subscription = _subscriptionManipulation.GetCustomerSubscription(1); subscription.SubscriptionExpirationDate = subscription.SubscriptionExpirationDate.AddMonths(1); _subscriptionManipulation.UpdateSubscription(subscription); return(Ok("Uspjesan placanje")); } else { return(BadRequest("Neuspjesna transakcija!")); } }