Skip to content

Commit

Permalink
Merge pull request #1222 from stripe/remi-add-payment-intents
Browse files Browse the repository at this point in the history
Add support for the PaymentIntent resource
  • Loading branch information
remi-stripe authored Sep 24, 2018
2 parents 0049626 + 25492a3 commit 9dd9875
Show file tree
Hide file tree
Showing 17 changed files with 824 additions and 0 deletions.
148 changes: 148 additions & 0 deletions src/Stripe.net/Entities/PaymentIntents/PaymentIntent.cs
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; }
}
}
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; }
}
}
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; }
}
}
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
}
}
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;
}
}
}
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
{
}
}
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; }
}
}
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; }
}
}
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 src/Stripe.net/Services/PaymentIntents/PaymentIntentListOptions.cs
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
{
}
}
Loading

0 comments on commit 9dd9875

Please sign in to comment.