-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for the PaymentIntent resource #1222
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
src/Stripe.net/Entities/PaymentIntents/PaymentIntent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> 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<StripeApplication>.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<StripeCharge> 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<StripeCustomer>.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<string, string> 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<StripeReview>.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<Source>.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; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Stripe.net/Entities/PaymentIntents/PaymentIntentSourceAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Stripe.net/Entities/PaymentIntents/PaymentIntentSourceActionAuthorizeWithUrl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Stripe | ||
{ | ||
using Newtonsoft.Json; | ||
|
||
public class PaymentIntentSourceActionAuthorizeWithUrl : StripeEntity | ||
{ | ||
[JsonProperty("url")] | ||
public string Url { get; set; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Stripe.net/Entities/PaymentIntents/PaymentIntentTransferData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StripeAccount>.Map(value, s => this.DestinationId = s, o => this.Destination = o); | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Stripe.net/Infrastructure/JsonConverters/PaymentIntentSourceActionConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PaymentIntentSourceActionAuthorizeWithUrl>.MapFromJson(incoming.SelectToken("value")?.ToString()); | ||
} | ||
else | ||
{ | ||
sourceAction.Type = PaymentIntentSourceActionType.Unknown; | ||
} | ||
|
||
return sourceAction; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Stripe.net/Services/PaymentIntents/PaymentIntentCancelOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Stripe | ||
{ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
public class PaymentIntentCancelOptions : StripeBaseOptions | ||
{ | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Stripe.net/Services/PaymentIntents/PaymentIntentCaptureOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Stripe.net/Services/PaymentIntents/PaymentIntentConfirmOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Stripe.net/Services/PaymentIntents/PaymentIntentCreateOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Stripe | ||
{ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
public class PaymentIntentCreateOptions : PaymentIntentSharedOptions | ||
{ | ||
[JsonProperty("allowed_source_types")] | ||
public List<string> 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; } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Stripe.net/Services/PaymentIntents/PaymentIntentListOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Stripe | ||
{ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Stripe.Infrastructure; | ||
|
||
public class PaymentIntentListOptions : StripeListOptionsWithCreated | ||
{ | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the OpenAPI spec, this request also has an additional
client_secret
string parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a client-side property used with the publishable key, I'm not sure this is a useful parameter in the server-side library. Do you still think I should add it? It's not in our docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, let's ignore it for now -- we can always append it later if needed.