diff --git a/src/Stripe.net/Entities/PaymentIntents/PaymentIntent.cs b/src/Stripe.net/Entities/PaymentIntents/PaymentIntent.cs new file mode 100644 index 0000000000..da98fba7fe --- /dev/null +++ b/src/Stripe.net/Entities/PaymentIntents/PaymentIntent.cs @@ -0,0 +1,148 @@ +namespace Stripe +{ + using System; + using System.Collections.Generic; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class PaymentIntent : StripeEntityWithId, ISupportMetadata + { + [JsonProperty("object")] + public string Object { get; set; } + + [JsonProperty("allowed_source_types")] + public List AllowedSourceTypes { get; set; } + + [JsonProperty("amount")] + public int? Amount { get; set; } + + [JsonProperty("amount_capturable")] + public int? AmountCapturable { get; set; } + + [JsonProperty("amount_received")] + public int? AmountReceived { get; set; } + + #region Expandable Application + public string ApplicationId { get; set; } + + [JsonIgnore] + public StripeApplication Application { get; set; } + + [JsonProperty("application")] + internal object InternalApplication + { + set + { + StringOrObject.Map(value, s => this.ApplicationId = s, o => this.Application = o); + } + } + #endregion + + [JsonProperty("application_fee_amount")] + public int? ApplicationFeeAmount { get; set; } + + [JsonProperty("canceled_at")] + [JsonConverter(typeof(StripeDateTimeConverter))] + public DateTime? CanceledAt { get; set; } + + [JsonProperty("capture_method")] + public string CaptureMethod { get; set; } + + [JsonProperty("charges")] + public StripeList Charges { get; set; } + + [JsonProperty("client_secret")] + public string ClientSecret { get; set; } + + [JsonProperty("confirmation_method")] + public string ConfirmationMethod { get; set; } + + [JsonProperty("created")] + [JsonConverter(typeof(StripeDateTimeConverter))] + public DateTime? Created { get; set; } + + [JsonProperty("currency")] + public string Currency { get; set; } + + #region Expandable Customer + public string CustomerId { get; set; } + + [JsonIgnore] + public StripeCustomer Customer { get; set; } + + [JsonProperty("customer")] + internal object InternalCustomer + { + set + { + StringOrObject.Map(value, s => this.CustomerId = s, o => this.Customer = o); + } + } + #endregion + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("livemode")] + public bool LiveMode { get; set; } + + [JsonProperty("metadata")] + public Dictionary Metadata { get; set; } + + [JsonProperty("next_source_action")] + public PaymentIntentSourceAction NextSourceAction { get; set; } + + [JsonProperty("receipt_email")] + public string ReceiptEmail { get; set; } + + [JsonProperty("return_url")] + public string ReturnUrl { get; set; } + + #region Expandable Review + public string ReviewId { get; set; } + + [JsonIgnore] + public StripeReview Review { get; set; } + + [JsonProperty("review")] + internal object InternalReview + { + set + { + StringOrObject.Map(value, s => this.ReviewId = s, o => this.Review = o); + } + } + #endregion + + [JsonProperty("shipping")] + public StripeShipping Shipping { get; set; } + + #region Expandable Source + public string SourceId { get; set; } + + [JsonIgnore] + public Source Source { get; set; } + + [JsonProperty("source")] + internal object InternalSource + { + set + { + StringOrObject.Map(value, s => this.SourceId = s, o => this.Source = o); + } + } + #endregion + + [JsonProperty("statement_descriptor")] + public string StatementDescriptor { get; set; } + + [JsonProperty("status")] + public string Status { get; set; } + + [JsonProperty("transfer_data")] + public PaymentIntentTransferData TransferData { get; set; } + + [JsonProperty("transfer_group")] + public string TransferGroup { get; set; } + } +} diff --git a/src/Stripe.net/Entities/PaymentIntents/PaymentIntentSourceAction.cs b/src/Stripe.net/Entities/PaymentIntents/PaymentIntentSourceAction.cs new file mode 100644 index 0000000000..635b051033 --- /dev/null +++ b/src/Stripe.net/Entities/PaymentIntents/PaymentIntentSourceAction.cs @@ -0,0 +1,20 @@ +namespace Stripe +{ + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public enum PaymentIntentSourceActionType + { + Unknown, + AuthorizeWithUrl, + None, + } + + [JsonConverter(typeof(PaymentIntentSourceActionConverter))] + public class PaymentIntentSourceAction : StripeEntity + { + public PaymentIntentSourceActionType Type { get; set; } + + public PaymentIntentSourceActionAuthorizeWithUrl AuthorizeWithUrl { get; set; } + } +} diff --git a/src/Stripe.net/Entities/PaymentIntents/PaymentIntentSourceActionAuthorizeWithUrl.cs b/src/Stripe.net/Entities/PaymentIntents/PaymentIntentSourceActionAuthorizeWithUrl.cs new file mode 100644 index 0000000000..0755bad381 --- /dev/null +++ b/src/Stripe.net/Entities/PaymentIntents/PaymentIntentSourceActionAuthorizeWithUrl.cs @@ -0,0 +1,10 @@ +namespace Stripe +{ + using Newtonsoft.Json; + + public class PaymentIntentSourceActionAuthorizeWithUrl : StripeEntity + { + [JsonProperty("url")] + public string Url { get; set; } + } +} diff --git a/src/Stripe.net/Entities/PaymentIntents/PaymentIntentTransferData.cs b/src/Stripe.net/Entities/PaymentIntents/PaymentIntentTransferData.cs new file mode 100644 index 0000000000..c39072d3b4 --- /dev/null +++ b/src/Stripe.net/Entities/PaymentIntents/PaymentIntentTransferData.cs @@ -0,0 +1,27 @@ +namespace Stripe +{ + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class PaymentIntentTransferData : StripeEntity + { + [JsonProperty("amount")] + public int Amount { get; set; } + + #region Expandable Destination (Account) + public string DestinationId { get; set; } + + [JsonIgnore] + public StripeAccount Destination { get; set; } + + [JsonProperty("destination")] + internal object InternalDestination + { + set + { + StringOrObject.Map(value, s => this.DestinationId = s, o => this.Destination = o); + } + } + #endregion + } +} diff --git a/src/Stripe.net/Infrastructure/JsonConverters/PaymentIntentSourceActionConverter.cs b/src/Stripe.net/Infrastructure/JsonConverters/PaymentIntentSourceActionConverter.cs new file mode 100644 index 0000000000..f6d6edc794 --- /dev/null +++ b/src/Stripe.net/Infrastructure/JsonConverters/PaymentIntentSourceActionConverter.cs @@ -0,0 +1,48 @@ +namespace Stripe.Infrastructure +{ + using System; + using Newtonsoft.Json; + using Newtonsoft.Json.Linq; + + internal class PaymentIntentSourceActionConverter : JsonConverter + { + public override bool CanWrite => false; + + public override bool CanConvert(Type objectType) + { + throw new NotImplementedException(); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var incoming = JObject.FromObject(value); + + incoming.WriteTo(writer); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var sourceAction = new PaymentIntentSourceAction(); + + if (reader.TokenType == JsonToken.Null) + { + sourceAction.Type = PaymentIntentSourceActionType.None; + return sourceAction; + } + + var incoming = JObject.Load(reader); + + if (incoming.SelectToken("type")?.ToString() == "authorize_with_url") + { + sourceAction.Type = PaymentIntentSourceActionType.AuthorizeWithUrl; + sourceAction.AuthorizeWithUrl = Mapper.MapFromJson(incoming.SelectToken("value")?.ToString()); + } + else + { + sourceAction.Type = PaymentIntentSourceActionType.Unknown; + } + + return sourceAction; + } + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentCancelOptions.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentCancelOptions.cs new file mode 100644 index 0000000000..c4aa7c3e35 --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentCancelOptions.cs @@ -0,0 +1,9 @@ +namespace Stripe +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public class PaymentIntentCancelOptions : StripeBaseOptions + { + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentCaptureOptions.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentCaptureOptions.cs new file mode 100644 index 0000000000..19e234a24e --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentCaptureOptions.cs @@ -0,0 +1,17 @@ +namespace Stripe +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public class PaymentIntentCaptureOptions : StripeBaseOptions + { + [JsonProperty("amount_to_capture")] + public int? AmountToCapture { get; set; } + + [JsonProperty("application_fee_amount")] + public int? ApplicationFeeAmount { get; set; } + + [JsonProperty("transfer_data")] + public PaymentIntentTransferDataOptions TransferData { get; set; } + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentConfirmOptions.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentConfirmOptions.cs new file mode 100644 index 0000000000..30df9995c7 --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentConfirmOptions.cs @@ -0,0 +1,26 @@ +namespace Stripe +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public class PaymentIntentConfirmOptions : StripeBaseOptions + { + [JsonProperty("invoice")] + public string Invoice { get; set; } + + [JsonProperty("invoice_charge_reason")] + public string InvoiceChargeReason { get; set; } + + [JsonProperty("receipt_email")] + public string ReceiptEmail { get; set; } + + [JsonProperty("return_url")] + public string ReturnUrl { get; set; } + + [JsonProperty("save_source_to_customer")] + public bool? SaveSourceToCustomer { get; set; } + + [JsonProperty("source")] + public string SourceId { get; set; } + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentCreateOptions.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentCreateOptions.cs new file mode 100644 index 0000000000..b0a086e36d --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentCreateOptions.cs @@ -0,0 +1,23 @@ +namespace Stripe +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public class PaymentIntentCreateOptions : PaymentIntentSharedOptions + { + [JsonProperty("allowed_source_types")] + public List AllowedSourceTypes { get; set; } + + [JsonProperty("attempt_confirmation")] + public bool? AttemptConfirmation { get; set; } + + [JsonProperty("capture_method")] + public string CaptureMethod { get; set; } + + [JsonProperty("shipping")] + public StripeChargeShippingOptions Shipping { get; set; } + + [JsonProperty("statement_descriptor")] + public string StatementDescriptor { get; set; } + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentListOptions.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentListOptions.cs new file mode 100644 index 0000000000..f8f8845316 --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentListOptions.cs @@ -0,0 +1,10 @@ +namespace Stripe +{ + using System; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class PaymentIntentListOptions : StripeListOptionsWithCreated + { + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentService.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentService.cs new file mode 100644 index 0000000000..83be7e6556 --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentService.cs @@ -0,0 +1,98 @@ +namespace Stripe +{ + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + using Stripe.Infrastructure; + + public class PaymentIntentService : StripeBasicService + { + public PaymentIntentService() + : base(null) + { + } + + public PaymentIntentService(string apiKey) + : base(apiKey) + { + } + + public bool ExpandApplication { get; set; } + + public bool ExpandCustomer { get; set; } + + public bool ExpandSource { get; set; } + + // Sync + public virtual PaymentIntent Create(PaymentIntentCreateOptions options, StripeRequestOptions requestOptions = null) + { + return this.Post($"{Urls.BaseUrl}/payment_intents", requestOptions, options); + } + + public virtual PaymentIntent Get(string paymentIntentId, StripeRequestOptions requestOptions = null) + { + return this.GetEntity($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}", requestOptions); + } + + public virtual PaymentIntent Update(string paymentIntentId, PaymentIntentUpdateOptions options, StripeRequestOptions requestOptions = null) + { + return this.Post($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}", requestOptions, options); + } + + public virtual StripeList List(PaymentIntentListOptions listOptions = null, StripeRequestOptions requestOptions = null) + { + return this.GetEntityList($"{Urls.BaseUrl}/payment_intents", requestOptions, listOptions); + } + + public virtual PaymentIntent Cancel(string paymentIntentId, PaymentIntentCancelOptions options, StripeRequestOptions requestOptions = null) + { + return this.Post($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}/cancel", requestOptions, options); + } + + public virtual PaymentIntent Capture(string paymentIntentId, PaymentIntentCaptureOptions options, StripeRequestOptions requestOptions = null) + { + return this.Post($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}/capture", requestOptions, options); + } + + public virtual PaymentIntent Confirm(string paymentIntentId, PaymentIntentConfirmOptions options, StripeRequestOptions requestOptions = null) + { + return this.Post($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}/confirm", requestOptions, options); + } + + // Async + public virtual Task CreateAsync(PaymentIntentCreateOptions options, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.PostAsync($"{Urls.BaseUrl}/payment_intents", requestOptions, cancellationToken, options); + } + + public virtual Task GetAsync(string paymentIntentId, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.GetEntityAsync($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}", requestOptions, cancellationToken); + } + + public virtual Task UpdateAsync(string paymentIntentId, PaymentIntentUpdateOptions options, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.PostAsync($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}", requestOptions, cancellationToken, options); + } + + public virtual Task> ListAsync(PaymentIntentListOptions listOptions = null, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.GetEntityListAsync($"{Urls.BaseUrl}/payment_intents", requestOptions, cancellationToken, listOptions); + } + + public virtual Task CancelAsync(string paymentIntentId, PaymentIntentCancelOptions options, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.PostAsync($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}/cancel", requestOptions, cancellationToken, options); + } + + public virtual Task CaptureAsync(string paymentIntentId, PaymentIntentCaptureOptions options, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.PostAsync($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}/capture", requestOptions, cancellationToken, options); + } + + public virtual Task ConfirmAsync(string paymentIntentId, PaymentIntentConfirmOptions options, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.PostAsync($"{Urls.BaseUrl}/payment_intents/{paymentIntentId}/confirm", requestOptions, cancellationToken, options); + } + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentSharedOptions.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentSharedOptions.cs new file mode 100644 index 0000000000..66d38e3cf9 --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentSharedOptions.cs @@ -0,0 +1,44 @@ +namespace Stripe +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public class PaymentIntentSharedOptions : StripeBaseOptions, ISupportMetadata + { + [JsonProperty("amount")] + public int? Amount { get; set; } + + [JsonProperty("application_fee_amount")] + public int? ApplicationFeeAmount { get; set; } + + [JsonProperty("currency")] + public string Currency { get; set; } + + [JsonProperty("customer")] + public string CustomerId { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("metadata")] + public Dictionary Metadata { get; set; } + + [JsonProperty("receipt_email")] + public string ReceiptEmail { get; set; } + + [JsonProperty("return_url")] + public string ReturnUrl { get; set; } + + [JsonProperty("save_source_to_customer")] + public bool? SaveSourceToCustomer { get; set; } + + [JsonProperty("source")] + public string SourceId { get; set; } + + [JsonProperty("transfer_data")] + public PaymentIntentTransferDataOptions TransferData { get; set; } + + [JsonProperty("transfer_group")] + public string TransferGroup { get; set; } + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentTransferDataOptions.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentTransferDataOptions.cs new file mode 100644 index 0000000000..ca3559c953 --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentTransferDataOptions.cs @@ -0,0 +1,14 @@ +namespace Stripe +{ + using Newtonsoft.Json; + + public class PaymentIntentTransferDataOptions : INestedOptions + { + [JsonProperty("transfer_data[amount]")] + public int? Amount { get; set; } + + // This is only available on creation and not update + [JsonProperty("transfer_data[destination]")] + public string Destination { get; set; } + } +} diff --git a/src/Stripe.net/Services/PaymentIntents/PaymentIntentUpdateOptions.cs b/src/Stripe.net/Services/PaymentIntents/PaymentIntentUpdateOptions.cs new file mode 100644 index 0000000000..a1b3c50430 --- /dev/null +++ b/src/Stripe.net/Services/PaymentIntents/PaymentIntentUpdateOptions.cs @@ -0,0 +1,9 @@ +namespace Stripe +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public class PaymentIntentUpdateOptions : PaymentIntentSharedOptions + { + } +} diff --git a/src/StripeTests/Entities/PaymentIntentTest.cs b/src/StripeTests/Entities/PaymentIntentTest.cs new file mode 100644 index 0000000000..4e5df88092 --- /dev/null +++ b/src/StripeTests/Entities/PaymentIntentTest.cs @@ -0,0 +1,71 @@ +namespace StripeTests +{ + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + + using Newtonsoft.Json; + using Stripe; + using Xunit; + + public class PaymentIntentTest : BaseStripeTest + { + [Fact] + public void Deserialize() + { + string json = GetFixture("/v1/payment_intents/pi_123"); + var intent = Mapper.MapFromJson(json); + Assert.NotNull(intent); + Assert.IsType(intent); + Assert.NotNull(intent.Id); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public void DeserializeWithExpansions() + { + string[] expansions = + { + "application", + "customer", + "source", + "transfer_data.destination", + }; + + string json = GetFixture("/v1/payment_intents/pi_123", expansions); + var intent = Mapper.MapFromJson(json); + Assert.NotNull(intent); + Assert.IsType(intent); + Assert.NotNull(intent.Id); + Assert.Equal("payment_intent", intent.Object); + + Assert.NotNull(intent.Application); + Assert.Equal("application", intent.Application.Object); + + Assert.NotNull(intent.Customer); + Assert.Equal("customer", intent.Customer.Object); + + Assert.NotNull(intent.Source); + Assert.Equal("card", intent.Source.Card.Object); + + Assert.NotNull(intent.TransferData); + Assert.NotNull(intent.TransferData.Destination); + Assert.Equal("account", intent.TransferData.Destination.Object); + } + + [Fact] + public void DeserializeNextSourceAction() + { + var json = GetResourceAsString("api_fixtures.payment_intent_with_next_source_action.json"); + var intent = Mapper.MapFromJson(json); + + Assert.NotNull(intent); + Assert.IsType(intent); + Assert.NotNull(intent.Id); + Assert.Equal("payment_intent", intent.Object); + + Assert.Equal(PaymentIntentSourceActionType.AuthorizeWithUrl, intent.NextSourceAction.Type); + Assert.Equal("https://stripe.com", intent.NextSourceAction.AuthorizeWithUrl.Url); + } + } +} diff --git a/src/StripeTests/Resources/api_fixtures/payment_intent_with_next_source_action.json b/src/StripeTests/Resources/api_fixtures/payment_intent_with_next_source_action.json new file mode 100644 index 0000000000..d1041c6a28 --- /dev/null +++ b/src/StripeTests/Resources/api_fixtures/payment_intent_with_next_source_action.json @@ -0,0 +1,66 @@ +{ + "id": "pi_123", + "object": "payment_intent", + "allowed_source_types": [ + "card" + ], + "amount": 1099, + "amount_capturable": 1000, + "amount_received": 0, + "application": null, + "application_fee": null, + "canceled_at": null, + "capture_method": "automatic", + "charges": { + "object": "list", + "data": [ + { + "id": "ch_123", + "object": "charge" + } + ], + "has_more": false, + "total_count": 1, + "url": "/v1/charges?payment_intent=pi_123" + }, + "client_secret": null, + "confirmation_method": "publishable", + "created": 123456789, + "currency": "usd", + "customer": null, + "description": "PaymentIntent Description", + "livemode": false, + "metadata": { + "order_id": "123456789" + }, + "next_source_action": { + "type": "authorize_with_url", + "value": { + "url": "https://stripe.com" + } + }, + "on_behalf_of": null, + "receipt_email": "test@stripe.com", + "return_url": null, + "shipping": { + "address": { + "city": "city", + "country": "USA", + "line1": "123 Main St", + "line2": "Apt B", + "postal_code": "90210", + "state": "NC" + }, + "carrier": "Carrier", + "name": "Namey Namerson", + "phone": null, + "tracking_number": "12345" + }, + "source": "src_123", + "statement_descriptor": "PaymentIntent Statement Descriptor", + "status": "succeeded", + "transfer_data": { + "amount": 1234 + }, + "transfer_group": null +} \ No newline at end of file diff --git a/src/StripeTests/Services/PaymentIntents/PaymentIntentServiceTest.cs b/src/StripeTests/Services/PaymentIntents/PaymentIntentServiceTest.cs new file mode 100644 index 0000000000..7e38dbe445 --- /dev/null +++ b/src/StripeTests/Services/PaymentIntents/PaymentIntentServiceTest.cs @@ -0,0 +1,184 @@ +namespace StripeTests +{ + using System.Collections.Generic; + using System.Threading.Tasks; + + using Stripe; + using Xunit; + + public class PaymentIntentServiceTest : BaseStripeTest + { + private const string PaymentIntentId = "pi_123"; + + private PaymentIntentService service; + private PaymentIntentCancelOptions cancelOptions; + private PaymentIntentCaptureOptions captureOptions; + private PaymentIntentConfirmOptions confirmOptions; + private PaymentIntentCreateOptions createOptions; + private PaymentIntentListOptions listOptions; + private PaymentIntentUpdateOptions updateOptions; + + public PaymentIntentServiceTest() + { + this.service = new PaymentIntentService(); + + this.cancelOptions = new PaymentIntentCancelOptions + { + }; + + this.captureOptions = new PaymentIntentCaptureOptions + { + AmountToCapture = 123, + }; + + this.confirmOptions = new PaymentIntentConfirmOptions + { + SaveSourceToCustomer = true, + }; + + this.createOptions = new PaymentIntentCreateOptions + { + AllowedSourceTypes = new List + { + "card", + }, + Amount = 1000, + Currency = "usd", + TransferData = new PaymentIntentTransferDataOptions + { + Amount = 100, + Destination = "acct_123", + } + }; + + this.listOptions = new PaymentIntentListOptions + { + Limit = 1, + }; + + this.updateOptions = new PaymentIntentUpdateOptions + { + Metadata = new Dictionary + { + { "key", "value" }, + }, + }; + } + + [Fact] + public void Cancel() + { + var intent = this.service.Cancel(PaymentIntentId, this.cancelOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public async Task CancelAsync() + { + var intent = await this.service.CancelAsync(PaymentIntentId, this.cancelOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public void Capture() + { + var intent = this.service.Capture(PaymentIntentId, this.captureOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public async Task CaptureAsync() + { + var intent = await this.service.CaptureAsync(PaymentIntentId, this.captureOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public void Confirm() + { + var intent = this.service.Confirm(PaymentIntentId, this.confirmOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public async Task ConfirmAsync() + { + var intent = await this.service.ConfirmAsync(PaymentIntentId, this.confirmOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public void Create() + { + var intent = this.service.Create(this.createOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public async Task CreateAsync() + { + var intent = await this.service.CreateAsync(this.createOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public void Get() + { + var intent = this.service.Get(PaymentIntentId); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public async Task GetAsync() + { + var intent = await this.service.GetAsync(PaymentIntentId); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public void List() + { + var intents = this.service.List(this.listOptions); + Assert.NotNull(intents); + Assert.Equal("list", intents.Object); + Assert.Single(intents.Data); + Assert.Equal("payment_intent", intents.Data[0].Object); + } + + [Fact] + public async Task ListAsync() + { + var intents = await this.service.ListAsync(this.listOptions); + Assert.NotNull(intents); + Assert.Equal("list", intents.Object); + Assert.Single(intents.Data); + Assert.Equal("payment_intent", intents.Data[0].Object); + } + + [Fact] + public void Update() + { + var intent = this.service.Update(PaymentIntentId, this.updateOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + + [Fact] + public async Task UpdateAsync() + { + var intent = await this.service.UpdateAsync(PaymentIntentId, this.updateOptions); + Assert.NotNull(intent); + Assert.Equal("payment_intent", intent.Object); + } + } +}