Skip to content

Commit

Permalink
Added support for the Customer Portal API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewangeta committed Nov 28, 2020
1 parent 3b00439 commit b392d5f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog

## 10.1.0 - 2020-11-28
* [#113](https://github.com/vapor-community/stripe-kit/pull/113) Added support for [Customer Portal](https://stripe.com/docs/api/customer_portal) API.

## 10.0.0 - 2020-11-10
* [#122](https://github.com/vapor-community/stripe-kit/pull/112) Updated to latest 2020-08-27 API version.
* [#112](https://github.com/vapor-community/stripe-kit/pull/112) Updated to latest 2020-08-27 API version.

## 8.0.0 - 2020-07-21
* [#98](https://github.com/vapor-community/stripe-kit/pull/98) Added support for the `Price`s API.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ See the [Vapor helper library](https://github.com/vapor-community/stripe) to use
* [x] Mandates
* [x] PaymentIntents
* [x] SetupIntents
* [x] SetupAttempts
* [x] Payouts
* [x] Prices
* [x] Products
Expand All @@ -247,11 +248,13 @@ See the [Vapor helper library](https://github.com/vapor-community/stripe) to use
* [x] Coupons
* [x] Credit Notes
* [x] Customer Balance Transactions
* [x] Customer Portal
* [x] Customer Tax IDs
* [x] Discounts
* [x] Invoices
* [x] Invoice Items
* [x] Plans
* [x] Promotion Codes
* [x] Products
* [x] Subscriptions
* [x] Subscription items
Expand Down
25 changes: 25 additions & 0 deletions Sources/StripeKit/Billing/Customer Portal/CustomerSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// CustomerSession.swift
//
//
// Created by Andrew Edwards on 11/28/20.
//

import Foundation

public struct StripeCustomerSession: StripeModel {
/// Unique identifier for the object.
public var id: String
/// String representing the object’s type. Objects of the same type share the same value.
public var object: String?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date
/// The ID of the customer for this session.
public var customer: String?
/// Has the value true if the object exists in live mode or the value false if the object exists in test mode.
public var livemode: Bool?
/// The URL to which Stripe should send customers when they click on the link to return to your website.
public var returnUrl: String?
/// The short-lived URL of the session giving customers access to the customer portal.
public var url: String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// CustomerSessionRoutes.swift
//
//
// Created by Andrew Edwards on 11/28/20.
//

import NIO
import NIOHTTP1

public protocol CustomerSessionRoutes {

/// Creates a session of the customer portal.
/// - Parameters:
/// - customer: The ID of an existing customer.
/// - returnUrl: The URL to which Stripe should send customers when they click on the link to return to your website. This field is required if a default return URL has not been configured for the portal.
func create(customer: String, returnUrl: String?) -> EventLoopFuture<StripeCustomerSession>
}

extension CustomerSessionRoutes {
public func create(customer: String, returnUrl: String? = nil) -> EventLoopFuture<StripeCustomerSession> {
create(customer: customer, returnUrl: returnUrl)
}
}

public struct StripeCustomerSessionRoutes: CustomerSessionRoutes {
public var headers: HTTPHeaders = [:]

private let apiHandler: StripeAPIHandler
private let sessions = APIBase + APIVersion + "billing_portal/sessions"

init(apiHandler: StripeAPIHandler) {
self.apiHandler = apiHandler
}

public func create(customer: String, returnUrl: String?) -> EventLoopFuture<StripeCustomerSession> {
var body: [String: Any] = ["customer": customer]

if let returnUrl = returnUrl {
body["return_url"] = returnUrl
}

return apiHandler.send(method: .POST, path: sessions, body: .string(body.queryParameters))
}
}
2 changes: 2 additions & 0 deletions Sources/StripeKit/StripeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class StripeClient {
public var coupons: CouponRoutes
public var creditNotes: CreditNoteRoutes
public var customerBalanceTransactions: CustomerBalanceTransactionRoutes
public var customerSession: CustomerSessionRoutes
public var customerTaxIds: CustomerTaxIDRoutes
public var discounts: DiscountRoutes
public var invoices: InvoiceRoutes
Expand Down Expand Up @@ -137,6 +138,7 @@ public final class StripeClient {
coupons = StripeCouponRoutes(apiHandler: handler)
creditNotes = StripeCreditNoteRoutes(apiHandler: handler)
customerBalanceTransactions = StripeCustomerBalanceTransactionRoutes(apiHandler: handler)
customerSession = StripeCustomerSessionRoutes(apiHandler: handler)
customerTaxIds = StripeCustomerTaxIDRoutes(apiHandler: handler)
discounts = StripeDiscountRoutes(apiHandler: handler)
invoices = StripeInvoiceRoutes(apiHandler: handler)
Expand Down

0 comments on commit b392d5f

Please sign in to comment.