Skip to content

Swe 12 enable payment suite #13

Merged
merged 14 commits into from Apr 8, 2019

SWE-12 swiftlint warning cleanup, payment fine tweaks

- created new `enum PaymentType` to provide a cleaner way to pass code for either current balance payment or minimum due payment
  • Loading branch information
ahm11003 committed Apr 5, 2019
commit 5407b6962b74498d76379923595db217fac773b0
@@ -90,7 +90,7 @@ class FetchData {
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,
@@ -103,11 +103,11 @@ 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,
@@ -125,7 +125,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
@@ -151,14 +151,13 @@ 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):
@@ -173,15 +172,14 @@ class FetchData {
}
}

static func submitPayment(for alias: String, type: String, amount: Double, bankID: String, completion: @escaping (String, String, Error?) -> Void) {
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
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):
@@ -47,7 +47,10 @@ class PaymentDetailInterfaceController: WKInterfaceController {
self.activityIndicator.configureForActivityIndicator()
self.activityIndicatorLabel.setHidden(false)
self.activityIndicatorLabel.setVerticalAlignment(.center)
FetchData.submitPayment(for: alias, type: "CBL", amount: 20.00, bankID: "9999") { confirmationNum, paymentID, error in
let type: PaymentType = self.paymentAmount == self.selectedAccount?.curBalance ? .currentBal : .minimumDue

// process this payment using default bank account (9999) until ability to change account is implemented
FetchData.submitPayment(for: alias, type: type, amount: self.paymentAmount, bankID: "9999") { confirmationNum, paymentID, error in
guard error == nil else {
let dismiss = WKAlertAction(title: "Dismiss", style: .cancel, handler: {})
self.presentAlert(withTitle: "Error", message: "We were unable to process your payment at this time. Please try again later.", preferredStyle: .alert, actions: [dismiss])
@@ -12,6 +12,11 @@ public enum TransactionType: Int {
case reimbursement = 1
}

public enum PaymentType: String {
case currentBal = "CBL"
case minimumDue = "MIN"
}

class Transaction: NSObject {
var type: TransactionType
var amount: Double
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.