Skip to content

Commit

Permalink
Merge pull request #29 from vapor-community/rc1.2
Browse files Browse the repository at this point in the history
Added CodingKeys enum
  • Loading branch information
Andrewangeta authored Apr 1, 2018
2 parents 9bf4ba8 + ea8ce3a commit 9b4960b
Show file tree
Hide file tree
Showing 84 changed files with 964 additions and 120 deletions.
25 changes: 0 additions & 25 deletions .circleci/config.yml

This file was deleted.

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Swift](http://img.shields.io/badge/swift-4.1-brightgreen.svg)
![Vapor](http://img.shields.io/badge/vapor-3.0-brightgreen.svg)
[![CircleCI](https://circleci.com/gh/vapor-community/stripe-provider/tree/beta.svg?style=svg)](https://circleci.com/gh/vapor-community/stripe-provider/tree/beta)
[![CircleCI](https://circleci.com/gh/vapor-community/stripe-provider/tree/beta.svg?style=svg)](https://circleci.com/gh/vapor-community/stripe-provider)

[Stripe][stripe_home] is a payment platform that handles credit cards, bitcoin and ACH transfers. They have become one of the best platforms for handling payments for projects, services or products.

Expand Down Expand Up @@ -47,10 +47,6 @@ futureCharge.do({ (charge) in

And you can always check the documentation to see the required paramaters for specific API calls.

## Linux compatibility
Currently the project won't compile for linux.
You can track this issue [here](https://bugs.swift.org/browse/SR-7180) and [here](https://github.com/apple/swift-corelibs-foundation/pull/1347)

## Whats Implemented

### Core Resources
Expand Down
5 changes: 2 additions & 3 deletions Sources/Stripe/API/StripeRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ public extension StripeRequest {
public func serializedResponse<SM: StripeModel>(response: HTTPResponse, worker: EventLoop) throws -> Future<SM> {
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970
decoder.keyDecodingStrategy = .convertFromSnakeCase

guard response.status == .ok else {
return try decoder.decode(StripeAPIError.self, from: response.body, on: worker).map(to: SM.self) { error in
return try decoder.decode(StripeAPIError.self, from: response.body, maxSize: 65_536, on: worker).map(to: SM.self) { error in
throw StripeError.apiError(error)
}
}

return try decoder.decode(SM.self, from: response.body, on: worker)
return try decoder.decode(SM.self, from: response.body, maxSize: 65_536, on: worker)
}
}

Expand Down
9 changes: 9 additions & 0 deletions Sources/Stripe/Errors/StripeAPIError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public struct StripeAPIErrorBody: APIError, StripeModel {
public var code: StripeAPICardErrorType?
public var declineCode: StripeAPIDeclineCode?
public var param: String?

public enum CodingKeys: CodingKey, String {
case type
case charge
case message
case code
case declineCode = "decline_code"
case param
}
}

public struct StripeAPIError: StripeModel {
Expand Down
5 changes: 5 additions & 0 deletions Sources/Stripe/Helpers/CodeVerification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
public struct CodeVerification: StripeModel {
public var attemptsRemaining: Int?
public var status: StripeStatus?

public enum CodingKeys: CodingKey, String {
case attemptsRemaining = "attempts_remaining"
case status
}
}
8 changes: 8 additions & 0 deletions Sources/Stripe/Models/Balance/Balance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ public struct StripeBalance: Balance, StripeModel {
public var connectReserved: [StripeBalanceTransfer]?
public var livemode: Bool?
public var pending: [StripeBalanceTransfer]?

public enum CodingKeys: CodingKey, String {
case object
case available
case connectReserved = "connect_reserved"
case livemode
case pending
}
}
8 changes: 8 additions & 0 deletions Sources/Stripe/Models/Balance/BalanceHistoryList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ public struct BalanceHistoryList: List, StripeModel {
public var totalCount: Int?
public var url: String?
public var data: [StripeBalance]?

public enum CodingKeys: CodingKey, String {
case object
case hasMore = "has_more"
case totalCount = "total_count"
case url
case data
}
}
17 changes: 17 additions & 0 deletions Sources/Stripe/Models/Balance/BalanceTransactionItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,21 @@ public struct StripeBalanceTransactionItem: BalanceTransactionItem, StripeModel
public var source: String?
public var status: StripeStatus?
public var type: BalanceTransactionType?

public enum CodingKeys: CodingKey, String {
case id
case object
case amount
case availableOn = "available_on"
case created
case currency
case exchangeRate = "exchange_rate"
case description
case fee
case feeDetails = "fee_details"
case net
case source
case status
case type
}
}
6 changes: 6 additions & 0 deletions Sources/Stripe/Models/Balance/BalanceTransfer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public struct StripeBalanceTransfer: BalanceTransfer, StripeModel {
public var currency: StripeCurrency?
public var amount: Int?
public var sourceTypes: [String: Int]?

public enum CodingKeys: CodingKey, String {
case currency
case amount
case sourceTypes = "source_types"
}
}
39 changes: 39 additions & 0 deletions Sources/Stripe/Models/Charges/Charge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,43 @@ public struct StripeCharge: Charge, StripeModel {
public var status: StripeStatus?
public var transfer: String?
public var transferGroup: String?

public enum CodingKeys: CodingKey, String {
case id
case object
case amount
case amountRefunded = "amount_refunded"
case application
case applicationFee = "application_fee"
case balanceTransaction = "balance_transaction"
case captured
case created
case currency
case customer
case description
case destination
case dispute
case failureCode = "failure_code"
case failureMessage = "failure_message"
case fraudDetails = "fraud_details"
case invoice
case livemode
case metadata
case onBehalfOf = "on_behalf_of"
case order
case outcome
case paid
case receiptEmail = "receipt_email"
case receiptNumber = "receipt_number"
case refunded
case refunds
case review
case shipping
case source
case sourceTransfer = "source_transfer"
case statementDescriptor = "statement_descriptor"
case status
case transfer
case transferGroup = "transfer_group"
}
}
8 changes: 8 additions & 0 deletions Sources/Stripe/Models/Charges/ChargeList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ public struct ChargesList: List, StripeModel {
public var totalCount: Int?
public var url: String?
public var data: [StripeCharge]?

public enum CodingKeys: CodingKey, String {
case object
case hasMore = "has_more"
case totalCount = "total_count"
case url
case data
}
}
5 changes: 5 additions & 0 deletions Sources/Stripe/Models/Charges/FruadDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public protocol FraudDetails {
public struct StripeFraudDetails: FraudDetails, StripeModel {
public var userReport: FraudReport?
public var stripeReport: FraudReport?

public enum CodingKeys: CodingKey, String {
case userReport = "user_report"
case stripeReport = "stripe_report"
}
}
9 changes: 9 additions & 0 deletions Sources/Stripe/Models/Charges/Outcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ public struct StripeOutcome: Outcome, StripeModel {
public var rule: String?
public var sellerMessage: String?
public var type: OutcomeType?

public enum CodingKeys: CodingKey, String {
case networkStatus = "network_status"
case reason
case riskLevel = "risk_level"
case rule
case sellerMessage = "seller_message"
case type
}
}
32 changes: 32 additions & 0 deletions Sources/Stripe/Models/Connect/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,36 @@ public struct StripeConnectAccount: ConnectAccount, StripeModel {
public var type: ConnectedAccountType?
public var verification: StripeAccountVerification?
public var transfersEnabled: Bool?

public enum CodingKeys: CodingKey, String {
case id
case object
case businessLogo = "business_logo"
case businessName = "business_name"
case businessUrl = "business_url"
case chargesEnabled = "charges_enabled"
case country
case created
case debitNegativeBalances = "debit_negative_balances"
case declineChargeOn = "decline_charge_on"
case defaultCurrency = "default_currency"
case detailsSubmitted = "details_submitted"
case displayName = "display_name"
case email
case externalAccounts = "external_accounts"
case legalEntity = "legal_entity"
case metadata
case payoutSchedule = "payout_schedule"
case payoutStatementDescriptor = "payout_statement_descriptor"
case payoutsEnabled = "payouts_enabled"
case productDescription = "product_description"
case statementDescriptor = "statement_descriptor"
case supportEmail = "support_email"
case supportPhone = "support_phone"
case timezone
case tosAcceptance = "tos_acceptance"
case type
case verification
case transfersEnabled = "transfers_enabled"
}
}
8 changes: 8 additions & 0 deletions Sources/Stripe/Models/Connect/AccountList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ public struct ConnectedAccountsList: List, StripeModel {
public var totalCount: Int?
public var url: String?
public var data: [StripeConnectAccount]?

public enum CodingKeys: CodingKey, String {
case object
case hasMore = "has_more"
case totalCount = "total_count"
case url
case data
}
}
6 changes: 6 additions & 0 deletions Sources/Stripe/Models/Connect/AccountVerification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public struct StripeAccountVerification: AccountVerification, StripeModel {
public var disabledReason: String?
public var dueBy: Date?
public var fieldsNeeded: [String]?

public enum CodingKeys: CodingKey, String {
case disabledReason = "disabled_reason"
case dueBy = "due_by"
case fieldsNeeded = "fields_needed"
}
}
10 changes: 10 additions & 0 deletions Sources/Stripe/Models/Connect/AdditionalOwner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public struct StripeLegalEntityAdditionalOwner: LegalEntityAdditionalOwner, Stri
public var personalIdNumberProvided: Bool?
public var address: StripeAddress?
public var verification: StripeLegalEntityVerification?

public enum CodingKeys: CodingKey, String {
case firstName = "first_name"
case lastName = "last_name"
case dob
case maidenName = "maiden_name"
case personalIdNumberProvided = "personal_id_number_provided"
case address
case verification
}
}
12 changes: 11 additions & 1 deletion Sources/Stripe/Models/Connect/ExternalAccounts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct ExternalAccountsList: StripeModel {
public var hasMore: Bool?
public var totalCount: Int?
public var url: String?
private var data: String?
public var data: String?
public var cardAccounts: [StripeCard]?
public var bankAccounts: [StripeBankAccount]?

Expand All @@ -29,6 +29,16 @@ public struct ExternalAccountsList: StripeModel {
cardAccounts = try container.decodeIfPresent([StripeCard].self, forKey: .data)?.filter{ $0.object == "card" }
bankAccounts = try container.decodeIfPresent([StripeBankAccount].self, forKey: .data)?.filter{ $0.object == "bank_account" }
}

public enum CodingKeys: String, CodingKey {
case object
case hasMore = "has_more"
case totalCount = "total_count"
case url
case data
case cardAccounts
case bankAccounts
}
}

public protocol ExternalAccount {}
10 changes: 10 additions & 0 deletions Sources/Stripe/Models/Connect/ExternalBankAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ public struct StripeExternalBankAccount: ExternalAccount, StripeModel {
public var accountHolderName: String?
public var accountHolderType: String?
public var routingNumber: String?

public enum CodingKeys: CodingKey, String {
case object
case accountNumber = "account_number"
case country
case currency
case accountHolderName = "account_holder_name"
case accountHolderType = "account_holder_type"
case routingNumber = "routing_number"
}
}
17 changes: 17 additions & 0 deletions Sources/Stripe/Models/Connect/ExternalCardAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,21 @@ public struct StripeExternalCardAccount: ExternalAccount, StripeModel {
public var cvc: String?
public var metadata: [String: String]?
public var name: String?

public enum CodingKeys: CodingKey, String {
case object
case defaultForCurrency = "default_for_currency"
case expMonth = "exp_month"
case expYear = "exp_year"
case number
case addressCity = "address_city"
case addressCountry = "address_country"
case addressLine1 = "address_line1"
case addressLine2 = "address_line2"
case addressState = "address_state"
case addressZip = "address_zip"
case cvc
case metadata
case name
}
}
20 changes: 20 additions & 0 deletions Sources/Stripe/Models/Connect/LegalEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,24 @@ public struct StripeConnectAccountLegalEntity: LegalEntity, StripeModel {
public var taxIdRegistrar: String?
public var type: String?
public var verification: StripeLegalEntityVerification?

public enum CodingKeys: CodingKey, String {
case additionalOwners = "additional_owners"
case address
case businessName = "business_name"
case businessTaxIdProvided = "business_tax_id_provided"
case businessVATIdProvided = "business_vat_id_provided"
case dob
case firstName = "first_name"
case lastName = "last_name"
case gender
case maidenName = "maiden_name"
case personalIdNumberProvided = "personal_id_number_provided"
case personalAddress = "personal_address"
case phoneNumber = "phone_number"
case ssnLast4Provided = "ssn_last_4_provided"
case taxIdRegistrar = "tax_id_registrar"
case type
case verification
}
}
Loading

0 comments on commit 9b4960b

Please sign in to comment.