-
Notifications
You must be signed in to change notification settings - Fork 1
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
task: add support for cart items #32
Changes from 12 commits
84cf4f0
13a9d06
5e90b8b
18210d4
22eca7a
41f304e
2af82cb
f96b765
212a37f
b7566bb
71d5a0e
a86e380
23cc26a
f48b33f
909cd15
29cb784
949893e
ee6f996
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
}, | ||
"resolutions": { | ||
"braces": "^3.0.3", | ||
"tar": "^6.2.1" | ||
"tar": "^6.2.1", | ||
"ws": "^7.5.10", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix |
||
"react-native/ws": "^6.2.3" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -67,7 +67,7 @@ class EmbedReactNative: NSObject { | |
completion(gr4vy) | ||
}) | ||
} | ||
|
||
func buildTheme(_ source: [String: [String: String?]?]?) -> Gr4vyTheme? { | ||
guard let theme = source, | ||
let fonts = theme["fonts"] ?? [:], | ||
|
@@ -148,7 +148,7 @@ class EmbedReactNative: NSObject { | |
) | ||
) | ||
} | ||
|
||
func convertStatementDescriptor(_ source: [String: String?]?) -> Gr4vyStatementDescriptor? { | ||
guard let statementDescriptor = source, | ||
let name = statementDescriptor["name"] ?? "", | ||
|
@@ -158,7 +158,7 @@ class EmbedReactNative: NSObject { | |
let url = statementDescriptor["url"] ?? "" else { | ||
return nil | ||
} | ||
|
||
return Gr4vyStatementDescriptor( | ||
name: name, | ||
description: description, | ||
|
@@ -167,7 +167,7 @@ class EmbedReactNative: NSObject { | |
url: url | ||
) | ||
} | ||
|
||
func convertCartItems(_ cartItems: NSArray?) -> [Gr4vyCartItem] { | ||
guard let cartItems = cartItems else { | ||
return [] | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is waiting for the type update in the iOS SDK https://github.com/gr4vy/gr4vy-ios/blob/main/gr4vy-iOS/Models/Gr4vyCartItem.swift. We don't want to pass a default of |
||
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 { | ||
|
@@ -202,10 +224,10 @@ class EmbedReactNative: NSObject { | |
return nil | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
@objc | ||
func constantsToExport() -> [AnyHashable : Any]! { | ||
return [ | ||
|
@@ -214,7 +236,7 @@ class EmbedReactNative: NSObject { | |
GR4VY_ERROR: GR4VY_ERROR | ||
] | ||
} | ||
|
||
@objc | ||
func showPaymentSheet(_ config: [String: Any]) | ||
{ | ||
|
@@ -253,7 +275,7 @@ class EmbedReactNative: NSObject { | |
) | ||
return | ||
} | ||
|
||
gr4vyInit(gr4vyId: gr4vyId, | ||
token: token, | ||
amount: Int(amount), | ||
|
@@ -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( | ||
|
@@ -352,7 +374,7 @@ class EmbedReactNative: NSObject { | |
}) | ||
} | ||
} | ||
|
||
@objc | ||
static func requiresMainQueueSetup() -> Bool { | ||
return true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadableMap
doesn't seem to have a method to get options values and fallback tonull
, so adding one here