Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SWE-12 Define web service call for making payment
  • Loading branch information
ahm11003 committed Mar 29, 2019
1 parent 2e991f6 commit a2689bd
Showing 1 changed file with 25 additions and 1 deletion.
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 Down Expand Up @@ -107,4 +107,28 @@ class FetchData {
}
}
}

static func submitPayment(for alias: String, type: String, 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"] = 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)")
}
}
}
}

0 comments on commit a2689bd

Please sign in to comment.