Skip to content

Commit 9dd9875

Browse files
authored
Merge pull request #1222 from stripe/remi-add-payment-intents
Add support for the PaymentIntent resource
2 parents 0049626 + 25492a3 commit 9dd9875

17 files changed

+824
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
namespace Stripe
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using Newtonsoft.Json;
6+
using Stripe.Infrastructure;
7+
8+
public class PaymentIntent : StripeEntityWithId, ISupportMetadata
9+
{
10+
[JsonProperty("object")]
11+
public string Object { get; set; }
12+
13+
[JsonProperty("allowed_source_types")]
14+
public List<string> AllowedSourceTypes { get; set; }
15+
16+
[JsonProperty("amount")]
17+
public int? Amount { get; set; }
18+
19+
[JsonProperty("amount_capturable")]
20+
public int? AmountCapturable { get; set; }
21+
22+
[JsonProperty("amount_received")]
23+
public int? AmountReceived { get; set; }
24+
25+
#region Expandable Application
26+
public string ApplicationId { get; set; }
27+
28+
[JsonIgnore]
29+
public StripeApplication Application { get; set; }
30+
31+
[JsonProperty("application")]
32+
internal object InternalApplication
33+
{
34+
set
35+
{
36+
StringOrObject<StripeApplication>.Map(value, s => this.ApplicationId = s, o => this.Application = o);
37+
}
38+
}
39+
#endregion
40+
41+
[JsonProperty("application_fee_amount")]
42+
public int? ApplicationFeeAmount { get; set; }
43+
44+
[JsonProperty("canceled_at")]
45+
[JsonConverter(typeof(StripeDateTimeConverter))]
46+
public DateTime? CanceledAt { get; set; }
47+
48+
[JsonProperty("capture_method")]
49+
public string CaptureMethod { get; set; }
50+
51+
[JsonProperty("charges")]
52+
public StripeList<StripeCharge> Charges { get; set; }
53+
54+
[JsonProperty("client_secret")]
55+
public string ClientSecret { get; set; }
56+
57+
[JsonProperty("confirmation_method")]
58+
public string ConfirmationMethod { get; set; }
59+
60+
[JsonProperty("created")]
61+
[JsonConverter(typeof(StripeDateTimeConverter))]
62+
public DateTime? Created { get; set; }
63+
64+
[JsonProperty("currency")]
65+
public string Currency { get; set; }
66+
67+
#region Expandable Customer
68+
public string CustomerId { get; set; }
69+
70+
[JsonIgnore]
71+
public StripeCustomer Customer { get; set; }
72+
73+
[JsonProperty("customer")]
74+
internal object InternalCustomer
75+
{
76+
set
77+
{
78+
StringOrObject<StripeCustomer>.Map(value, s => this.CustomerId = s, o => this.Customer = o);
79+
}
80+
}
81+
#endregion
82+
83+
[JsonProperty("description")]
84+
public string Description { get; set; }
85+
86+
[JsonProperty("livemode")]
87+
public bool LiveMode { get; set; }
88+
89+
[JsonProperty("metadata")]
90+
public Dictionary<string, string> Metadata { get; set; }
91+
92+
[JsonProperty("next_source_action")]
93+
public PaymentIntentSourceAction NextSourceAction { get; set; }
94+
95+
[JsonProperty("receipt_email")]
96+
public string ReceiptEmail { get; set; }
97+
98+
[JsonProperty("return_url")]
99+
public string ReturnUrl { get; set; }
100+
101+
#region Expandable Review
102+
public string ReviewId { get; set; }
103+
104+
[JsonIgnore]
105+
public StripeReview Review { get; set; }
106+
107+
[JsonProperty("review")]
108+
internal object InternalReview
109+
{
110+
set
111+
{
112+
StringOrObject<StripeReview>.Map(value, s => this.ReviewId = s, o => this.Review = o);
113+
}
114+
}
115+
#endregion
116+
117+
[JsonProperty("shipping")]
118+
public StripeShipping Shipping { get; set; }
119+
120+
#region Expandable Source
121+
public string SourceId { get; set; }
122+
123+
[JsonIgnore]
124+
public Source Source { get; set; }
125+
126+
[JsonProperty("source")]
127+
internal object InternalSource
128+
{
129+
set
130+
{
131+
StringOrObject<Source>.Map(value, s => this.SourceId = s, o => this.Source = o);
132+
}
133+
}
134+
#endregion
135+
136+
[JsonProperty("statement_descriptor")]
137+
public string StatementDescriptor { get; set; }
138+
139+
[JsonProperty("status")]
140+
public string Status { get; set; }
141+
142+
[JsonProperty("transfer_data")]
143+
public PaymentIntentTransferData TransferData { get; set; }
144+
145+
[JsonProperty("transfer_group")]
146+
public string TransferGroup { get; set; }
147+
}
148+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Stripe
2+
{
3+
using Newtonsoft.Json;
4+
using Stripe.Infrastructure;
5+
6+
public enum PaymentIntentSourceActionType
7+
{
8+
Unknown,
9+
AuthorizeWithUrl,
10+
None,
11+
}
12+
13+
[JsonConverter(typeof(PaymentIntentSourceActionConverter))]
14+
public class PaymentIntentSourceAction : StripeEntity
15+
{
16+
public PaymentIntentSourceActionType Type { get; set; }
17+
18+
public PaymentIntentSourceActionAuthorizeWithUrl AuthorizeWithUrl { get; set; }
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Stripe
2+
{
3+
using Newtonsoft.Json;
4+
5+
public class PaymentIntentSourceActionAuthorizeWithUrl : StripeEntity
6+
{
7+
[JsonProperty("url")]
8+
public string Url { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Stripe
2+
{
3+
using Newtonsoft.Json;
4+
using Stripe.Infrastructure;
5+
6+
public class PaymentIntentTransferData : StripeEntity
7+
{
8+
[JsonProperty("amount")]
9+
public int Amount { get; set; }
10+
11+
#region Expandable Destination (Account)
12+
public string DestinationId { get; set; }
13+
14+
[JsonIgnore]
15+
public StripeAccount Destination { get; set; }
16+
17+
[JsonProperty("destination")]
18+
internal object InternalDestination
19+
{
20+
set
21+
{
22+
StringOrObject<StripeAccount>.Map(value, s => this.DestinationId = s, o => this.Destination = o);
23+
}
24+
}
25+
#endregion
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace Stripe.Infrastructure
2+
{
3+
using System;
4+
using Newtonsoft.Json;
5+
using Newtonsoft.Json.Linq;
6+
7+
internal class PaymentIntentSourceActionConverter : JsonConverter
8+
{
9+
public override bool CanWrite => false;
10+
11+
public override bool CanConvert(Type objectType)
12+
{
13+
throw new NotImplementedException();
14+
}
15+
16+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
17+
{
18+
var incoming = JObject.FromObject(value);
19+
20+
incoming.WriteTo(writer);
21+
}
22+
23+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
24+
{
25+
var sourceAction = new PaymentIntentSourceAction();
26+
27+
if (reader.TokenType == JsonToken.Null)
28+
{
29+
sourceAction.Type = PaymentIntentSourceActionType.None;
30+
return sourceAction;
31+
}
32+
33+
var incoming = JObject.Load(reader);
34+
35+
if (incoming.SelectToken("type")?.ToString() == "authorize_with_url")
36+
{
37+
sourceAction.Type = PaymentIntentSourceActionType.AuthorizeWithUrl;
38+
sourceAction.AuthorizeWithUrl = Mapper<PaymentIntentSourceActionAuthorizeWithUrl>.MapFromJson(incoming.SelectToken("value")?.ToString());
39+
}
40+
else
41+
{
42+
sourceAction.Type = PaymentIntentSourceActionType.Unknown;
43+
}
44+
45+
return sourceAction;
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Stripe
2+
{
3+
using System.Collections.Generic;
4+
using Newtonsoft.Json;
5+
6+
public class PaymentIntentCancelOptions : StripeBaseOptions
7+
{
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Stripe
2+
{
3+
using System.Collections.Generic;
4+
using Newtonsoft.Json;
5+
6+
public class PaymentIntentCaptureOptions : StripeBaseOptions
7+
{
8+
[JsonProperty("amount_to_capture")]
9+
public int? AmountToCapture { get; set; }
10+
11+
[JsonProperty("application_fee_amount")]
12+
public int? ApplicationFeeAmount { get; set; }
13+
14+
[JsonProperty("transfer_data")]
15+
public PaymentIntentTransferDataOptions TransferData { get; set; }
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace Stripe
2+
{
3+
using System.Collections.Generic;
4+
using Newtonsoft.Json;
5+
6+
public class PaymentIntentConfirmOptions : StripeBaseOptions
7+
{
8+
[JsonProperty("invoice")]
9+
public string Invoice { get; set; }
10+
11+
[JsonProperty("invoice_charge_reason")]
12+
public string InvoiceChargeReason { get; set; }
13+
14+
[JsonProperty("receipt_email")]
15+
public string ReceiptEmail { get; set; }
16+
17+
[JsonProperty("return_url")]
18+
public string ReturnUrl { get; set; }
19+
20+
[JsonProperty("save_source_to_customer")]
21+
public bool? SaveSourceToCustomer { get; set; }
22+
23+
[JsonProperty("source")]
24+
public string SourceId { get; set; }
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Stripe
2+
{
3+
using System.Collections.Generic;
4+
using Newtonsoft.Json;
5+
6+
public class PaymentIntentCreateOptions : PaymentIntentSharedOptions
7+
{
8+
[JsonProperty("allowed_source_types")]
9+
public List<string> AllowedSourceTypes { get; set; }
10+
11+
[JsonProperty("attempt_confirmation")]
12+
public bool? AttemptConfirmation { get; set; }
13+
14+
[JsonProperty("capture_method")]
15+
public string CaptureMethod { get; set; }
16+
17+
[JsonProperty("shipping")]
18+
public StripeChargeShippingOptions Shipping { get; set; }
19+
20+
[JsonProperty("statement_descriptor")]
21+
public string StatementDescriptor { get; set; }
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Stripe
2+
{
3+
using System;
4+
using Newtonsoft.Json;
5+
using Stripe.Infrastructure;
6+
7+
public class PaymentIntentListOptions : StripeListOptionsWithCreated
8+
{
9+
}
10+
}

0 commit comments

Comments
 (0)