/// <inheritdoc /> /// <summary> /// Pay with a single use token Obtain a token from Stripe, following their examples and documentation. Pays an invoice without creating a payment method. Ensure that Stripe itself has been configured with the webhook so that invoices are marked paid. <br><br><b>Permissions Needed:</b> ANY /// </summary> /// <param name="request">The request to pay an invoice</param> public void PayStripeInvoice(StripePaymentRequest request) { mWebCallEvent.WebPath = "/payment/provider/stripe/payments"; if (!string.IsNullOrEmpty(mWebCallEvent.WebPath)) { mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json"); } mWebCallEvent.HeaderParams.Clear(); mWebCallEvent.QueryParams.Clear(); mWebCallEvent.AuthSettings.Clear(); mWebCallEvent.PostBody = null; mWebCallEvent.PostBody = KnetikClient.Serialize(request); // http body (model) parameter // authentication settings mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant"); // authentication settings mWebCallEvent.AuthSettings.Add("oauth2_password_grant"); // make the HTTP request mPayStripeInvoiceStartTime = DateTime.Now; mWebCallEvent.Context = mPayStripeInvoiceResponseContext; mWebCallEvent.RequestType = KnetikRequestType.POST; KnetikLogger.LogRequest(mPayStripeInvoiceStartTime, "PayStripeInvoice", "Sending server request..."); KnetikGlobalEventSystem.Publish(mWebCallEvent); }
public JsonResult Charge(StripePaymentRequest model) { if (model.UserBaseId == 0) { model.UserBaseId = _userService.GetCurrentUserId(); } //GET STRIPE SECRET KEY //INSTANTIATED ABOVE IN CONSTRUCTOR //IF CUSTOMER ID IS NOT PRESENT, CREATE NEW CUSTOMER, AND CHARGE CUSTOMER'S CARD if (model.Customer == null) { var customers = new StripeCustomerService(); var customer = customers.Create(new StripeCustomerCreateOptions { Email = model.Email, SourceToken = model.Id }); //CHARGE THE USER'S CARD var charges = new StripeChargeService(); var charge = charges.Create(new StripeChargeCreateOptions { Amount = model.AmountInPennies, Currency = "USD", Description = "Subscription Charge", CustomerId = customer.Id }); //RETURN JSON OBJECT TO PROMISE IN STRIPE.JS DIRECTIVE. TOKEN WILL BE STORED //IN CALL IN STRIPE.JS. WE ARE DOING IT IN FRONT END BECAUSE WE NEED TO GET USER //INFORMATION return(Json(charge)); } //IF CUSTOMER ID IS PRESENT, USE IT TO CHARGE THE TRANSACTION. else { AppTokenAddUpdateRequest tknModel = new AppTokenAddUpdateRequest(); tknModel.UserBaseId = model.UserBaseId; //HARD CODED APPTOKENTYPEID FOR STRIPE TRANSACTION TOKEN tknModel.AppTokenTypeId = 2; var charges = new StripeChargeService(); var charge = charges.Create(new StripeChargeCreateOptions { Amount = model.AmountInPennies, Currency = "USD", Description = "Subscription Charge", CustomerId = model.Customer }); tknModel.Token = charge.BalanceTransactionId; //ADD TRANSACTION TOKEN AND RENEW SUBSCRIPTION. _appTokenService.InsertStripeTxnId(tknModel); //RETURN JSON OBJECT TO PROMISE IN STRIPE.JS DIRECTIVE return(Json(charge)); } }
//IF THE DAILY SUBSCRIPTION RENEWAL DOESN'T CATCH YOUR EXPIRED SUBSCRIPTION, THIS ONE WILL //WILL CHARGE AND RENEW CURRENT LOGGED IN USER'S EXPIRED SUBSCRIPTION UPON REACHING ANY MEMBER PAGE private void RenewSubscriptionById(int userBaseId) { StripePayment cust = _userService.GetExpiredSubscriptionById(userBaseId); StripePaymentRequest model = new StripePaymentRequest(); model.AmountInPennies = cust.AmountInPennies; model.Customer = cust.Customer; model.Email = cust.Email; model.UserBaseId = cust.UserBaseId; Charge(model); }
//MESSAGE CALLED ON BY HANGFIRE THAT WILL PULL ALL EXPIRED SUBSCRIPTIONS AND WILL //GO THROUGH EACH OF THOSE EXPIRED SUBSCRIPTIONS, CHARGE THEM, AND THEN RENEW THEM public void RenewSubscriptions() { List <StripePayment> expiredSubList = _userService.GetExpiredSubscriptions(); StripePaymentRequest model = new StripePaymentRequest(); foreach (StripePayment cust in expiredSubList) { model.AmountInPennies = cust.AmountInPennies; model.Customer = cust.Customer; model.Email = cust.Email; model.UserBaseId = cust.UserBaseId; Charge(model); } }
/*public IActionResult Processing([FromBody]StripePaymentRequest paymentRequest)*/ public JsonResult Post([FromBody] StripePaymentRequest paymentRequest) { var myCharge = new ChargeCreateOptions(); myCharge.Source = paymentRequest.tokenId; myCharge.Amount = paymentRequest.amount; myCharge.Currency = "vnd"; myCharge.Metadata = new Dictionary <string, string>(); myCharge.Metadata["OurRef"] = "OurRef-" + Guid.NewGuid().ToString(); var chargeService = new ChargeService(); Charge stripeCharge = chargeService.Create(myCharge); return(new JsonResult(stripeCharge)); }
public JsonResult Post([FromBody] StripePaymentRequest paymentRequest) { StripeConfiguration.SetApiKey("sk_test_eAGTVpWttNKmjbDdtDridju600y7eg4UJU"); var myCharge = new ChargeCreateOptions(); myCharge.SourceId = paymentRequest.tokenId; myCharge.Amount = paymentRequest.amount; myCharge.Currency = "eur"; myCharge.Description = paymentRequest.productName; myCharge.Metadata = new Dictionary <string, string>(); myCharge.Metadata["OurRef"] = "OurRef-" + Guid.NewGuid().ToString(); var chargeService = new ChargeService(); Charge stripeCharge = chargeService.Create(myCharge); return(Json(stripeCharge)); }
public IActionResult Post([FromBody] StripePaymentRequest paymentRequest) { StripeConfiguration.ApiKey = "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"; var myCharge = new ChargeCreateOptions(); myCharge.Source = paymentRequest.tokenId; myCharge.Amount = paymentRequest.amount; myCharge.Currency = "usd"; myCharge.Description = paymentRequest.productName; myCharge.Metadata = new Dictionary <string, string>(); myCharge.Metadata["OurRef"] = "OurRef-" + Guid.NewGuid().ToString(); var chargeService = new ChargeService(); var stripeCharge = chargeService.Create(myCharge); return(Json(stripeCharge)); }
public IHttpActionResult RegisterTeam(TeamWithPlayers teamWithPlayers, StripePaymentRequest stripePaymentRequest) { try { _stripePaymentService.Charge(stripePaymentRequest); } catch (Exception ex) { throw new HttpResponseException( new HttpResponseMessage(HttpStatusCode.PaymentRequired) { StatusCode = HttpStatusCode.InternalServerError, ReasonPhrase = ex.Message }); } _registerFacade.RegisterTeam(teamWithPlayers); return(Ok()); }
public JsonResult DoPayment([FromBody] StripePaymentRequest request) { var customers = new CustomerService(); var charges = new ChargeService(); var customer = customers.Create(new CustomerCreateOptions { SourceToken = request.tokenId }); var charge = charges.Create(new ChargeCreateOptions { Amount = 500, Description = "Sample Charge", Currency = "usd", CustomerId = customer.Id }); return(Json(new { result = "ok" })); }
public IActionResult Post([FromBody] StripePaymentRequest paymentRequest) { //Stripe developer api key StripeConfiguration.SetApiKey("sk_test_IhD98M0gMGB1G7rbcHifS3GP"); //configuration of stripe chrarge object var myCharge = new StripeChargeCreateOptions(); myCharge.SourceTokenOrExistingSourceId = paymentRequest.tokenId; myCharge.Amount = paymentRequest.amount; myCharge.Currency = "gbp"; myCharge.Description = paymentRequest.productName; myCharge.Metadata = new Dictionary <string, string>(); myCharge.Metadata["OurRef"] = "OurRef-" + Guid.NewGuid().ToString(); var chargeService = new StripeChargeService(); StripeCharge stripeCharge = chargeService.Create(myCharge); if (stripeCharge.Status.Equals("succeeded")) { TransactionDto transaction = new TransactionDto(); transaction.Amount = (decimal)(paymentRequest.amount / 100.0); transaction.Status = "succeeded"; transaction.CustomerId = 1; transaction.PaymentGatewayId = 1; transaction.PricingPackageId = paymentRequest.packageId; transaction.DateCreated = DateTime.Now; _transactionManipulation.SaveTransaction(transaction); SubscriptionDto subscription = new SubscriptionDto(); subscription.CustomerId = 1; subscription.PricingPackageId = paymentRequest.packageId; _subscriptionManipulation.GetCustomerSubscription(1); _subscriptionManipulation.SaveSubscription(subscription); } return(Ok(stripeCharge)); }
public StripeCharge Charge(StripePaymentRequest stripePaymentRequest) { var myCharge = new StripeChargeCreateOptions() { SourceTokenOrExistingSourceId = stripePaymentRequest.TokenId, Amount = stripePaymentRequest.Amount, Currency = "usd", StatementDescriptor = "Crawfish Cup Tennis", ReceiptEmail = stripePaymentRequest.ReceiptEmail, Description = stripePaymentRequest.Description, Metadata = new Dictionary <string, string>() }; myCharge.Metadata["OurRef"] = "OurRef-" + Guid.NewGuid(); try { return(new StripeChargeService().Create(myCharge)); } catch (StripeException ex) { throw new Exception(ex.StripeError.Message); } }
public IActionResult Put([FromQuery] bool?firstPayment = false, [FromQuery] bool?sepa_debit = false, [FromQuery] bool?customer = false, [FromQuery] bool?subscription = false, [FromBody] StripePaymentRequest request = null) { var paymentProvider = new StripePaymentProvider(paymentSettings); // Create customer if requested var customerObject = customer.HasValue && customer.Value ? new StripeCustomerService(paymentSettings.StripePrivateKey).Create(new StripeCustomerCreateOptions { Email = request.Email, Description = request.Name }) : null; // define return url request.ReturnUrl = $"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host}/{nameof(StripePaymentFlowController).Replace(nameof(Controller), string.Empty)}?returnUrl=" + ($"{request.ReturnUrl}?{string.Concat(request.ReturnUrlParams.Select(x => $"&{x.Key}={x.Value}")).Substring(1)}").Replace("?", "_qm_").Replace("&", "_amp_") + (customerObject != null ? $"&customerId={customerObject.Id}" : "") + $"&amount={request.AmountCents}" + $"¤cy={request.Currency}"; // Create first payment source if requested var dataForSource = new FirstPaymentData { Amount = request.AmountCents, Currency = request.Currency, OwnerName = request.Name, RedirectReturnUrl = request.ReturnUrl, CountryCode = request.CountryCode }; var firstPaymentSource = PaymentSourceCreator.Build(dataForSource).Create(paymentSettings, dataForSource); // create sepa source if requested var sepaSource = sepa_debit.HasValue && sepa_debit.Value ? new StripeSourceService(paymentSettings.StripePrivateKey).Create(new StripeSourceCreateOptions { Type = StripeSourceType.SepaDebit, Amount = request.AmountCents, Currency = request.Currency, Owner = new StripeSourceOwner { Name = request.Name, Email = request.Email, Phone = request.Phone, PostalCode = request.PostalCode, Line1 = request.Line1, CityOrTown = request.CityOrTown, Country = "NL" }, SepaDebitIban = !string.IsNullOrEmpty(request.Iban) ? request.Iban : "DE89370400440532013000" }) : null; if (customerObject != null) { // Assign customer to the source new StripeCustomerService(paymentSettings.StripePrivateKey).Update(customerObject.Id, new StripeCustomerUpdateOptions { SourceToken = (sepaSource ?? firstPaymentSource)?.Id }); } // Create plan and subscriptions to sepaDirectDebit if (subscription.HasValue && subscription.Value && customerObject != null) { var planId = $"1_{request.Currency}"; var planName = $"One {request.Currency} plan"; var plan = new StripePaymentProvider(paymentSettings).GetPlan(planId) ?? new StripePlanService(paymentSettings.StripePrivateKey).Create(new StripePlanCreateOptions { Amount = 100, Currency = request.Currency, Interval = StripePlanIntervals.Month, Name = planName, StatementDescriptor = paymentSettings.SepaStatementDescriptor, TrialPeriodDays = 30, IntervalCount = 1, Id = planId }); new StripeSubscriptionService(paymentSettings.StripePrivateKey).Create(customerObject.Id, new StripeSubscriptionCreateOptions { PlanId = planId, Quantity = request.AmountCents }); } return(Json((firstPayment.HasValue && firstPayment.Value) ? firstPaymentSource.Redirect.Url : ($"{request.ReturnUrl}?{string.Concat(request.ReturnUrlParams.Select(x => $"&{x.Key}={x.Value}")).Substring(1)}").Replace("?", "_qm_").Replace("&", "_amp_"))); }
/// <summary> /// Pay with a single use token Obtain a token from Stripe, following their examples and documentation. Pays an invoice without creating a payment method. Ensure that Stripe itself has been configured with the webhook so that invoices are marked paid. <br><br><b>Permissions Needed:</b> ANY /// </summary> /// <exception cref="com.knetikcloud.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="request">The request to pay an invoice (optional)</param> /// <returns>ApiResponse of Object(void)</returns> public ApiResponse <Object> PayStripeInvoiceWithHttpInfo(StripePaymentRequest request = null) { var localVarPath = "/payment/provider/stripe/payments"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (request != null && request.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(request); // http body (model) parameter } else { localVarPostBody = request; // byte array } // authentication (oauth2_client_credentials_grant) required // oauth required if (!String.IsNullOrEmpty(Configuration.AccessToken)) { localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken; } // authentication (oauth2_password_grant) required // oauth required if (!String.IsNullOrEmpty(Configuration.AccessToken)) { localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken; } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("PayStripeInvoice", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), null)); }
/// <summary> /// Pay with a single use token Obtain a token from Stripe, following their examples and documentation. Pays an invoice without creating a payment method. Ensure that Stripe itself has been configured with the webhook so that invoices are marked paid. <br><br><b>Permissions Needed:</b> ANY /// </summary> /// <exception cref="com.knetikcloud.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="request">The request to pay an invoice (optional)</param> /// <returns></returns> public void PayStripeInvoice(StripePaymentRequest request = null) { PayStripeInvoiceWithHttpInfo(request); }