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 d69ada8
Show file tree
Hide file tree
Showing 13 changed files with 604 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/Stripe.net/Entities/Checkout/Sessions/Session.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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>
/// 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 ID of the customer created.
/// </summary>
[JsonProperty("customer")]
public string CustomerId { 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>
/// The email address used to create the customer object.
/// </summary>
[JsonProperty("customer_email")]
public string CustomerEmail { 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; }

/// <summary>
/// The ID of the PaymentIntent created if SKUs or line items were provided.
/// </summary>
[JsonProperty("payment_intent")]
public string PaymentIntentId { 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>
/// The ID of the subscription created if one or more plans were provided.
/// </summary>
[JsonProperty("subscription")]
public string SubscriptionId { get; set; }

/// <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>
/// 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>
/// 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>
/// 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>
/// 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>
/// 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>
/// 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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace Stripe.Checkout
{
using System.Collections.Generic;
using Newtonsoft.Json;

public class SessionPaymentIntentDataOptions : INestedOptions
{
/// <summary>
/// The amount of the application fee (if any) that will be applied to the payment and
/// transferred to the application owner’s Stripe account.
/// </summary>
[JsonProperty("application_fee_amount")]
public long? ApplicationFeeAmount { get; set; }

/// <summary>
/// Capture method of this PaymentIntent, one of <c>automatic</c> or <c>manual</c>.
/// </summary>
[JsonProperty("capture_method")]
public string CaptureMethod { get; set; }

/// <summary>
/// An arbitrary string attached to the object. Often useful for displaying to users.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }

/// <summary>
/// Set of key-value pairs that you can attach to an object. This can be useful for storing
/// additional information about the object in a structured format.
/// </summary>
[JsonProperty("metadata")]
public Dictionary<string, string> Metadata { get; set; }

/// <summary>
/// The Stripe account ID for which these funds are intended.
/// </summary>
[JsonProperty("on_behalf_of")]
public string OnBehalfOf { get; set; }

/// <summary>
/// Email address that the receipt for the resulting payment will be sent to.
/// </summary>
[JsonProperty("receipt_email")]
public string ReceiptEmail { get; set; }

/// <summary>
/// Shipping information for this payment.
/// </summary>
[JsonProperty("shipping")]
public ChargeShippingOptions Shipping { get; set; }

/// <summary>
/// Extra information about the payment. This will appear on your customer’s statement when
/// this payment succeeds in creating a charge.
/// </summary>
[JsonProperty("statement_descriptor")]
public string StatementDescriptor { get; set; }

/// <summary>
/// The parameters used to automatically create a Transfer when the payment succeeds.
/// </summary>
[JsonProperty("transfer_data")]
public SessionPaymentIntentTransferDataOptions TransferData { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Stripe
{
using System;
using Newtonsoft.Json;

public class SessionPaymentIntentTransferDataOptions : INestedOptions
{
[JsonProperty("destination")]
public string Destination { get; set; }
}
}
Loading

0 comments on commit d69ada8

Please sign in to comment.