Skip to content

Commit

Permalink
Merge branch 'master' into SWE-23-transaction-details
Browse files Browse the repository at this point in the history
# Conflicts:
#	SynchronyFinancial/SynchronyFinancial.xcodeproj/project.pbxproj
  • Loading branch information
ahm11003 committed Apr 8, 2019
2 parents 9c5c0b1 + e48f289 commit ae6d59d
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@
<tableRow identifier="account" id="5xi-FS-LlJ" customClass="AccountCell" customModule="SynchronyFinancial_WatchKit_Extension">
<group key="rootItem" width="1" height="44" alignment="left" layout="vertical" id="mYi-9N-Ue7">
<items>
<label alignment="left" text="Label" id="Tl1-Kc-YJS"/>
<label alignment="left" text="Account Name" id="Tl1-Kc-YJS"/>
<label width="136" alignment="left" verticalAlignment="bottom" text="(...XXXX)" textAlignment="left" id="OWC-kI-GEy"/>
</items>
</group>
<connections>
<outlet property="accountName" destination="Tl1-Kc-YJS" id="cgD-CY-lzh"/>
<outlet property="last4Label" destination="OWC-kI-GEy" id="su7-E3-eEF"/>
</connections>
</tableRow>
</items>
Expand Down Expand Up @@ -199,31 +201,60 @@
<objects>
<controller id="t8d-XB-ngB" customClass="PaymentDetailInterfaceController" customModule="SynchronyFinancial_WatchKit_App" customModuleProvider="target">
<items>
<label width="1" alignment="center" text="Pay From:" textAlignment="center" id="xE5-Zl-U7d"/>
<button width="1" height="40" alignment="left" title="Synchrony (1234)" id="SZD-0B-PrF" userLabel="detailButton">
<fontDescription key="font" type="system" pointSize="15"/>
</button>
<separator alignment="left" verticalAlignment="center" id="et0-Sq-Qxm">
<color key="color" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</separator>
<label width="1" alignment="center" verticalAlignment="bottom" text="Confirm Payment" textAlignment="center" id="mT0-3D-JGP"/>
<button width="1" height="49" alignment="left" verticalAlignment="bottom" title="Button" id="FgU-iZ-2XU" userLabel="paymentButton">
<color key="titleColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" red="0.16078431369999999" green="0.6705882353" blue="0.8862745098" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<action selector="paymentAction" destination="t8d-XB-ngB" id="Zjv-zI-wCI"/>
</connections>
</button>
<imageView alignment="left" hidden="YES" id="qfi-KI-QXK"/>
<label width="1" alignment="center" hidden="YES" text="Processing ..." textAlignment="center" id="kgd-iG-og7"/>
<group width="1" height="1" alignment="left" layout="vertical" id="9VF-fb-CV3">
<items>
<label width="1" alignment="center" text="Pay From:" textAlignment="center" id="xE5-Zl-U7d"/>
<button width="1" height="40" alignment="left" title="Synchrony (1234)" id="SZD-0B-PrF" userLabel="detailButton">
<fontDescription key="font" type="system" pointSize="15"/>
</button>
<separator alignment="left" verticalAlignment="center" id="et0-Sq-Qxm">
<color key="color" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</separator>
<label width="1" alignment="center" verticalAlignment="bottom" text="Confirm Payment" textAlignment="center" id="mT0-3D-JGP"/>
<button width="1" height="49" alignment="left" verticalAlignment="bottom" title="Button" id="FgU-iZ-2XU" userLabel="paymentButton">
<color key="titleColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" red="0.16078431369999999" green="0.6705882353" blue="0.8862745098" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<action selector="paymentAction" destination="t8d-XB-ngB" id="Zjv-zI-wCI"/>
</connections>
</button>
</items>
</group>
</items>
<connections>
<outlet property="activityIndicator" destination="qfi-KI-QXK" id="wVj-x3-NzV"/>
<outlet property="activityIndicatorLabel" destination="kgd-iG-og7" id="csx-e2-1eZ"/>
<outlet property="amount" destination="mT0-3D-JGP" id="rff-wG-B82"/>
<outlet property="contentGroup" destination="9VF-fb-CV3" id="vfa-YT-ipt"/>
<outlet property="detailButton" destination="SZD-0B-PrF" id="xEw-gE-yIP"/>
<outlet property="paymentButton" destination="FgU-iZ-2XU" id="yZe-dZ-nBV"/>
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1085" y="186"/>
</scene>
<!--PaymentResult-->
<scene sceneID="mFc-oM-oG1">
<objects>
<controller identifier="PaymentResult" id="mpK-7H-pjK" customClass="PaymentResultInterfaceController" customModule="SynchronyFinancial_WatchKit_App" customModuleProvider="target">
<items>
<label width="1" alignment="center" text="Payment Result:" textAlignment="center" id="gg1-Wq-NeI"/>
<separator width="1" alignment="center" id="Y1o-3Q-hjG"/>
<label width="1" alignment="center" text="Confirmation Number:" textAlignment="center" minimumScaleFactor="0.69999999999999996" id="qAX-bM-U5t"/>
<label width="1" alignment="center" text="Label" textAlignment="center" minimumScaleFactor="0.5" id="cF3-r2-BMf"/>
<label width="1" alignment="center" verticalAlignment="center" text="Payment ID:" textAlignment="center" id="7Cr-Kh-rJ2"/>
<label width="1" alignment="center" verticalAlignment="center" text="Label" textAlignment="center" id="wSp-wZ-Ksf"/>
</items>
<connections>
<outlet property="confirmationNumberLabel" destination="cF3-r2-BMf" id="FBR-K8-kdQ"/>
<outlet property="paymentIDLabel" destination="wSp-wZ-Ksf" id="7MN-ZT-Jxw"/>
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1408" y="185"/>
</scene>
<!--Transactions-->
<scene sceneID="yXO-yR-k6b">
<objects>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import WatchKit

class AccountCell: NSObject {
@IBOutlet weak var accountName: WKInterfaceLabel!
@IBOutlet weak var last4Label: WKInterfaceLabel!
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AccountTableInterfaceController: WKInterfaceController {
for index in 0..<accountTable.numberOfRows {
if let row = accountTable.rowController(at: index) as? AccountCell {
row.accountName.setText(accounts[index].accountName)
row.last4Label.setText("(...\(accounts[index].last4))")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FetchData {
completion(false, NSError())
return
}

if let token = dict["access_token"]?.string {
// now we should save our token somewhere safe (UserDefaults)
UserDefaults.standard.set(token, forKey: "access_token")
Expand All @@ -43,16 +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,
Expand All @@ -62,7 +60,7 @@ class FetchData {
let statementBalString = $0.dictionaryValue["statement_bal"]?.string,
let statementBalance = Double(statementBalString),
let accountName = $0.dictionaryValue["cc_program_name"]?.string {
let inAccount = Account(accountAlias: accountAlias, creditLimit: creditLimit, paymentDueDate: paymentDueDate, curBalance: currentBalance, availCredit: availableCredit, minPayDue: minPaymentDue, statementBal: statementBalance, accountName: accountName)
let inAccount = Account(accountAlias, creditLimit, last4, paymentDueDate, currentBalance, availableCredit, minPaymentDue, statementBalance, accountName)
accountList.append(inAccount)
}
}
Expand All @@ -80,20 +78,17 @@ 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 {
case .success(let value):
let dict = JSON(value).dictionaryValue
guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return }

//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,
Expand All @@ -102,15 +97,15 @@ class FetchData {
let modifiable = $0["is_payment_modifiable"].string {
let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement
let isModifiable: Bool = modifiable == "Y" ? true : false

transactions.append(Transaction(type: type, amount: amount, merchantID: desc, date: date, confirmationNum: confirmationNum, paymentId: paymentId, isPending: true, isModifiable: isModifiable))
}
}

// 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
Expand All @@ -124,7 +119,7 @@ class FetchData {
}
}
}

static func getBankInfo(completion: @escaping ([BankAcct], Error?) -> Void) {
var bankIds: [BankAcct] = []
Alamofire.request(Defaults.FETCH_BANKS_URL, method: .post, parameters: Defaults.headerForMulti, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in
Expand All @@ -150,6 +145,47 @@ class FetchData {
}
}
}



static func cancelPayment(accountAlias: String, confirmationNum: String, paymentId: Int, completion: @escaping (String, Error?) -> Void) {
var paymentHeader = Defaults.headerForCancelPmt
paymentHeader["account_alias"] = accountAlias
paymentHeader["payment_confirmation_number"] = confirmationNum
paymentHeader["payment_id"] = paymentId

Alamofire.request(Defaults.CANCEL_PAYMENT_URL, method: .post, parameters: paymentHeader, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in
switch payload.result {
case .success(let value):
let dict = JSON(value).dictionaryValue
guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return }
if let paymentCancelNum = dict["cancellation_confirmation_number"]?.stringValue {
completion(paymentCancelNum, nil)
}
case .failure(let error):
NSLog("Error: \(error.localizedDescription)")
}
}
}

static func submitPayment(for alias: String, type: PaymentType, amount: Double, bankID: String, completion: @escaping (String, String, Error?) -> Void) {
var paymentHeader = Defaults.headerForPmt
paymentHeader["account_alias"] = alias
paymentHeader["bank_account_id"] = bankID
paymentHeader["payment_amount_type"] = type.rawValue
paymentHeader["payment_amount"] = amount
paymentHeader["scheduled_payment_post_date"] = Defaults.careCreditDateFormatter.string(from: Date())

Alamofire.request(Defaults.MAKE_PAYMENT_URL, method: .post, parameters: paymentHeader, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in
switch payload.result {
case .success(let value):
let dict = JSON(value).dictionaryValue
guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return }
if let paymentConfirmationNum = dict["payment_confirmation_number"]?.stringValue,
let paymentID = dict["payment_id"]?.stringValue {
completion(paymentConfirmationNum, paymentID, nil)
}
case .failure(let error):
NSLog("Error: \(error.localizedDescription)")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class PayBillInterfaceController: WKInterfaceController {
let minimumFormatted = String(format: "$%.2f", valid.minPayDue)
minimumLabel.setText("Minimum Payment:\n\(minimumFormatted)")
payMinimumButton.setTitle("Pay \(minimumFormatted)")

payMinimumButton.setEnabled(valid.minPayDue > 0.0)
payBalanceButton.setEnabled(valid.curBalance > 0.0)
}
}
}
Loading

0 comments on commit ae6d59d

Please sign in to comment.