Skip to content
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 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

[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