Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTPP-11 Organizing Demo app folder structure #306

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 78 additions & 30 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,78 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
1001E2AA2CF53C970023A03C /* CardPayments */ = {
isa = PBXGroup;
children = (
3BA56FEA2A9DCBB30081D14F /* CardPaymentViews */,
1001E2AF2CF62EA20023A03C /* CardPaymentsViewModel */,
);
path = CardPayments;
sourceTree = "<group>";
};
1001E2AB2CF53CB30023A03C /* CardVault */ = {
isa = PBXGroup;
children = (
3B43290F2A8FD7FD00C5441A /* CardVaultViews */,
1001E2AE2CF53E540023A03C /* CardVaulthViewModel */,
);
path = CardVault;
sourceTree = "<group>";
};
1001E2AC2CF53CC70023A03C /* PayPalVault */ = {
isa = PBXGroup;
children = (
3B2501052B2679F000903EAB /* VaultViews */,
3BB60B512B1F9EE400A298CF /* PayPalVaultViews */,
1001E2B02CF62EF40023A03C /* VaultViewModel */,
);
path = PayPalVault;
sourceTree = "<group>";
};
1001E2AD2CF53CD70023A03C /* PayPalWebPayments */ = {
isa = PBXGroup;
children = (
3BA56FFF2A9FF6630081D14F /* PayPalWebPaymentsView */,
1001E2B12CF6300F0023A03C /* PayPalWebViewModel */,
);
path = PayPalWebPayments;
sourceTree = "<group>";
};
1001E2AE2CF53E540023A03C /* CardVaulthViewModel */ = {
isa = PBXGroup;
children = (
3B20273E2A89F24E0007907E /* CardVaultViewModel.swift */,
);
path = CardVaulthViewModel;
sourceTree = "<group>";
};
1001E2AF2CF62EA20023A03C /* CardPaymentsViewModel */ = {
isa = PBXGroup;
children = (
3BA56FE62A9DC9D70081D14F /* CardPaymentViewModel.swift */,
3BA56FE82A9DCA520081D14F /* CardPaymentState.swift */,
);
path = CardPaymentsViewModel;
sourceTree = "<group>";
};
1001E2B02CF62EF40023A03C /* VaultViewModel */ = {
isa = PBXGroup;
children = (
3BB60B542B1FA00C00A298CF /* PayPalVaultViewModel.swift */,
3BA0A58A2B1E240300330681 /* VaultViewModel.swift */,
3B2027402A8A72050007907E /* VaultState.swift */,
);
path = VaultViewModel;
sourceTree = "<group>";
};
1001E2B12CF6300F0023A03C /* PayPalWebViewModel */ = {
isa = PBXGroup;
children = (
3BA56FFB2A9FEFE90081D14F /* PayPalWebViewModel.swift */,
);
path = PayPalWebViewModel;
sourceTree = "<group>";
};
3B2501052B2679F000903EAB /* VaultViews */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -263,17 +335,16 @@
path = CardPaymentViews;
sourceTree = "<group>";
};
3BA56FFF2A9FF6630081D14F /* PayPalWebPayments */ = {
3BA56FFF2A9FF6630081D14F /* PayPalWebPaymentsView */ = {
isa = PBXGroup;
children = (
3BA570062AA0DF330081D14F /* PayPalWebButtonsView.swift */,
3BA570022AA053AE0081D14F /* PayPalWebCreateOrderView.swift */,
3BA570002AA052E80081D14F /* PayPalWebPaymentsView.swift */,
BE8117632B07E778009867B9 /* PayPalWebResultView.swift */,
3B6472A62AFAEB3A004745C4 /* PayPalWebTransactionView.swift */,
3BA56FFB2A9FEFE90081D14F /* PayPalWebViewModel.swift */,
);
path = PayPalWebPayments;
path = PayPalWebPaymentsView;
sourceTree = "<group>";
};
3BB60B512B1F9EE400A298CF /* PayPalVaultViews */ = {
Expand All @@ -300,13 +371,6 @@
path = CommonComponents;
sourceTree = "<group>";
};
53B9E8E828C93B2B00719239 /* Helpers */ = {
isa = PBXGroup;
children = (
);
path = Helpers;
sourceTree = "<group>";
};
805AB84C26B87A87003BEE0D /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -350,17 +414,19 @@
isa = PBXGroup;
children = (
806C7A812C000626000E85E8 /* Demo.entitlements */,
53B9E8E828C93B2B00719239 /* Helpers */,
806F1E4126B85369007A60E6 /* Assets.xcassets */,
BED0422F2710833100C80954 /* Card */,
BECD849E27036D95007CCAE4 /* DemoSettings */,
BEDE3048275EA31800D275FD /* Extensions */,
806F1E4626B85369007A60E6 /* Info.plist */,
80921C1C2710A0720040D76F /* LaunchScreen.storyboard */,
1001E2AD2CF53CD70023A03C /* PayPalWebPayments */,
1001E2AC2CF53CC70023A03C /* PayPalVault */,
1001E2AB2CF53CB30023A03C /* CardVault */,
1001E2AA2CF53C970023A03C /* CardPayments */,
80F33CEB26F8E799006811B1 /* Models */,
BE1766B526FA562B007EF438 /* Networking */,
BEDE3047275E998700D275FD /* SwiftUIComponents */,
BE4876A827567D4200802EAF /* ViewModels */,
3BCCFE482A9D96CA00C5102F /* DemoApp.swift */,
);
path = Demo;
Expand Down Expand Up @@ -411,19 +477,6 @@
path = Networking;
sourceTree = "<group>";
};
BE4876A827567D4200802EAF /* ViewModels */ = {
isa = PBXGroup;
children = (
3B20273E2A89F24E0007907E /* CardVaultViewModel.swift */,
3BA0A58A2B1E240300330681 /* VaultViewModel.swift */,
3B2027402A8A72050007907E /* VaultState.swift */,
3BA56FE62A9DC9D70081D14F /* CardPaymentViewModel.swift */,
3BA56FE82A9DCA520081D14F /* CardPaymentState.swift */,
3BB60B542B1FA00C00A298CF /* PayPalVaultViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
};
BECD849E27036D95007CCAE4 /* DemoSettings */ = {
isa = PBXGroup;
children = (
Expand All @@ -446,12 +499,7 @@
BEDE3047275E998700D275FD /* SwiftUIComponents */ = {
isa = PBXGroup;
children = (
3B2501052B2679F000903EAB /* VaultViews */,
3BB60B512B1F9EE400A298CF /* PayPalVaultViews */,
3BA56FFF2A9FF6630081D14F /* PayPalWebPayments */,
3BA56FEA2A9DCBB30081D14F /* CardPaymentViews */,
3BCCFE472A9D962E00C5102F /* CommonComponents */,
3B43290F2A8FD7FD00C5441A /* CardVaultViews */,
CB9ED44D28411B110081F4DE /* SwiftUIPaymentButtonDemo.swift */,
3BCCFE4A2A9D985F00C5102F /* FeatureSelectionView.swift */,
BE8117672B080472009867B9 /* CurrentState.swift */,
Expand Down
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)
)
}
}
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)")
}
}
}
}
}
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")
}
}
}
}
}
}
Loading