public sources_fixture() { SourceCreateOptions = new StripeSourceCreateOptions { Type = StripeSourceType.AchCreditTransfer, Currency = "usd", Owner = new StripeSourceOwner { Email = "*****@*****.**", CityOrTown = "Mayberry", State = "NC" } }; SourceUpdateOptions = new StripeSourceUpdateOptions { Owner = new StripeSourceOwner { Email = "*****@*****.**" } }; var service = new StripeSourceService(Cache.ApiKey); Source = service.Create(SourceCreateOptions); SourceUpdated = service.Update(Source.Id, SourceUpdateOptions); SourceRetrieved = service.Get(Source.Id); }
public sources_fixture() { SourceCreateOptions = new StripeSourceCreateOptions { Type = StripeSourceType.Bitcoin, Amount = 1, Currency = "usd", Owner = new StripeSourceOwner { Email = "*****@*****.**", CityOrTown = "Mayberry", State = "NC" } }; SourceUpdateOptions = new StripeSourceUpdateOptions { Owner = new StripeSourceOwner { Email = "*****@*****.**" } }; var service = new StripeSourceService(Cache.ApiKey); Source = service.Create(SourceCreateOptions); SourceUpdated = service.Update(Source.Id, SourceUpdateOptions); SourceRetrieved = service.Get(Source.Id); }
public StripeSource GetSource(string sourceId, string accountId, string redirectUrl) { var requestOptions = new StripeRequestOptions() { StripeConnectAccountId = accountId, }; var source = _stripeSourceService.Get(sourceId, requestOptions); if (source.Flow == "redirect") { return(source); } if (source.Card.ThreeDSecure == "required") { return(this.GetStripeSource3d(source, redirectUrl)); } return(source); }
public static StripeOutcome ChargeSource(string source, bool livemode, string client_secret, long id, string idType) { // Set your secret key: remember to change this to your live secret key in production // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.SetApiKey(MasterStrings.StripeSecretKey); var service = new StripeSourceService(); StripeSource sourceService = service.Get(source); if (sourceService.Status == "chargeable") { var options = new StripeChargeCreateOptions { Amount = sourceService.Amount, Currency = sourceService.Currency, SourceTokenOrExistingSourceId = source, Description = "Charge for Order Id " + id.ToString(), Metadata = new Dictionary <String, String>() { { idType, id.ToString() } } }; var serviceCharge = new StripeChargeService(); try { StripeCharge charge = serviceCharge.Create(options); if (charge.Outcome.Reason == "approve_with_id" || charge.Outcome.Reason == "issuer_not_available" || charge.Outcome.Reason == "processing_error" || charge.Outcome.Reason == "reenter_transaction" || charge.Outcome.Reason == "try_again_later") { charge = serviceCharge.Create(options); } charge.Outcome.Id = charge.Id; return(charge.Outcome); } catch (Exception ex) { throw new StripeException(ex.Message); } } return(new StripeOutcome() { NetworkStatus = MasterStrings.StripeNotSent, SellerMessage = "Card not yet chargeable.", Type = "pending" }); }
public Transaction_Result Sale(Sale_Details details) { StripeConfiguration.SetApiKey(secretKey); //ONCE-OFF PAYMENT if (details.ProviderToken == null || details.ProviderToken.Length <= 1) { try { StripeSource source = createStripeSource(details.CardNumber, details.CardExpiryYear, details.CardExpiryMonth, details.CardCCV, details.CardHolderName + " " + details.CardHolderLastName, false); details.ProviderToken = source.Id; } catch (StripeException e) { return(new Transaction_Result() { isApproved = false, hasServerError = true, ErrorCode = e.StripeError.Code, ErrorText = e.StripeError.Message, FullResponse = e.StripeError.StripeResponse.ResponseJson }); } } //INITIATING A CHARGE var chargeOptions = new StripeChargeCreateOptions(); var chargeService = new StripeChargeService(); StripeCharge charge = new StripeCharge(); chargeOptions.Capture = true; bool isApproved = false; bool isPending = false; try { //IF A SOURCE TOKEN IS PROVIDED >>>> ONCE-OFF PAYMENT if (details.ProviderToken.IndexOf("src") > -1) { var sourceService = new StripeSourceService(); StripeSource source = sourceService.Get(details.ProviderToken); chargeOptions.SourceTokenOrExistingSourceId = source.Id; chargeOptions.Amount = calculateAmount(details.Amount, details.CurrencyCode); // $1.00 = 100 cents chargeOptions.Currency = details.CurrencyCode.ToLower(); //SHOULD BE LOWER CASE charge = chargeService.Create(chargeOptions); } //ONCE-OFF PAYMENT else if (details.ProviderToken.IndexOf("tok") > -1) { var sourceService = new StripeSourceService(); chargeOptions.SourceTokenOrExistingSourceId = details.ProviderToken; chargeOptions.Amount = calculateAmount(details.Amount, details.CurrencyCode); // $1.00 = 100 cents chargeOptions.Currency = details.CurrencyCode.ToLower(); //SHOULD BE LOWER CASE charge = chargeService.Create(chargeOptions); } //A REUSABLE CUSTOMER (OR A CARD) else if (details.ProviderToken.IndexOf("cus") > -1) { var customerService = new StripeCustomerService(); StripeCustomer customer = customerService.Get(details.ProviderToken); chargeOptions.SourceTokenOrExistingSourceId = customer.DefaultSourceId; chargeOptions.CustomerId = details.ProviderToken; chargeOptions.Amount = calculateAmount(details.Amount, details.CurrencyCode); // $1.00 = 100 cents chargeOptions.Currency = details.CurrencyCode.ToLower(); //SHOULD BE LOWER CASE charge = chargeService.Create(chargeOptions); } string status = charge.Status; if (status.Contains("succeeded")) { isApproved = true; } else if (status.Contains("pending")) { isPending = true; } return(new Transaction_Result { isApproved = isApproved, hasServerError = isPending, ErrorText = charge.FailureMessage, ErrorCode = charge.FailureCode, TransactionIndex = charge.BalanceTransactionId, ProviderToken = charge.Id, ResultText = charge.Status, FullResponse = charge.StripeResponse.ResponseJson }); } catch (StripeException e) { return(new Transaction_Result { isApproved = false, hasServerError = true, ErrorText = e.StripeError.Message, ProviderToken = null, ErrorCode = e.StripeError.Code, FullResponse = e.StripeError.StripeResponse.ResponseJson }); } }