Skip to content

Commit

Permalink
Merge branch 'main' into convert-3ds-viewcontroller
Browse files Browse the repository at this point in the history
# Conflicts:
#	Demo/Demo.xcodeproj/project.pbxproj
  • Loading branch information
jaxdesmarais committed Sep 22, 2023
2 parents 387cd99 + 4d2a575 commit 7553b1b
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)viewDidLoad {
[self.paymentButton.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
[self.paymentButton.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
[self.paymentButton.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor constant:self.centerYConstant],
[self.paymentButton.heightAnchor constraintEqualToConstant:44.0]
[self.paymentButton.heightAnchor constraintEqualToConstant:100.0]
]];
}

Expand Down

This file was deleted.

96 changes: 0 additions & 96 deletions Demo/Application/Features/Amex/BraintreeDemoAmexViewController.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import Foundation
import BraintreeAmericanExpress
import BraintreeCard

class BraintreeDemoAmexViewController: BraintreeDemoPaymentButtonBaseViewController {

lazy var amexClient = BTAmericanExpressClient(apiClient: apiClient)
lazy var cardClient = BTCardClient(apiClient: apiClient)

override func viewDidLoad() {
super.viewDidLoad()
title = "Amex"
}

override func createPaymentButton() -> UIView! {
let validCardButton = createButton(title: "Valid card", action: #selector(tappedValidCard))
let insufficientPointsCardButton = createButton(title: "Insufficient points card", action: #selector(tappedInsufficientPointsCard))
let ineligibleCardButton = createButton(title: "Ineligible card", action: #selector(tappedIneligibleCard))

let stackView = UIStackView(arrangedSubviews: [validCardButton, insufficientPointsCardButton, ineligibleCardButton])
stackView.axis = .vertical
stackView.alignment = .center
stackView.distribution = .fillEqually
stackView.translatesAutoresizingMaskIntoConstraints = false

return stackView
}

@objc func tappedValidCard() {
getRewards(for: "371260714673002")
}

@objc func tappedInsufficientPointsCard() {
getRewards(for: "371544868764018")
}

@objc func tappedIneligibleCard() {
getRewards(for: "378267515471109")
}

private func getRewards(for cardNumber: String) {
let card = BTCard()
card.number = cardNumber
card.expirationMonth = "12"
card.expirationYear = generateFutureYear()
card.cvv = "1234"

progressBlock("Tokenizing Card")

cardClient.tokenize(card) { tokenizedCard, error in
guard let tokenizedCard else {
self.progressBlock(error?.localizedDescription)
return
}

self.progressBlock("Amex - getting rewards balance")

self.amexClient.getRewardsBalance(forNonce: tokenizedCard.nonce, currencyISOCode: "USD") { rewardsBalance, error in
guard let rewardsBalance else {
self.progressBlock(error?.localizedDescription)
return
}

if let errorCode = rewardsBalance.errorCode, let errorMessage = rewardsBalance.errorMessage {
self.progressBlock("\(errorCode): \(errorMessage)")
} else if let rewardsAmount = rewardsBalance.rewardsAmount,
let rewardsUnit = rewardsBalance.rewardsUnit,
let currencyAmount = rewardsBalance.currencyAmount,
let currencyIsoCode = rewardsBalance.currencyIsoCode {
self.progressBlock("\(rewardsAmount) \(rewardsUnit), \(currencyAmount) \(currencyIsoCode)")
}
}
}
}

private func generateFutureYear() -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yy"

let futureYear = Calendar.current.date(byAdding: .year, value: 3, to: Date())!
return dateFormatter.string(from: futureYear)
}

// TODO: move this helper into BraintreeDemoPaymentButtonBaseViewController once converted so all buttons share the same characteristics
private func createButton(title: String, action: Selector) -> UIButton {
let button = UIButton(type: .system)
button.setTitle(title, for: .normal)
button.setTitleColor(.blue, for: .normal)
button.setTitleColor(.lightGray, for: .highlighted)
button.setTitleColor(.lightGray, for: .disabled)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: action, for: .touchUpInside)
return button
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7553b1b

Please sign in to comment.