-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DTPP-11 Organizing Demo app folder structure
- Loading branch information
Showing
30 changed files
with
1,830 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Demo/Demo/CardPayments/CardPaymentViews/CardApprovalResultView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import SwiftUI | ||
|
||
struct CardApprovalResultView: View { | ||
|
||
@ObservedObject var cardPaymentViewModel: CardPaymentViewModel | ||
|
||
var body: some View { | ||
switch cardPaymentViewModel.state.approveResultResponse { | ||
case .idle, .loading: | ||
EmptyView() | ||
case .loaded(let approvalResult): | ||
getSuccessView(approvalResult: approvalResult) | ||
case .error(let errorMessage): | ||
ErrorView(errorMessage: errorMessage) | ||
} | ||
} | ||
|
||
func getSuccessView(approvalResult: CardPaymentState.CardResult) -> some View { | ||
VStack(spacing: 16) { | ||
HStack { | ||
Text("Card Approval Result") | ||
.font(.system(size: 20)) | ||
Spacer() | ||
} | ||
LeadingText("ID", weight: .bold) | ||
LeadingText("\(approvalResult.id)") | ||
if let status = approvalResult.status { | ||
LeadingText("Order Status", weight: .bold) | ||
LeadingText("\(status)") | ||
} | ||
LeadingText("didAttemptThreeDSecureAuthentication", weight: .bold) | ||
LeadingText("\(approvalResult.didAttemptThreeDSecureAuthentication)") | ||
} | ||
.frame(maxWidth: .infinity) | ||
.padding() | ||
.background( | ||
RoundedRectangle(cornerRadius: 10) | ||
.stroke(.gray, lineWidth: 2) | ||
.padding(5) | ||
) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Demo/Demo/CardPayments/CardPaymentViews/CardOrderActionButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import SwiftUI | ||
|
||
struct CardOrderActionButton: View { | ||
|
||
let intent: Intent | ||
let orderID: String | ||
let selectedMerchantIntegration: MerchantIntegration | ||
|
||
@ObservedObject var cardPaymentViewModel: CardPaymentViewModel | ||
|
||
var body: some View { | ||
ZStack { | ||
Button("\(intent.rawValue)") { | ||
completeOrder() | ||
} | ||
.buttonStyle(RoundedBlueButtonStyle()) | ||
.padding() | ||
|
||
if .loading == cardPaymentViewModel.state.authorizedOrderResponse || | ||
.loading == cardPaymentViewModel.state.capturedOrderResponse { | ||
CircularProgressView() | ||
} | ||
} | ||
} | ||
|
||
private func completeOrder() { | ||
if intent == .capture { | ||
Task { | ||
do { | ||
try await cardPaymentViewModel.captureOrder( | ||
orderID: orderID, | ||
selectedMerchantIntegration: selectedMerchantIntegration | ||
) | ||
print("Order Captured. ID: \(cardPaymentViewModel.state.capturedOrder?.id ?? "")") | ||
} catch { | ||
print("Error capturing order: \(error.localizedDescription)") | ||
} | ||
} | ||
} else { | ||
Task { | ||
do { | ||
try await cardPaymentViewModel.authorizeOrder( | ||
orderID: orderID, | ||
selectedMerchantIntegration: selectedMerchantIntegration | ||
) | ||
print("Order Authorized. ID: \(cardPaymentViewModel.state.authorizedOrder?.id ?? "")") | ||
} catch { | ||
print("Error authorizing order: \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
Demo/Demo/CardPayments/CardPaymentViews/CardOrderApproveView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import SwiftUI | ||
import CardPayments | ||
import CorePayments | ||
|
||
struct CardOrderApproveView: View { | ||
|
||
let cardSections: [CardSection] = [ | ||
CardSection(title: "Successful Authentication Visa", numbers: ["4868 7194 6070 7704"]), | ||
CardSection(title: "Vault with Purchase (no 3DS)", numbers: ["4000 0000 0000 0002"]), | ||
CardSection(title: "Step up", numbers: ["5314 6090 4083 0349"]), | ||
CardSection(title: "Frictionless - LiabilityShift Possible", numbers: ["4005 5192 0000 0004"]), | ||
CardSection(title: "Frictionless - LiabilityShift NO", numbers: ["4020 0278 5185 3235"]), | ||
CardSection(title: "No Challenge", numbers: ["4111 1111 1111 1111"]) | ||
] | ||
let orderID: String | ||
|
||
@ObservedObject var cardPaymentViewModel: CardPaymentViewModel | ||
@State private var cardNumberText: String = "4111 1111 1111 1111" | ||
@State private var expirationDateText: String = "01 / 25" | ||
@State private var cvvText: String = "123" | ||
|
||
var body: some View { | ||
ScrollView { | ||
ScrollViewReader { scrollView in | ||
VStack { | ||
VStack(spacing: 16) { | ||
HStack { | ||
Text("Enter Card Information") | ||
.font(.system(size: 20)) | ||
Spacer() | ||
} | ||
|
||
CardFormView( | ||
cardSections: cardSections, | ||
cardNumberText: $cardNumberText, | ||
expirationDateText: $expirationDateText, | ||
cvvText: $cvvText | ||
) | ||
|
||
let card = Card.createCard( | ||
cardNumber: cardNumberText, | ||
expirationDate: expirationDateText, | ||
cvv: cvvText | ||
) | ||
|
||
Picker("SCA", selection: $cardPaymentViewModel.state.scaSelection) { | ||
Text(SCA.scaWhenRequired.rawValue).tag(SCA.scaWhenRequired) | ||
Text(SCA.scaAlways.rawValue).tag(SCA.scaAlways) | ||
} | ||
.pickerStyle(SegmentedPickerStyle()) | ||
.frame(height: 50) | ||
|
||
ZStack { | ||
Button("Approve Order") { | ||
Task { | ||
do { | ||
await cardPaymentViewModel.checkoutWith( | ||
card: card, | ||
orderID: orderID, | ||
sca: cardPaymentViewModel.state.scaSelection | ||
) | ||
} | ||
} | ||
} | ||
.buttonStyle(RoundedBlueButtonStyle()) | ||
if case .loading = cardPaymentViewModel.state.approveResultResponse { | ||
CircularProgressView() | ||
} | ||
} | ||
} | ||
.padding() | ||
.background( | ||
RoundedRectangle(cornerRadius: 10) | ||
.stroke(.gray, lineWidth: 2) | ||
.padding(5) | ||
) | ||
CardApprovalResultView(cardPaymentViewModel: cardPaymentViewModel) | ||
if cardPaymentViewModel.state.approveResult != nil { | ||
NavigationLink { | ||
CardPaymentOrderCompletionView(orderID: orderID, cardPaymentViewModel: cardPaymentViewModel) | ||
} label: { | ||
Text("Complete Order Transaction") | ||
} | ||
.buttonStyle(RoundedBlueButtonStyle()) | ||
.padding() | ||
} | ||
Text("") | ||
.id("bottomView") | ||
Spacer() | ||
} | ||
.onChange(of: cardPaymentViewModel.state) { _ in | ||
withAnimation { | ||
scrollView.scrollTo("bottomView") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.