Skip to content

Swe 12 enable payment suite #13

Merged
merged 14 commits into from Apr 8, 2019

SWE-12 Support for Disclaimer screen

- also made IBOutlets `weak` to avoid retain cycles
- we present an action sheet to the user which requires them to tape Pay Now to submit payment
- activity indicator is shown until web service returns
- if successful, we push to the payment result screen and show confirmation number, etc
- if error, we ask the user to try again later
  • Loading branch information
ahm11003 committed Apr 2, 2019
commit 50d58635a2014339084d538c8edbe280072fa1ce
@@ -199,24 +199,33 @@
<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>
@@ -247,7 +256,7 @@
</connections>
</controller>
</objects>
<point key="canvasLocation" x="1414" y="182"/>
<point key="canvasLocation" x="1408" y="185"/>
</scene>
<!--Transactions-->
<scene sceneID="yXO-yR-k6b">
@@ -16,15 +16,21 @@ class PaymentDetailInterfaceController: WKInterfaceController {
var paymentButtonArmed: Bool = false
var paymentAmount: Double = 0.0

@IBOutlet weak var contentGroup: WKInterfaceGroup!
@IBOutlet weak var activityIndicator: WKInterfaceImage!
@IBOutlet weak var activityIndicatorLabel: WKInterfaceLabel!
@IBOutlet weak var detailButton: WKInterfaceButton!
@IBOutlet weak var amount: WKInterfaceLabel!
@IBOutlet weak var paymentButton: WKInterfaceButton!

override func awake(withContext context: Any?) {
super.awake(withContext: context)
guard let data = context as? [String: Any], let acct = data["acct"] as? Account, let amount = data["payment_amount"] as? Double else {
NSLog("Error getting account object and payment amount")
return

guard let data = context as? [String: Any],
let acct = data["acct"] as? Account,
let amount = data["payment_amount"] as? Double else {
NSLog("Error getting account object and payment amount")
return
}

self.paymentAmount = amount
@@ -35,13 +41,28 @@ class PaymentDetailInterfaceController: WKInterfaceController {
@IBAction func paymentAction() {
if paymentButtonArmed {
guard let alias = selectedAccount?.accountAlias else { return }
FetchData.submitPayment(for: alias, type: "CBL", amount: 20.00, bankID: "9999") { confirmationNum, paymentID, error in
guard error == nil else { return }
self.dictForPayment.updateValue(confirmationNum, forKey: "payment_confirmation_number")
self.dictForPayment.updateValue(paymentID, forKey: "payment_id")
self.presentController(withName: "PaymentResult", context: self.dictForPayment)
self.popToRootController()
}
let cancel = WKAlertAction(title: "Cancel", style: .cancel, handler: {})
let submit = WKAlertAction(title: "Pay Now", style: .default, handler: {
self.contentGroup.setHidden(true)
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
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])
return
}
self.dictForPayment.updateValue(confirmationNum, forKey: "payment_confirmation_number")
self.dictForPayment.updateValue(paymentID, forKey: "payment_id")
self.activityIndicator.stopAnimatingAsIndicator()
self.activityIndicatorLabel.setHidden(true)
self.contentGroup.setHidden(false)
self.presentController(withName: "PaymentResult", context: self.dictForPayment)
self.popToRootController()
}
})
presentAlert(withTitle: "Disclaimer", message: "By tapping \"Pay Now\", you are authorizing Synchrony Bank to process a one time payment in the amount of \(String(format: "$%.2f", paymentAmount)).", preferredStyle: .actionSheet, actions: [cancel, submit])
} else {
animate(withDuration: 0.5) {
self.paymentButton.setBackgroundColor(#colorLiteral(red: 0.6092301607, green: 0.9366738796, blue: 0.2432599962, alpha: 1))
@@ -10,8 +10,8 @@ import WatchKit
import Foundation

class PaymentResultInterfaceController: WKInterfaceController {
@IBOutlet var confirmationNumberLabel: WKInterfaceLabel!
@IBOutlet var paymentIDLabel: WKInterfaceLabel!
@IBOutlet weak var confirmationNumberLabel: WKInterfaceLabel!
@IBOutlet weak var paymentIDLabel: WKInterfaceLabel!

override func awake(withContext context: Any?) {
super.awake(withContext: context)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.