Skip to content

Commit

Permalink
Merge pull request #27 from vapor-community/5.0.0
Browse files Browse the repository at this point in the history
5.0.0
  • Loading branch information
Andrewangeta authored Jan 6, 2020
2 parents 7b99ff8 + 2bbac30 commit e9046e5
Show file tree
Hide file tree
Showing 59 changed files with 1,209 additions and 69 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
### StripeKit is a Swift package used to communicate with the [Stripe](https://stripe.com) API for Server Side Swift Apps.

## Current supported version
Version **4.0.0** of StripeKit supports the Stripe API version of **[2019-11-05](https://stripe.com/docs/upgrades#2019-11-05)**.
Version **5.0.0** of StripeKit supports the Stripe API version of **[2019-12-03](https://stripe.com/docs/upgrades#2019-12-03)**.
**You can check the releases page to use a version of StripeKit that meets your needs.**

## Installation
To start using StripeKit, in your `Package.swift`, add the following

~~~~swift
.package(url: "https://github.com/vapor-community/stripekit.git", from: "4.0.0")
.package(url: "https://github.com/vapor-community/stripekit.git", from: "5.0.0")
~~~~

## Using the API
Expand Down Expand Up @@ -108,6 +108,22 @@ None of the API calls throw errors. Instead each route returns a successful `Eve
}
~~~

## Vapor Integration
To use StripeKit with Vapor 4.x, add a simple extension on `Request`.
~~~swift
extension Request {
public var stripe: StripeClient {
return StripeClient(httpClient: self.application.client.http, eventLoop: self.eventLoop, apiKey: "STRIPE_API_KEY")
}
}

// Later...

func charge(req: Request) -> EventLoopFuture<Response> {
return req.stripe.charge(...)
}
~~~

## Whats Implemented

### Core Resources
Expand All @@ -116,7 +132,7 @@ None of the API calls throw errors. Instead each route returns a successful `Eve
* [x] Charges
* [x] Customers
* [x] Disputes
* [ ] Events
* [x] Events
* [x] Files
* [x] File Links
* [x] Mandates
Expand Down Expand Up @@ -148,6 +164,7 @@ None of the API calls throw errors. Instead each route returns a successful `Eve
* [x] Products
* [x] Subscriptions
* [x] Subscription items
* [x] Subscription Schedule
* [x] Tax Rates
* [x] Usage Records
---
Expand Down Expand Up @@ -197,7 +214,7 @@ None of the API calls throw errors. Instead each route returns a successful `Eve
* [x] Report Types
---
### Webhooks
* [ ] Webhook Endpoints
* [x] Webhook Endpoints


## TODO At some point
Expand Down
2 changes: 1 addition & 1 deletion Sources/StripeKit/Billing/Coupons/Coupon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct StripeCoupon: StripeModel {
/// Amount (in the `currency` specified) that will be taken off the subtotal of any invoices for this customer.
public var amountOff: Int?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date?
public var created: Date
/// If amount_off has been set, the three-letter ISO code for the currency of the amount to take off.
public var currency: StripeCurrency?
/// One of `forever`, `once`, and `repeating`. Describes how long a customer who applies this coupon will get the discount.
Expand Down
2 changes: 1 addition & 1 deletion Sources/StripeKit/Billing/Credit Notes/CreditNote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct StripeCreditNote: StripeModel {
/// The integer amount in cents representing the total amount of the credit note.
public var amount: Int?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date?
public var created: Date
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
public var currency: StripeCurrency?
/// ID of the customer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct StripeCustomerBalanceTransaction: StripeModel {
/// The amount of the transaction. A negative value is a credit for the customer’s balance, and a positive value is a debit to the customer’s balance.
public var amount: Int?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date?
public var created: Date
/// The ID of the credit note (if any) related to the transaction.
public var creditNote: String?
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
Expand Down
2 changes: 1 addition & 1 deletion Sources/StripeKit/Billing/Customer Tax IDs/TaxID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct StripeTaxID: StripeModel {
/// Two-letter ISO code representing the country of the tax ID.
public var country: String?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date?
public var created: Date
/// ID of the customer.
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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/StripeKit/Billing/Invoices/Invoice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct StripeInvoice: StripeModel {
/// 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.
public var collectionMethod: StripeInvoiceCollectionMethod?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date?
public var created: Date
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
public var currency: StripeCurrency?
/// Custom fields displayed on the invoice.
Expand Down
2 changes: 1 addition & 1 deletion Sources/StripeKit/Billing/Plans/Plans.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct StripePlan: StripeModel {
/// Describes how to compute the price per period. Either `per_unit` or `tiered`. `per_unit` indicates that the fixed amount (specified in `amount`) will be charged per unit in `quantity` (for plans with `usage_type=licensed`), or per unit of total usage (for plans with `usage_type=metered`). `tiered` indicates that the unit pricing will be computed using a tiering strategy as defined using the `tiers` and `tiers_mode` attributes.
public var billingScheme: StripePlanBillingScheme?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date?
public var created: Date
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
public var currency: StripeCurrency?
/// One of `day`, `week`, `month` or `year`. The frequency with which a subscription should be billed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct StripeSubscriptionItem: StripeModel {
/// Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period
public var billingThresholds: StripeSubscriptionItemBillingThresholds?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date?
public var created: Date
/// 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.
public var metadata: [String: String]?
/// Hash describing the plan the customer is subscribed to.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// SubscriptionSchedule.swift
//
//
// Created by Andrew Edwards on 1/2/20.
//

import Foundation

/// The [Schedule Object](https://stripe.com/docs/api/subscription_schedules/object)
public struct StripeSubscriptionSchedule: 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 subscription schedule was canceled. Measured in seconds since the Unix epoch.
public var canceledAt: Date?
/// Time at which the subscription schedule was completed. Measured in seconds since the Unix epoch.
public var completedAt: Date?
/// Time at which the object was created. Measured in seconds since the Unix epoch.
public var created: Date
/// Object representing the start and end dates for the current phase of the subscription schedule, if it is active.
public var currentPhase: StripeSubscriptionScheduleCurrentPhase?
/// ID of the customer who owns the subscription schedule.
public var customer: String?
/// Object representing the subscription schedule’s default settings.
public var defaultSettings: StripeSubscriptionScheduleDefaultSettings?
/// Behavior of the subscription schedule and underlying subscription when it ends.
public var endBehavior: 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?
/// 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.
public var metadata: [String: String]?
/// Configuration for the subscription schedule’s phases.
public var phases: [StripeSubscriptionSchedulePhase]?
/// Time at which the subscription schedule was released. Measured in seconds since the Unix epoch.
public var releasedAt: Date?
/// ID of the subscription once managed by the subscription schedule (if it is released).
public var releasedSubscription: String?
/// The present status of the subscription schedule. Possible values are not_started, active, completed, released, and canceled. You can read more about the different states in our behavior guide.
public var status: StripeSubscriptionScheduleStatus?
/// ID of the subscription managed by the subscription schedule.
public var subscription: String?
}

public struct StripeSubscriptionScheduleCurrentPhase: StripeModel {
/// timestamp
public var endDate: Date?
/// timestamp
public var startDate: Date?
}

public struct StripeSubscriptionScheduleDefaultSettings: StripeModel {
/// Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period
public var billingThresholds: StripeSubscriptionBillingThresholds?
/// Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay the underlying subscription at the end of each billing cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions.
public var collectionMethod: StripeInvoiceCollectionMethod?
/// ID of the default payment method for the subscription schedule. If not set, invoices will use the default payment method in the customer’s invoice settings.
public var defaultPaymentMethod: String?
/// The subscription schedule’s default invoice settings.
public var invoiceSettings: StripeSubscriptionScheduleInvoiceSettings?
}

public struct StripeSubscriptionScheduleInvoiceSettings: StripeModel {
/// Number of days within which a customer must pay invoices generated by this subscription schedule. This value will be `null` for subscription schedules where `billing=charge_automatically`.
public var daysUntilDue: Int?
}

public struct StripeSubscriptionSchedulePhase: StripeModel {
/// A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice subtotal that will be transferred to the application owner’s Stripe account during this phase of the schedule.
public var applicationFeePercent: Decimal?
/// Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period
public var billingThresholds: StripeSubscriptionBillingThresholds?
/// Either charge_automatically, or send_invoice. When charging automatically, Stripe will attempt to pay the underlying subscription at the end of each billing cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions.
public var collectionMethod: StripeInvoiceCollectionMethod?
/// ID of the coupon to use during this phase of the subscription schedule.
public var coupon: String?
/// ID of the default payment method for the subscription schedule. It must belong to the customer associated with the subscription schedule. If not set, invoices will use the default payment method in the customer’s invoice settings.
public var defaultPaymentMethod: String?
///
public var defaultTaxRates: [StripeTaxRate]?
/// The end of this phase of the subscription schedule.
public var endDate: Date?
/// The subscription schedule’s default invoice settings.
public var invoiceSettings: StripeSubscriptionScheduleInvoiceSettings?
/// Plans to subscribe during this phase of the subscription schedule.
public var plans: [StripePlan]?
/// The start of this phase of the subscription schedule.
public var startDate: Date?
/// When the trial ends within the phase.
public var trialEnd: Date?
}

public enum StripeSubscriptionScheduleStatus: String, StripeModel {
case notStarted = "not_started"
case active
case completed
case released
case canceled
}

public struct StripeSubscriptionScheduleList: StripeModel {
public var object: String
public var hasMore: Bool
public var url: String?
public var data: [StripeSubscriptionSchedule]?
}
Loading

0 comments on commit e9046e5

Please sign in to comment.