-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1222 from stripe/remi-add-payment-intents
Add support for the PaymentIntent resource
- Loading branch information
Showing
17 changed files
with
824 additions
and
0 deletions.
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.