public IActionResult GetCardByCustomer(string cusID) { APIResponseData responseData = new APIResponseData(); responseData.StatusCode = 0; responseData.Message = "Failed."; try { Customer trans = StripeHelpers.GetCustomerById(cusID); var customerModel = _mapper.Map <Customer, CustomerModel>(trans); responseData.Message = "Successfully."; responseData.StatusCode = 1; responseData.Result.Data = trans; } catch (Exception ex) { responseData.Message = "Something went wrong, please try again."; responseData.StatusCode = 0; //EmailHelpers.SendEmail(new Common.DTO.ErrorInfo() //{ // Section = "AQ Request GetCardByCustomer", // Exception = ex //}); } skipToReturn: //label use to force return return(Ok(responseData)); }
public IActionResult DeleteCard(string cusID, string cardID) { APIResponseData responseData = new APIResponseData(); responseData.StatusCode = 0; responseData.Message = "Failed."; try { var trans = StripeHelpers.RemoveCard(cusID, cardID); var CardModel = _mapper.Map <Card, CardStripeModel>(trans); responseData.Message = "Successfully."; responseData.StatusCode = 1; responseData.Result.Data = trans; } catch (Exception ex) { responseData.Message = "Something went wrong, please try again."; responseData.StatusCode = 0; EmailHelpers.SendEmail(new Common.DTO.ErrorInfo() { Section = "AQ Request DeleteCard", Exception = ex }); } skipToReturn: //label use to force return return(Ok(responseData)); }
bool IsTrue(string description, string currencyType, decimal curren) { var trans = new Transactions() { ID = Guid.NewGuid(), Currency = currencyType, OrderAmount = curren, PaymentCardToken = "tok_visa", PaymentMethod = "Full", OrderId = "orderIDTest000", Description = description, }; var charger = StripeHelpers.RequestCharge(trans, curren, description); var amount = charger.Amount.ToString(); var strAmount = amount.Insert(amount.Length - 2, "."); var AmountPart = Convert.ToDecimal(strAmount); WriteToFile($"### Test Currency [{currencyType}] {DateTime.Now.ToString()} ### \n\n"); if (curren == AmountPart) { WriteToFile($" {currencyType}: CurrencyInput {curren} || CurrencyOutput {AmountPart} ==> true \n\n"); return(true); } WriteToFile($" {currencyType}: CurrencyInput {curren} || CurrencyOutput {AmountPart} ==> false \n\n"); return(false); }
public IActionResult GetTokenCard(CardModel card) { APIResponseData responseData = new APIResponseData(); responseData.StatusCode = 0; responseData.Message = "Failed."; responseData.Result.Data = ""; try { var result = StripeHelpers.GetTokenCard(card); if (!string.IsNullOrEmpty(result)) { responseData.Message = "Successfully."; responseData.StatusCode = 1; responseData.Result.Data = result; } } catch (Exception ex) { responseData.Message = "Something went wrong, please try again."; responseData.StatusCode = 0; EmailHelpers.SendEmail(new Common.DTO.ErrorInfo() { Section = "AQ GetTokenCard", Exception = ex }); } return(Ok(responseData)); //return "value"; }
public IActionResult PostData([FromBody] Transactions value) { if (value != null) { if (value.ReferenceId != null)//Kiểm tra có tồn tại trên api Striper thì dùng lệnh update { } var rescoure = StripeHelpers.RequestCharge(value); Transactions trans = new Transactions() { ID = Guid.NewGuid(), Currency = rescoure.Currency, OrderId = rescoure.OrderId, ReferenceId = rescoure.Id, CreatedDate = DateTime.Now, OrderAmount = rescoure.Amount, Description = rescoure.Description, PaymentMethod = rescoure.PaymentMethodId, Status = rescoure.Status, BackUrl = rescoure.ReceiptUrl }; _TransactionsService.InsertTransactions(trans); return(Ok(rescoure)); } return(Ok("Fail")); }
/**** FROM STRIPE ****/ public static SubscriptionPlan ToSubscriptionPlan(this StripePlan stripePlan) { var plan = new SubscriptionPlan { Id = stripePlan.Id, Name = stripePlan.Nickname, Amount = ((int)stripePlan.Amount).ToDecimalAmount(), Currency = stripePlan.Currency, IntervalCount = stripePlan.IntervalCount, Interval = StripeHelpers.ToStripeInterval(stripePlan.Interval), ProductId = stripePlan.ProductId }; //Product doesn't expand here, but can be contained. return(plan); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value); //TODO: setup webhook key. StripeHelpers.SetWebhookSecret("InvoiceWebhook", Configuration.GetSection("Stripe:WebhookSecrets:InvoiceWebhook").Value); //TODO: Set the whole dictionary EncryptionHelper.SetEncryptionKey(Configuration.GetSection("Encryption:Key").Value); app.UseAuthentication(); app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}"); } ); }
//TODO: Figure out usage for App Fee. currently not used. public static Subscription ToSubscription(this StripeSubscription stripeSubscription) { var subscription = new Subscription { Id = stripeSubscription.Id, CustomerId = stripeSubscription.CustomerId, BillingType = ((StripeBilling)stripeSubscription.Billing).ToBillingType(), InvoiceStartDate = stripeSubscription.BillingCycleAnchor, CancelAtPeriodEnd = stripeSubscription.CancelAtPeriodEnd, CancellationDate = stripeSubscription.CanceledAt, CreatedDate = (DateTime)stripeSubscription.Created, CurrentPeriodEndDate = stripeSubscription.CurrentPeriodEnd, CurrentPeriodStartDate = stripeSubscription.CurrentPeriodStart, DaysUntilDue = stripeSubscription.DaysUntilDue, SubscriptionEndDate = stripeSubscription.EndedAt, Meta = stripeSubscription.Metadata, Status = StripeHelpers.ToSubscriptionStatus(stripeSubscription.Status), Tax = stripeSubscription.TaxPercent == null ? 0.1M : (decimal)stripeSubscription.TaxPercent, TrialStart = stripeSubscription.TrialStart, TrialEnd = stripeSubscription.TrialEnd }; //Items if (stripeSubscription.Items != null && stripeSubscription.Items.TotalCount > 0) { subscription.Items = new List <SubscriptionItem>(); foreach (var item in stripeSubscription.Items.Data) { subscription.Items.Add( new SubscriptionItem { Id = item.Id, Plan = item.Plan.ToSubscriptionPlan(), Quantity = item.Quantity } ); } } return(subscription); }
public IActionResult StripeInvoiceWebhook() { try { var webhookSecret = StripeHelpers.GetWebhookSecret(WHS_KEY); var requestBody = new StreamReader(Request.Body).ReadToEnd(); StripeEvent eventRequest = null; if (Request.Headers.ContainsKey(STRIPE_SIGNATURE)) { var signature = Request.Headers[STRIPE_SIGNATURE]; eventRequest = StripeEventUtility.ConstructEvent(requestBody, signature, webhookSecret); } else { Response.StatusCode = (int)HttpStatusCode.Unauthorized; } //eventRequest = JsonConvert.DeserializeObject<StripeEvent>(requestBody); var eventData = eventRequest.Data.Object; switch (eventRequest.Type) { case "invoice.payment_succeeded": var eventInvoice = eventData.ToObject <StripeInvoice>(); return(ProcessInvoicePaymentSucceeded(eventInvoice)); } return(Json(new { StatusCode = true })); } catch (Exception e) { var errorResponse = new ErrorResponse { Status = "Error", Message = e.Message }; _logger.LogError($"{Response.StatusCode} - {e.Message}, Stack: {e.StackTrace}"); return(Json(errorResponse)); } }
public IActionResult ProcessSchedulePayment(string transactionId) { APIResponseData responseData = new APIResponseData(); responseData.StatusCode = 0; responseData.Message = "Failed."; if (string.IsNullOrEmpty(transactionId) == true) { responseData.StatusCode = 2; responseData.Message = "Id is required."; goto skipToReturn; } try { var trans = _TransactionsService.GetTransactionById(transactionId); if (trans == null) { responseData.Message = "Notfound."; responseData.StatusCode = 2; goto skipToReturn; } var transactionItems = _TransactionsService.GetTransactionItems(trans.ID).ToList() .Where(x => x.Status == null).OrderBy(x => x.OrderNo).ToList(); var nextPayItem = transactionItems.FirstOrDefault(); string description = string.Format("Charge {0}% of OrderId: {1}. {2}", nextPayItem.PayPercent, trans.OrderId, trans.Description); var charge = StripeHelpers.RequestChargeWithCustomer(trans, trans.StripeCustomerId, nextPayItem.PayAmount.Value, description); if (charge.Status == "succeeded") { nextPayItem.Status = charge.Status; nextPayItem.ReferenceId = charge.Id; _TransactionsService.UpdateTransactionItem(nextPayItem); trans.ModifiedDate = DateTime.Now; trans.OrderAmountRemaining = trans.OrderAmountRemaining.Value - nextPayItem.PayAmount.Value; if (trans.OrderAmountRemaining == 0 || trans.OrderAmountRemaining.Value.ToString("#") == "0") { trans.Status = PaymentStatus.Completed; } _TransactionsService.UpdateTransactions(trans); } responseData.Message = "Successfully."; responseData.StatusCode = 1; responseData.Result.Data = new { TransactionId = transactionId, ProcessItemNo = nextPayItem.OrderNo, ProcessItemAmount = nextPayItem.PayAmount, ProcessItemPercent = nextPayItem.PayPercent, ProcessStatus = charge.Status, }; } catch (Exception ex) { responseData.Message = "Something went wrong, please try again."; responseData.StatusCode = 0; } skipToReturn: //label use to force return return(Ok(responseData)); }
public IActionResult ProcessPayment([FromBody] TransactionProcessParamsItems request, string PaymentType) { var requestParams = request.TransactionProcess; Transactions model = new Transactions(); model.BackUrl = requestParams.BackUrl; model.Currency = requestParams.Currency; model.Description = requestParams.Description; model.ID = requestParams.ID; model.OrderAmount = requestParams.OrderAmount; model.OrderId = requestParams.OrderId; model.PaymentMethod = requestParams.PaymentMethod; model.PaymentCardToken = requestParams.PaymentCardToken; APIResponseData responseData = new APIResponseData(); responseData.StatusCode = 0; responseData.Message = "Failed."; if (model == null) { responseData.StatusCode = 2; responseData.Message = "Value is required."; goto skipToReturn; } try { var trans = _TransactionsService.GetTransactionById(model.ID.ToString()); if (trans == null) { responseData.Message = "Notfound."; responseData.StatusCode = 2; goto skipToReturn; } #region PAYPAL if (PaymentType.ToUpper() == "PAYPAL") // Paypal { var paypal = Payment_PayPal(request); trans.ModifiedDate = DateTime.Now; trans.PaymentTypeAPI = PaymentType.ToUpper(); _TransactionsService.UpdateTransactions(trans); responseData.Message = "Successfully."; responseData.StatusCode = 1; responseData.Result.Data = new { TransactionId = model.ID, PaymenID = paypal.id, PaymentStatus = paypal.state, FailureMessage = paypal.failed_transactions }; return(Ok(responseData)); //return new JsonResult(paypal); } #endregion #region Stripe else { Stripe.Charge charge = null; //var amount = charge.Amount.ToString(); decimal payAmount = 0; if (trans.PaymentMethod == Common.DTO.PaymentMethod.Full.ToUpper()) { payAmount = model.OrderAmount.Value; charge = StripeHelpers.RequestCharge(model, payAmount, model.Description); trans.Status = charge.Status; trans.ReferenceId = charge.Id; } else { var transactionItems = _TransactionsService.GetTransactionItems(trans.ID).ToList() .Where(x => x.Status == null).OrderBy(x => x.OrderNo).ToList(); var nextPayItem = transactionItems.FirstOrDefault(); payAmount = nextPayItem.PayAmount.Value; string description = string.Format("Charge {0}% of OrderId: {1}. {2}", nextPayItem.PayPercent, model.OrderId, model.Description); charge = StripeHelpers.RequestCharge(model, payAmount, description); nextPayItem.Status = charge.Status; nextPayItem.ReferenceId = charge.Id; _TransactionsService.UpdateTransactionItem(nextPayItem); trans.Status = PaymentStatus.Processing; } trans.ModifiedDate = DateTime.Now; trans.PaymentCardToken = model.PaymentCardToken; trans.StripeCustomerId = charge.CustomerId; trans.OrderAmountRemaining = trans.OrderAmountRemaining.Value - payAmount; trans.PaymentTypeAPI = PaymentType.ToUpper(); _TransactionsService.UpdateTransactions(trans); responseData.Message = "Successfully."; responseData.StatusCode = 1; responseData.Result.Data = new { TransactionId = model.ID, PaymenID = charge.Id, PaymentStatus = charge.Status, FailureMessage = charge.FailureMessage }; var PaymentLogs = new PaymentLogs() { Data = Newtonsoft.Json.JsonConvert.SerializeObject(charge), Error = "Success", PaymentType = PaymentType, FunctionName = "ProcessPayment", TransID = requestParams.ID.ToString() }; _PaymentLogsService.InsertPaymentLogs(PaymentLogs); } #endregion } catch (Exception ex) { responseData.Message = "Something went wrong, please try again."; responseData.StatusCode = 0; var typeEx = ex.GetType(); if (typeEx.FullName == "PayPal.PayPalException") { var excep = ex as PayPal.PaymentsException; StringBuilder sb = new StringBuilder(); sb.AppendLine("Error: " + excep.Details.name); sb.AppendLine("Message: " + excep.Details.message); sb.AppendLine("URI: " + excep.Details.information_link); sb.AppendLine("Debug ID: " + excep.Details.debug_id); foreach (var errorDetails in excep.Details.details) { sb.AppendLine("Details: " + errorDetails.field + " -> " + errorDetails.issue); } var PaymentLogs = new PaymentLogs() { Data = Newtonsoft.Json.JsonConvert.SerializeObject(request), Error = sb.ToString(), PaymentType = PaymentType, FunctionName = "ProcessPayment", TransID = requestParams.ID.ToString() }; _PaymentLogsService.InsertPaymentLogs(PaymentLogs); } else { var PaymentLogs = new PaymentLogs() { Data = Newtonsoft.Json.JsonConvert.SerializeObject(request), Error = ex.InnerException != null?Newtonsoft.Json.JsonConvert.SerializeObject(ex.InnerException.Message) : Newtonsoft.Json.JsonConvert.SerializeObject(ex.Message), PaymentType = PaymentType, FunctionName = "ProcessPayment", TransID = requestParams.ID.ToString() }; _PaymentLogsService.InsertPaymentLogs(PaymentLogs); } EmailHelpers.SendEmail(new Common.DTO.ErrorInfo() { Section = $"AQ ProcessPayment PaymentType: {PaymentType} <br /> TransactionID : {requestParams.ID}", Exception = ex }); } skipToReturn: //label use to force return return(Ok(responseData)); }
public IActionResult RefundStripe(string TransId) { var trans = _TransactionsService.GetTransactionById(TransId); APIResponseData responseData = new APIResponseData(); responseData.StatusCode = 0; responseData.Message = "Failed."; responseData.Result.Data = new { TransactionId = TransId, Status = "Fail" }; try { if (trans != null) { var refund = StripeHelpers.RefundPayment(trans.ReferenceId); responseData.StatusCode = 1; responseData.Message = "Success"; responseData.Result.Data = new { TransactionId = TransId, Status = refund.Status }; var RefundStripe = new RefundStripe() { Reason = refund.Reason, Description = refund.Description, Status = refund.Status, ChargeId = trans.ReferenceId, Amount = refund.Amount, RefundID = refund.Id, FailureReason = refund.FailureReason, Currency = refund.Currency, TransID = TransId }; refundStripeService.InsertRefundStripe(RefundStripe); var PaymentLogs = new PaymentLogs() { Data = Newtonsoft.Json.JsonConvert.SerializeObject(refund), Error = "Success", PaymentType = "STRIPE", FunctionName = "RefundStripe", TransID = TransId }; _PaymentLogsService.InsertPaymentLogs(PaymentLogs); } } catch (Exception ex) { responseData.StatusCode = 0; responseData.Message = "Something went wrong, please try again."; var typeEx = ex.GetType(); var PaymentLogs = new PaymentLogs() { Data = Newtonsoft.Json.JsonConvert.SerializeObject(trans), Error = ex.Message, PaymentType = "STRIPE", FunctionName = "RefundStripe", TransID = TransId }; _PaymentLogsService.InsertPaymentLogs(PaymentLogs); EmailHelpers.SendEmail(new Common.DTO.ErrorInfo() { Section = $"AQ RefundStripe PaymentType: STRIPE <br /> TransactionID : {TransId}", Exception = ex }); } return(Ok(responseData)); }
public void Put(int id, [FromBody] string value) { StripeHelpers.GetListCharge(new Transactions()); }
public IActionResult UpdateById(string value) { StripeHelpers.UpdateWithKeyCharge(value); return(Ok()); }
public ActionResult <string> Get(string id) { StripeHelpers.GetByIdCharge(id); return("value"); }