Skip to content

Commit

Permalink
Pass rest of cartItems props
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-gr4vy committed Jun 26, 2024
1 parent f96b765 commit 212a37f
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions ios/EmbedReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EmbedReactNative: NSObject {
paymentSourceConverted = Gr4vyPaymentSource(rawValue: paymentSource!)
}

DispatchQueue.main.async(execute: {
DispatchQueue.main.async(execute: {
guard let gr4vy = Gr4vy(gr4vyId: gr4vyId,
token: token,
amount: amount,
Expand Down Expand Up @@ -67,7 +67,7 @@ class EmbedReactNative: NSObject {
completion(gr4vy)
})
}

func buildTheme(_ source: [String: [String: String?]?]?) -> Gr4vyTheme? {
guard let theme = source,
let fonts = theme["fonts"] ?? [:],
Expand Down Expand Up @@ -148,7 +148,7 @@ class EmbedReactNative: NSObject {
)
)
}

func convertStatementDescriptor(_ source: [String: String?]?) -> Gr4vyStatementDescriptor? {
guard let statementDescriptor = source,
let name = statementDescriptor["name"] ?? "",
Expand All @@ -158,7 +158,7 @@ class EmbedReactNative: NSObject {
let url = statementDescriptor["url"] ?? "" else {
return nil
}

return Gr4vyStatementDescriptor(
name: name,
description: description,
Expand All @@ -167,7 +167,7 @@ class EmbedReactNative: NSObject {
url: url
)
}

func convertCartItems(_ cartItems: NSArray?) -> [Gr4vyCartItem] {
guard let cartItems = cartItems else {
return []
Expand All @@ -181,17 +181,39 @@ class EmbedReactNative: NSObject {
let unitAmount = dict["unitAmount"] as? Int else {
return []
}
result.append(Gr4vyCartItem(name: name, quantity: quantity, unitAmount: unitAmount))
let discountAmount = dict["discountAmount"] as? Int ?? 0
let taxAmount = dict["taxAmount"] as? Int ?? 0
let externalIdentifier = dict["externalIdentifier"] as? String
let sku = dict["sku"] as? String
let productUrl = dict["productUrl"] as? String
let imageUrl = dict["imageUrl"] as? String
let categories = dict["categories"] as? [String]
let productType = dict["productType"] as? String
result.append(
Gr4vyCartItem(
name: name,
quantity: quantity,
unitAmount: unitAmount,
discountAmount: discountAmount,
taxAmount: taxAmount,
externalIdentifier: externalIdentifier,
sku: sku,
productUrl: productUrl,
imageUrl: imageUrl,
categories: categories,
productType: productType
)
)
}

return result
}

func convertStore(_ store: Any?) -> Gr4vyStore? {
guard let storeValue = store else {
return nil
}

if let storeBool = storeValue as? Bool {
return storeBool ? .true : .false
} else if let storeString = store as? String {
Expand All @@ -202,10 +224,10 @@ class EmbedReactNative: NSObject {
return nil
}
}

return nil
}

@objc
func constantsToExport() -> [AnyHashable : Any]! {
return [
Expand All @@ -214,7 +236,7 @@ class EmbedReactNative: NSObject {
GR4VY_ERROR: GR4VY_ERROR
]
}

@objc
func showPaymentSheet(_ config: [String: Any])
{
Expand Down Expand Up @@ -253,7 +275,7 @@ class EmbedReactNative: NSObject {
)
return
}

gr4vyInit(gr4vyId: gr4vyId,
token: token,
amount: Int(amount),
Expand Down Expand Up @@ -291,11 +313,11 @@ class EmbedReactNative: NSObject {

DispatchQueue.main.async(execute: {
let presentingViewController = RCTPresentedViewController()

gr4vy!.launch(
presentingViewController: presentingViewController!,
onEvent: { event in

switch event {
case .transactionFailed(let transactionID, let status, let paymentMethodID):
EmbedReactNativeEvents.emitter.sendEvent(
Expand Down Expand Up @@ -352,7 +374,7 @@ class EmbedReactNative: NSObject {
})
}
}

@objc
static func requiresMainQueueSetup() -> Bool {
return true
Expand Down

0 comments on commit 212a37f

Please sign in to comment.