Skip to content

Commit

Permalink
cardForm spike
Browse files Browse the repository at this point in the history
  • Loading branch information
KunJeongPark committed Dec 18, 2024
1 parent a6039a6 commit 014692f
Show file tree
Hide file tree
Showing 13 changed files with 1,099 additions and 44 deletions.
8 changes: 6 additions & 2 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
3B80D5102A291CB100D2EAC4 /* ClientIDResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B80D50F2A291CB100D2EAC4 /* ClientIDResponse.swift */; };
3B8EF4DB2A932DA300A70D0B /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B8EF4DA2A932DA300A70D0B /* ErrorView.swift */; };
3BA0A58B2B1E240300330681 /* VaultViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BA0A58A2B1E240300330681 /* VaultViewModel.swift */; };
3BA3643C2D134857008926B7 /* CardPaySheet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BA3643B2D134857008926B7 /* CardPaySheet.framework */; };
3BA56FE72A9DC9D70081D14F /* CardPaymentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BA56FE62A9DC9D70081D14F /* CardPaymentViewModel.swift */; };
3BA56FE92A9DCA520081D14F /* CardPaymentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BA56FE82A9DCA520081D14F /* CardPaymentState.swift */; };
3BA56FEC2A9DCBF30081D14F /* CreateOrderCardPaymentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BA56FEB2A9DCBF30081D14F /* CreateOrderCardPaymentView.swift */; };
Expand Down Expand Up @@ -139,6 +140,7 @@
3B80D50F2A291CB100D2EAC4 /* ClientIDResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientIDResponse.swift; sourceTree = "<group>"; };
3B8EF4DA2A932DA300A70D0B /* ErrorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorView.swift; sourceTree = "<group>"; };
3BA0A58A2B1E240300330681 /* VaultViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VaultViewModel.swift; sourceTree = "<group>"; };
3BA3643B2D134857008926B7 /* CardPaySheet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CardPaySheet.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3BA56FE62A9DC9D70081D14F /* CardPaymentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPaymentViewModel.swift; sourceTree = "<group>"; };
3BA56FE82A9DCA520081D14F /* CardPaymentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPaymentState.swift; sourceTree = "<group>"; };
3BA56FEB2A9DCBF30081D14F /* CreateOrderCardPaymentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateOrderCardPaymentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -214,6 +216,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3BA3643C2D134857008926B7 /* CardPaySheet.framework in Frameworks */,
CB1AC3B82982AAD70081AED6 /* CardPayments.framework in Frameworks */,
CB1AC3C02982C4030081AED6 /* PayPalWebPayments.framework in Frameworks */,
CB1AC3BB2982BB130081AED6 /* PaymentButtons.framework in Frameworks */,
Expand Down Expand Up @@ -406,6 +409,7 @@
805AB84C26B87A87003BEE0D /* Frameworks */ = {
isa = PBXGroup;
children = (
3BA3643B2D134857008926B7 /* CardPaySheet.framework */,
8052E2A229B684A600B33FBC /* PPRiskMagnes.xcframework */,
CBDEEA212989990200A460A6 /* CorePayments.framework */,
CB1AC3C62982E32D0081AED6 /* FraudProtection.framework */,
Expand Down Expand Up @@ -794,7 +798,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -849,7 +853,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.6;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down
21 changes: 21 additions & 0 deletions Demo/Demo/Assets.xcassets/headphonePic.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "headphonePic.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ class CardPaymentViewModel: ObservableObject {

@Published var state = CardPaymentState()
private var payPalDataCollector: PayPalDataCollector?
public var config: CoreConfig?

let configManager = CoreConfigManager(domain: "Card Payments")

private var cardClient: CardClient?

func getConfig() async throws {
let config = try await configManager.getCoreConfig()
self.config = config
}

func createOrder(
amount: String,
selectedMerchantIntegration: MerchantIntegration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,64 @@
import SwiftUI
import CardPayments
import CorePayments
import CardPaySheet

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

var config: CoreConfig?

@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"

@State private var showingCardSheet = false

var body: some View {
ScrollView {
ScrollViewReader { scrollView in
VStack {
VStack(spacing: 16) {
HStack {
Text("Enter Card Information")
.font(.system(size: 20))
Text("Your cart")
.font(.system(size: 22, weight: .semibold))
Spacer()
}

CardFormView(
cardSections: cardSections,
cardNumberText: $cardNumberText,
expirationDateText: $expirationDateText,
cvvText: $cvvText
)

let card = Card.createCard(
cardNumber: cardNumberText,
expirationDate: expirationDateText,
cvv: cvvText
)


HStack(spacing: 20) {
Image("headphonePic")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 120, height: 120)
VStack(alignment: .leading, spacing: 4) {
Text("Bose Rose Gold QC35II")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.primary)
Text("$10.00")
.font(.system(size: 16))
.foregroundColor(.secondary)
}
}

Spacer().frame(height: 20)

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
)
Button("Pay with Card") {
Task {
do {
try await cardPaymentViewModel.getConfig()
await MainActor.run {
showingCardSheet = true
}
}
}
.buttonStyle(RoundedBlueButtonStyle())
if case .loading = cardPaymentViewModel.state.approveResultResponse {
CircularProgressView()
}
}
.buttonStyle(RoundedBlueButtonStyle())
}
.padding()
.background(
Expand All @@ -88,6 +80,28 @@ struct CardOrderApproveView: View {
.id("bottomView")
Spacer()
}
.sheet(isPresented: $showingCardSheet) {
if let config = cardPaymentViewModel.config {
CardPaySheetView(config: config, orderID: orderID, sca: cardPaymentViewModel.state.scaSelection) { result in
switch result {
case .success(let cardResult):
print("success!: \(cardResult.orderID)")
cardPaymentViewModel.setApprovalSuccessResult(
approveResult:
CardPaymentState.CardResult(
id: cardResult.orderID,
status: cardResult.status,
didAttemptThreeDSecureAuthentication: cardResult.didAttemptThreeDSecureAuthentication
)
)
case .failure(let error):
cardPaymentViewModel.setApprovalFailureResult(error: error)
}
showingCardSheet = false
}
.presentationDetents([.fraction(0.75)])
}
}
.onChange(of: cardPaymentViewModel.state) { _ in
withAnimation {
scrollView.scrollTo("bottomView")
Expand Down
Loading

0 comments on commit 014692f

Please sign in to comment.