Skip to content

Swe 12 enable payment suite #13

Merged
merged 14 commits into from Apr 8, 2019
Prev

SWE-12 use new date formatter

- several commits ago we created `careCreditDateFormatter`
- replace usage of regular `DateFormatter` which require setting of format style and locale in each instance to `static` property which automatically returns the date formatter we want
  • Loading branch information
ahm11003 committed Apr 5, 2019
commit be8b0cfda9e504639636bb61f9390950e9f4a47c
@@ -43,17 +43,14 @@ class FetchData {
guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return }
//print(json)
let formatter = DateFormatter()
formatter.locale = Locale.current
formatter.dateFormat = "yyyyMMdd"
if let accounts = dict["account_number_list"]?.arrayValue {
accounts.forEach {
if let accountAlias = $0.dictionaryValue["account_alias"]?.string,
let last4 = $0["last4_acct_number"].string,
let creditLimitString = $0.dictionaryValue["credit_limit"]?.string,
let creditLimit = Double(creditLimitString),
let payDueDateString = $0.dictionaryValue["next_payment_due_date"]?.string,
let paymentDueDate = formatter.date(from: payDueDateString),
let paymentDueDate = Defaults.careCreditDateFormatter.date(from: payDueDateString),
let curBalString = $0.dictionaryValue["current_balance"]?.string,
let currentBalance = Double(curBalString),
let availCreditString = $0.dictionaryValue["available_credit"]?.string,
@@ -81,9 +78,6 @@ class FetchData {
var header = Defaults.headerForTransaction
header["account_alias"] = accountAlias
var transactions: [Transaction] = []
let formatter = DateFormatter()
formatter.locale = Locale.current
formatter.dateFormat = "yyyyMMdd"

Alamofire.request(Defaults.TRANS_HISTORY_URL, method: .post, parameters: header, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in
switch payload.result {
@@ -94,7 +88,7 @@ class FetchData {
//let's first parse the pending transactions
dict["pending_transaction_list"]?.arrayValue.forEach {
if let desc = $0["description"].string,
let date = formatter.date(from: $0["transaction_date"].stringValue),
let date = Defaults.careCreditDateFormatter.date(from: $0["transaction_date"].stringValue),
let amountString = $0["transaction_amount"].string,
let amount = Double(amountString),
let confirmationNum = $0["payment_confirmation_number"].string,
@@ -111,7 +105,7 @@ class FetchData {
// let's parse just processed transactions now
dict["processed_transaction_list"]?.arrayValue.forEach {
if let desc = $0["description"].string,
let date = formatter.date(from: $0["transaction_date"].stringValue),
let date = Defaults.careCreditDateFormatter.date(from: $0["transaction_date"].stringValue),
let amountString = $0["transaction_amount"].string,
let amount = Double(amountString) {
let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement
@@ -54,13 +54,9 @@ final class Defaults {
var account_alias = ""

// Dates
let formatter = DateFormatter()
formatter.locale = Locale.current
formatter.dateFormat = "yyyyMMdd"

// for now lets get transactions from the past 2 weeks
let start_date = formatter.string(from: Calendar.current.date(byAdding: .day, value: -14, to: Date()) ?? Date())
let end_date = formatter.string(from: Date())
let start_date = careCreditDateFormatter.string(from: Calendar.current.date(byAdding: .day, value: -14, to: Date()) ?? Date())
let end_date = careCreditDateFormatter.string(from: Date())

return ["account_alias": account_alias,
"begin_sequence": "1",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.