Skip to content

Commit

Permalink
API updates and support for quotes and verification APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewangeta committed Aug 2, 2021
1 parent 9ab8c28 commit be61a70
Show file tree
Hide file tree
Showing 37 changed files with 2,282 additions and 109 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 13.0.0 - 2021-08-01
* [#133](https://github.com/vapor-community/stripe-kit/pull/133)
* ⚠️ Breaking changes ⚠️ Multiple API updates.
* Adds support for `Quotes` and `QuoteLineItems`
* Adds support for `VerificationSessions` and `VerificationReports`

## 12.0.2 - 2021-04-29
* [#125](https://github.com/vapor-community/stripe-kit/pull/125) Added payment method models.

Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
To start using StripeKit, in your `Package.swift`, add the following

~~~~swift
.package(url: "https://github.com/vapor-community/stripe-kit.git", from: "12.0.0")
.package(url: "https://github.com/vapor-community/stripe-kit.git", from: "13.0.0")
~~~~

## Using the API
Expand Down Expand Up @@ -230,8 +230,6 @@ See the [Vapor helper library](https://github.com/vapor-community/stripe) to use
* [x] SetupIntents
* [x] SetupAttempts
* [x] Payouts
* [x] Prices
* [x] Products
* [x] Refunds
* [x] Tokens
---
Expand All @@ -241,25 +239,30 @@ See the [Vapor helper library](https://github.com/vapor-community/stripe) to use
* [x] Cards
* [x] Sources
---
### Products
* [x] Products
* [x] Prices
* [x] Coupons
* [x] Promotion Codes
* [x] Discounts
* [x] Tax Rates
---
### Checkout
* [x] Sessions
---
### Billing
* [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] Quotes
* [x] Quote Line Items
* [x] Subscriptions
* [x] Subscription items
* [x] Subscription Schedule
* [x] Tax Rates
* [x] Usage Records
---
### Connect
Expand Down Expand Up @@ -307,6 +310,10 @@ See the [Vapor helper library](https://github.com/vapor-community/stripe) to use
* [x] Report Runs
* [x] Report Types
---
### Identity
* [x] VerificationSessions
* [x] VerificationReports
---
### Webhooks
* [x] Webhook Endpoints
* [x] Signature Verification
Expand Down
2 changes: 2 additions & 0 deletions Sources/StripeKit/Billing/Invoices/Invoice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public struct StripeInvoice: StripeModel {
public var postPaymentCreditNotesAmount: Int?
/// Total amount of all pre-payment credit notes issued for this invoice.
public var prePaymentCreditNotesAmount: Int?
/// The quote this invoice was generated from.
@Expandable<StripeQuote> public var quote: String?
/// This is the transaction number that appears on email receipts sent for this invoice.
public var receiptNumber: String?
/// Starting customer balance before the invoice is finalized. If the invoice has not been finalized yet, this will be the current customer balance.
Expand Down
4 changes: 2 additions & 2 deletions Sources/StripeKit/Billing/Invoices/InvoiceRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public protocol InvoiceRoutes {
/// - applicationFeeAmount: A fee in cents that will be applied to the invoice and transferred to the application owner’s Stripe account. The request must be made with an OAuth key or the Stripe-Account header in order to take an application fee. For more information, see the application fees documentation.
/// - autoAdvance: Controls whether Stripe will perform automatic collection of the invoice.
/// - collectionMethod: Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay this invoice using the default source attached to the customer. When sending an invoice, Stripe will email this invoice to the customer with payment instructions. Defaults to `charge_automatically`.
/// - customFields: A list of up to 4 custom fields to be displayed on the invoice. If a value for custom_fields is specified, the list specified will replace the existing custom field list on this invoice.
/// - daysUntilDue: The number of days from which the invoice is created until it is due. Only valid for invoices where billing=send_invoice. This field can only be updated on draft invoices.
/// - customFields: A list of up to 4 custom fields to be displayed on the invoice. If a value for `custom_fields` is specified, the list specified will replace the existing custom field list on this invoice.
/// - daysUntilDue: The number of days from which the invoice is created until it is due. Only valid for invoices where `billing=send_invoice`. This field can only be updated on draft invoices.
/// - defaultPaymentMethod: ID of the default payment method for the invoice. It must belong to the customer associated with the invoice. If not set, defaults to the subscription’s default payment method, if any, or to the default payment method in the customer’s invoice settings.
/// - defaultSource: ID of the default payment source for the invoice. It must belong to the customer associated with the invoice and be in a chargeable state. If not set, defaults to the subscription’s default source, if any, or to the customer’s default source.
/// - defaultTaxRates: The tax rates that will apply to any line item that does not have `tax_rates` set. Pass an empty string to remove previously-defined tax rates.
Expand Down
54 changes: 54 additions & 0 deletions Sources/StripeKit/Billing/Quote Line Items/QuoteLineItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// QuoteLineItem.swift
// StripeKit
//
// Created by Andrew Edwards on 7/25/21.
//

import Foundation

public struct StripeQuoteLineItem: 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
/// Total before any discounts or taxes are applied.
public var amountSubtotal: Int?
/// Total after discounts and taxes.
public var amountTotal: Int?
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
public var currency: StripeCurrency?
/// An arbitrary string attached to the object. Often useful for displaying to users. Defaults to product name.
public var description: String?
/// This field is not included by default. To include it in the response, expand the `discounts` field.
public var discounts: [StripeQuoteLineItemDiscount]?
/// The price used to generate the line item.
public var price: StripePrice?
/// The quantity of products being purchased.
public var quantity: Int?
/// The taxes applied to the line item.
///
/// This field is not included by default. To include it in the response, expand the `taxes` field.
public var taxes: [StripeQuoteLineItemTax]?
}

public struct StripeQuoteLineItemDiscount: StripeModel {
/// The amount discounted.
public var amount: Int?
/// The discount applied.
public var discount: StripeDiscount?
}

public struct StripeQuoteLineItemTax: StripeModel {
/// Amount of tax applied for this rate.
public var amount: Int?
/// The tax rate applied.
public var rate: StripeTaxRate?
}

public struct StripeQuoteLineItemList: StripeModel {
public var object: String
public var hasMore: Bool?
public var url: String?
public var data: [StripeQuoteLineItem]?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// QuoteLineItemRoutes.swift
// StripeKit
//
// Created by Andrew Edwards on 7/25/21.
//

import NIO
import NIOHTTP1

public protocol QuoteLineItemRoutes {
/// When retrieving a quote, there is an includable `line_items` property containing the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items.
/// - Parameter quote: The ID of the quote
/// - Parameter filter: A dictionary that will be used for the query parameters.
/// - Returns: A `StripeQuoteLineItemList`.
func retrieve(quote: String, filter: [String: Any]?) -> EventLoopFuture<StripeQuoteLineItemList>

/// When retrieving a quote, there is an includable `upfront.line_items` property containing the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of upfront line items.
/// - Parameter quote: The ID of the quote
/// - Parameter filter: A dictionary that will be used for the query parameters.
/// - Returns: A `StripeQuoteLineItemList`.
func retrieveUpfront(quote: String, filter: [String: Any]?) -> EventLoopFuture<StripeQuoteLineItemList>

/// Headers to send with the request.
var headers: HTTPHeaders { get set }
}

extension QuoteLineItemRoutes {
public func retrieve(quote: String, filter: [String: Any]? = nil) -> EventLoopFuture<StripeQuoteLineItemList> {
retrieve(quote: quote, filter: filter)
}

public func retrieveUpfront(quote: String, filter: [String: Any]? = nil) -> EventLoopFuture<StripeQuoteLineItemList> {
retrieveUpfront(quote: quote, filter: filter)
}
}

public struct StripeQuoteLineItemRoutes: QuoteLineItemRoutes {
public var headers: HTTPHeaders = [:]

private let apiHandler: StripeAPIHandler
private let quotelineitems = APIBase + APIVersion + "quotes"

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

public func retrieve(quote: String, filter: [String: Any]?) -> EventLoopFuture<StripeQuoteLineItemList> {
var queryParams = ""
if let filter = filter {
queryParams = filter.queryParameters
}

return apiHandler.send(method: .GET, path: "\(quotelineitems)/\(quote)/line_items", query: queryParams, headers: headers)
}

public func retrieveUpfront(quote: String, filter: [String: Any]?) -> EventLoopFuture<StripeQuoteLineItemList> {
var queryParams = ""
if let filter = filter {
queryParams = filter.queryParameters
}

return apiHandler.send(method: .GET, path: "\(quotelineitems)/\(quote)/computed_upfront_line_items", query: queryParams, headers: headers)
}
}
Loading

0 comments on commit be61a70

Please sign in to comment.