Skip to content

Commit

Permalink
Add support for Checkout Session
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Apr 15, 2019
1 parent 7ee3f88 commit 6f5d071
Show file tree
Hide file tree
Showing 15 changed files with 703 additions and 2 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:
COVERALLS_REPO_TOKEN:
secure: T0PmP8uyzCseacBCDRBlti2y9Tz5DL6fknea0MKWvbPYrzADmLY2/5kOTfYIsPUk
# If you bump this, don't forget to bump `MinimumMockVersion` in `StripeMockFixture.cs` as well.
STRIPE_MOCK_VERSION: 0.52.0
STRIPE_MOCK_VERSION: 0.53.0

deploy:
- provider: NuGet
Expand Down
162 changes: 162 additions & 0 deletions src/Stripe.net/Entities/Checkout/Sessions/Session.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
namespace Stripe.Checkout
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class Session : StripeEntity, IHasId, IHasObject
{
/// <summary>
/// Unique identifier for the object.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// String representing the object’s type. Objects of the same type share the same value.
/// </summary>
[JsonProperty("object")]
public string Object { get; set; }

/// <summary>
/// Specify whether Checkout should collect the customer’s billing address. If set to
/// <c>required</c>, Checkout will always collect the customer’s billing address. If left
/// blank or set to <c>auto</c> Checkout will only collect the billing address when
/// necessary.
/// </summary>
[JsonProperty("billing_address_collection")]
public string BillingAddressCollection { get; set; }

/// <summary>
/// The URL the customer will be directed to if they decide to go back to your website.
/// </summary>
[JsonProperty("cancel_url")]
public string CancelUrl { get; set; }

/// <summary>
/// A unique string to reference the Checkout Session. This can be a customer ID, a cart
/// ID, or similar. It is included in the <c>checkout.session.completed</c> webhook and can
/// be used to fulfill the purchase.
/// </summary>
[JsonProperty("client_reference_id")]
public string ClientReferenceId { get; set; }

#region Expandable Customer

/// <summary>
/// ID of the customer this Session is for if one exists.
/// </summary>
[JsonIgnore]
public string CustomerId { get; set; }

[JsonIgnore]
public Customer Customer { get; set; }

[JsonProperty("customer")]
internal object InternalCustomer
{
get
{
return this.Customer ?? (object)this.CustomerId;
}

set
{
StringOrObject<Customer>.Map(value, s => this.CustomerId = s, o => this.Customer = o);
}
}
#endregion

/// <summary>
/// The email address used to create the customer object.
/// </summary>
[JsonProperty("customer_email")]
public string CustomerEmail { get; set; }

/// <summary>
/// The line items, plans, or SKUs that were purchased by the customer.
/// </summary>
[JsonProperty("display_items")]
public List<SessionDisplayItem> DisplayItems { get; set; }

/// <summary>
/// Has the value <c>true</c> if the object exists in live mode or the value
/// <c>false</c> if the object exists in test mode.
/// </summary>
[JsonProperty("livemode")]
public bool Livemode { get; set; }

/// <summary>
/// The IETF language tag of the locale Checkout is displayed in. If blank or <c>auto</c>,
/// the browser’s locale is used.
/// </summary>
[JsonProperty("locale")]
public string Locale { get; set; }

#region Expandable PaymentIntent

/// <summary>
/// The ID of the PaymentIntent created if SKUs or line items were provided.
/// </summary>
[JsonIgnore]
public string PaymentIntentId { get; set; }

[JsonIgnore]
public PaymentIntent PaymentIntent { get; set; }

[JsonProperty("payment_intent")]
internal object InternalPaymentIntent
{
get
{
return this.PaymentIntent ?? (object)this.PaymentIntentId;
}

set
{
StringOrObject<PaymentIntent>.Map(value, s => this.PaymentIntentId = s, o => this.PaymentIntent = o);
}
}
#endregion

/// <summary>
/// The list of payment method types (e.g. card) that this Checkout Session is allowed to
/// use.
/// </summary>
[JsonProperty("payment_method_types")]
public List<string> PaymentMethodTypes { get; set; }

#region Expandable Subscription

/// <summary>
/// The ID of the subscription created if one or more plans were provided.
/// </summary>
[JsonProperty("subscription")]
public string SubscriptionId { get; set; }

[JsonIgnore]
public Subscription Subscription { get; set; }

[JsonProperty("subscription")]
internal object InternalSubscription
{
get
{
return this.Subscription ?? (object)this.SubscriptionId;
}

set
{
StringOrObject<Subscription>.Map(value, s => this.SubscriptionId = s, o => this.Subscription = o);
}
}
#endregion

/// <summary>
/// The URL the customer will be directed to after a successful payment.
/// </summary>
[JsonProperty("success_url")]
public string SuccessUrl { get; set; }
}
}
49 changes: 49 additions & 0 deletions src/Stripe.net/Entities/Checkout/Sessions/SessionDisplayItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace Stripe
{
using Newtonsoft.Json;

public class SessionDisplayItem : StripeEntity
{
/// <summary>
/// Amount for the display item.
/// </summary>
[JsonProperty("amount")]
public long? Amount { get; set; }

/// <summary>
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
/// </summary>
[JsonProperty("currency")]
public string Currency { get; set; }

/// <summary>
/// Details about the display item if it's of type custom.
/// </summary>
[JsonProperty("custom")]
public SessionDisplayItemCustom Custom { get; set; }

/// <summary>
/// The Plan if the display item is of type plan.
/// </summary>
[JsonProperty("plan")]
public Plan Plan { get; set; }

/// <summary>
/// Quantity of the display item being purchased.
/// </summary>
[JsonProperty("quantity")]
public long? Quantity { get; set; }

/// <summary>
/// The Sku if the display item is of type sku.
/// </summary>
[JsonProperty("sku")]
public Sku Sku { get; set; }

/// <summary>
/// The type of display item.
/// </summary>
[JsonProperty("type")]
public string Type { 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 SessionDisplayItemCustom : StripeEntity
{
/// <summary>
/// The description of the line item.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }

/// <summary>
/// The images of the line item.
/// </summary>
[JsonProperty("images")]
public List<string> Images { get; set; }

/// <summary>
/// The name of the line item.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Stripe.net/Infrastructure/StripeTypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal static class StripeTypeRegistry
{ "bank_account", typeof(BankAccount) },
{ "card", typeof(Card) },
{ "charge", typeof(Charge) },
{ "checkout.session", typeof(Checkout.Session) },
{ "country_spec", typeof(CountrySpec) },
{ "coupon", typeof(Coupon) },
{ "customer", typeof(Customer) },
Expand Down
86 changes: 86 additions & 0 deletions src/Stripe.net/Services/Checkout/SessionCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
namespace Stripe.Checkout
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class SessionCreateOptions : BaseOptions
{
/// <summary>
/// Specify whether Checkout should collect the customer’s billing address. If set to
/// <c>required</c>, Checkout will always collect the customer’s billing address. If left
/// blank or set to <c>auto</c> Checkout will only collect the billing address when
/// necessary.
/// </summary>
[JsonProperty("billing_address_collection")]
public string BillingAddressCollection { get; set; }

/// <summary>
/// The URL the customer will be directed to if they decide to go back to your website.
/// </summary>
[JsonProperty("cancel_url")]
public string CancelUrl { get; set; }

/// <summary>
/// A unique string to reference the Checkout Session. This can be a customer ID, a cart
/// ID, or similar. It is included in the <c>checkout.session.completed</c> webhook and can
/// be used to fulfill the purchase.
/// </summary>
[JsonProperty("client_reference_id")]
public string ClientReferenceId { get; set; }

/// <summary>
/// The email address used to create the customer object. If you already know your
/// customer’s email address, use this attribute to prefill it on Checkout.
/// </summary>
[JsonProperty("customer_email")]
public string CustomerEmail { get; set; }

/// <summary>
/// ID of the customer this Checkout Session is for if one exists. May only be used with
/// <c>LineItems</c>. Usage with <c>SubscriptionData</c> is not yet available.
/// </summary>
[JsonProperty("customer")]
public string CustomerId { get; set; }

/// <summary>
/// A list of items your customer is purchasing.
/// </summary>
[JsonProperty("line_items")]
public List<SessionLineItemOptions> LineItems { get; set; }

/// <summary>
/// The IETF language tag of the locale Checkout is displayed in. If blank or <c>auto</c>,
/// the browser’s locale is used.
/// </summary>
[JsonProperty("locale")]
public string Locale { get; set; }

/// <summary>
/// The list of payment method types (e.g. card) that this Checkout Session is allowed to
/// use.
/// </summary>
[JsonProperty("payment_intent_data")]
public SessionPaymentIntentDataOptions PaymentIntentData { get; set; }

/// <summary>
/// The list of payment method types (e.g. card) that this Checkout Session is allowed to
/// use.
/// </summary>
[JsonProperty("payment_method_types")]
public List<string> PaymentMethodTypes { get; set; }

/// <summary>
/// A subset of parameters to be passed to subscription creation.
/// </summary>
[JsonProperty("subscription_data")]
public SessionSubscriptionDataOptions SubscriptionData { get; set; }

/// <summary>
/// The URL the customer will be directed to after a successful payment.
/// </summary>
[JsonProperty("success_url")]
public string SuccessUrl { get; set; }
}
}
44 changes: 44 additions & 0 deletions src/Stripe.net/Services/Checkout/SessionLineItemOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Stripe.Checkout
{
using System.Collections.Generic;
using Newtonsoft.Json;

public class SessionLineItemOptions : INestedOptions
{
/// <summary>
/// Per item amount to be collected
/// </summary>
[JsonProperty("amount")]
public long? Amount { get; set; }

/// <summary>
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
/// </summary>
[JsonProperty("currency")]
public string Currency { get; set; }

/// <summary>
/// The description for the line item.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }

/// <summary>
/// A list of images representing this line item.
/// </summary>
[JsonProperty("images")]
public List<string> Images { get; set; }

/// <summary>
/// The name for the line item.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Quantity of the line item being purchased.
/// </summary>
[JsonProperty("quantity")]
public long? Quantity { get; set; }
}
}
Loading

0 comments on commit 6f5d071

Please sign in to comment.