-
Notifications
You must be signed in to change notification settings - Fork 571
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the Checkout Session resource
- Loading branch information
1 parent
cb9318c
commit abbf853
Showing
11 changed files
with
240 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Stripe.net/Entities/CheckoutSessions/CheckoutSession.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Stripe | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Stripe.Infrastructure; | ||
|
||
public class CheckoutSession : StripeEntity, IHasId, IHasObject | ||
{ | ||
[JsonProperty("id")] | ||
public string Id { get; set; } | ||
|
||
[JsonProperty("object")] | ||
public string Object { get; set; } | ||
|
||
[JsonProperty("livemode")] | ||
public bool Livemode { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/Stripe.net/Services/CheckoutSessions/CheckoutSessionCreateOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Stripe | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Stripe.Infrastructure; | ||
|
||
public class CheckoutSessionCreateOptions : BaseOptions | ||
{ | ||
[JsonProperty("allowed_source_types")] | ||
public List<string> AllowedSourceTypes { get; set; } | ||
|
||
[JsonProperty("cancel_url")] | ||
public string CancelUrl { get; set; } | ||
|
||
[JsonProperty("client_reference_id")] | ||
public string ClientReferenceId { get; set; } | ||
|
||
[JsonProperty("line_items")] | ||
public List<CheckoutSessionLineItemOptions> LineItems { get; set; } | ||
|
||
[JsonProperty("payment_intent_data")] | ||
public CheckoutSessionPaymentIntentDataOptions PaymentIntentData { get; set; } | ||
|
||
[JsonProperty("success_url")] | ||
public string SuccessUrl { get; set; } | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Stripe.net/Services/CheckoutSessions/CheckoutSessionLineItemOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 CheckoutSessionLineItemOptions : INestedOptions | ||
{ | ||
[JsonProperty("amount")] | ||
public long? Amount { get; set; } | ||
|
||
[JsonProperty("currency")] | ||
public string Currency { get; set; } | ||
|
||
[JsonProperty("description")] | ||
public string Description { get; set; } | ||
|
||
[JsonProperty("images")] | ||
public List<string> Images { get; set; } | ||
|
||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonProperty("quantity")] | ||
public long? Quantity { get; set; } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Stripe.net/Services/CheckoutSessions/CheckoutSessionPaymentIntentDataOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 CheckoutSessionPaymentIntentDataOptions : INestedOptions | ||
{ | ||
[JsonProperty("description")] | ||
public string Description { get; set; } | ||
|
||
[JsonProperty("metadata")] | ||
public Dictionary<string, string> Metadata { get; set; } | ||
|
||
[JsonProperty("receipt_email")] | ||
public string ReceiptEmail { get; set; } | ||
|
||
[JsonProperty("shipping")] | ||
public ChargeShippingOptions Shipping { get; set; } | ||
|
||
[JsonProperty("statement_descriptor")] | ||
public string StatementDescriptor { get; set; } | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Stripe.net/Services/CheckoutSessions/CheckoutSessionService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Stripe | ||
{ | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Stripe.Infrastructure; | ||
|
||
public class CheckoutSessionService : Service<CheckoutSession>, | ||
ICreatable<CheckoutSession, CheckoutSessionCreateOptions> | ||
{ | ||
public CheckoutSessionService() | ||
: base(null) | ||
{ | ||
} | ||
|
||
public CheckoutSessionService(string apiKey) | ||
: base(apiKey) | ||
{ | ||
} | ||
|
||
public override string BasePath => "/checkout_sessions"; | ||
|
||
public virtual CheckoutSession Create(CheckoutSessionCreateOptions options, RequestOptions requestOptions = null) | ||
{ | ||
return this.CreateEntity(options, requestOptions); | ||
} | ||
|
||
public virtual Task<CheckoutSession> CreateAsync(CheckoutSessionCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return this.CreateEntityAsync(options, requestOptions, cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace StripeTests | ||
{ | ||
using Newtonsoft.Json; | ||
using Stripe; | ||
using Xunit; | ||
|
||
public class CheckoutSessionTest : BaseStripeTest | ||
{ | ||
[Fact] | ||
public void Deserialize() | ||
{ | ||
var json = GetResourceAsString("api_fixtures.checkout_session.json"); | ||
var session = JsonConvert.DeserializeObject<CheckoutSession>(json); | ||
Assert.NotNull(session); | ||
Assert.IsType<CheckoutSession>(session); | ||
Assert.NotNull(session.Id); | ||
Assert.Equal("checkout_session", session.Object); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "randomid", | ||
"object": "checkout_session", | ||
"livemode": false | ||
} |
82 changes: 82 additions & 0 deletions
82
src/StripeTests/Services/CheckoutSessions/CheckoutSessionServiceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
namespace StripeTests | ||
{ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
using Stripe; | ||
using Xunit; | ||
|
||
public class CheckoutSessionServiceTest : BaseStripeTest | ||
{ | ||
private CheckoutSessionService service; | ||
private CheckoutSessionCreateOptions createOptions; | ||
|
||
public CheckoutSessionServiceTest() | ||
{ | ||
this.service = new CheckoutSessionService(); | ||
|
||
this.createOptions = new CheckoutSessionCreateOptions | ||
{ | ||
AllowedSourceTypes = new List<string> | ||
{ | ||
"card", | ||
}, | ||
CancelUrl = "https://stripe.con/cancel", | ||
ClientReferenceId = "1234", | ||
LineItems = new List<CheckoutSessionLineItemOptions> | ||
{ | ||
new CheckoutSessionLineItemOptions | ||
{ | ||
Amount = 1234, | ||
Currency = "usd", | ||
Description = "item1", | ||
Images = new List<string> | ||
{ | ||
"https://stripe.com/image1", | ||
}, | ||
Name = "item name", | ||
Quantity = 2, | ||
}, | ||
}, | ||
PaymentIntentData = new CheckoutSessionPaymentIntentDataOptions | ||
{ | ||
Description = "description", | ||
Shipping = new ChargeShippingOptions | ||
{ | ||
Name = "name", | ||
Phone = "555-555-5555", | ||
Address = new AddressOptions | ||
{ | ||
State = "CA", | ||
City = "City", | ||
Line1 = "Line1", | ||
Line2 = "Line2", | ||
PostalCode = "90210", | ||
Country = "US", | ||
}, | ||
} | ||
}, | ||
SuccessUrl = "https://stripe.con/success", | ||
}; | ||
} | ||
|
||
[Fact] | ||
public void Create() | ||
{ | ||
var session = this.service.Create(this.createOptions); | ||
this.AssertRequest(HttpMethod.Post, "/v1/checkout_sessions"); | ||
Assert.NotNull(session); | ||
Assert.Equal("checkout_session", session.Object); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateAsync() | ||
{ | ||
var session = await this.service.CreateAsync(this.createOptions); | ||
this.AssertRequest(HttpMethod.Post, "/v1/checkout_sessions"); | ||
Assert.NotNull(session); | ||
Assert.Equal("checkout_session", session.Object); | ||
} | ||
} | ||
} |