Skip to content

Commit daa7fa7

Browse files
Merge pull request #63 from qonversion/release/1.5.0
Release 1.5.0
2 parents 8dd65a9 + f6ba02c commit daa7fa7

21 files changed

Lines changed: 310 additions & 17 deletions

QonversionCapacitorPlugin.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ Pod::Spec.new do |s|
1414
s.ios.deployment_target = '14.0'
1515
s.dependency 'Capacitor'
1616
s.swift_version = '5.1'
17-
s.dependency "QonversionSandwich", "7.7.0"
17+
s.dependency "QonversionSandwich", "7.9.0"
1818
end

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ dependencies {
6161
implementation project(':capacitor-android')
6262
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
6363
implementation 'androidx.core:core-ktx:1.13.1'
64-
implementation "io.qonversion:sandwich:7.7.0"
64+
implementation "io.qonversion:sandwich:7.9.0"
6565
testImplementation "junit:junit:$junitVersion"
6666
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
6767
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"

android/src/main/java/io/qonversion/capacitor/NoCodesPlugin.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ class NoCodesPlugin : Plugin() {
8181
val contextKey = call.getString("contextKey")
8282
?: return call.noNecessaryDataError("contextKey")
8383

84-
noCodesSandwich.showScreen(contextKey)
84+
val customVariablesJson = call.getObject("customVariables")
85+
val customVariables: Map<String, String>? = customVariablesJson?.let { json ->
86+
buildMap {
87+
json.keys().forEach { key ->
88+
(json.opt(key) as? String)?.let { value -> put(key, value) }
89+
}
90+
}
91+
}
92+
93+
noCodesSandwich.showScreen(contextKey, customVariables)
8594
call.resolve()
8695
}
8796

android/src/main/java/io/qonversion/capacitor/QonversionPlugin.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import io.qonversion.sandwich.QonversionSandwich
1212
import io.qonversion.sandwich.BridgeData
1313

1414
private const val EntitlementsUpdatedEvent = "entitlementsUpdatedEvent"
15+
private const val DeferredPurchaseCompletedEvent = "deferredPurchaseCompletedEvent"
1516

1617
@CapacitorPlugin(name = "Qonversion")
1718
class QonversionPlugin : Plugin() {
@@ -33,6 +34,10 @@ class QonversionPlugin : Plugin() {
3334
override fun onEntitlementsUpdated(entitlements: BridgeData) {
3435
notifyListeners(EntitlementsUpdatedEvent, entitlements.toJSObject())
3536
}
37+
38+
override fun onDeferredPurchaseCompleted(transaction: BridgeData) {
39+
notifyListeners(DeferredPurchaseCompletedEvent, transaction.toJSObject())
40+
}
3641
}
3742

3843
@PluginMethod
@@ -106,6 +111,13 @@ class QonversionPlugin : Plugin() {
106111
qonversionSandwich.userProperties(call.toResultListener())
107112
}
108113

114+
@PluginMethod
115+
fun forceSendProperties(call: PluginCall) {
116+
qonversionSandwich.forceSendProperties {
117+
call.resolve()
118+
}
119+
}
120+
109121
@PluginMethod
110122
fun isFallbackFileAccessible(call: PluginCall) {
111123
qonversionSandwich.isFallbackFileAccessible(call.toResultListener())

ios/Sources/QonversionPlugin/NoCodesPlugin.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,18 @@ public class NoCodesPlugin: CAPPlugin, CAPBridgedPlugin {
6767
return call.noNecessaryDataError()
6868
}
6969

70+
let customVariables: [String: String]? = call.getObject("customVariables").map { rawObject in
71+
var result: [String: String] = [:]
72+
for (key, value) in rawObject {
73+
if let stringValue = value as? String {
74+
result[key] = stringValue
75+
}
76+
}
77+
return result
78+
}
79+
7080
DispatchQueue.main.async { [weak self] in
71-
self?.noCodesSandwich?.showScreen(contextKey)
81+
self?.noCodesSandwich?.showScreen(contextKey, customVariables: customVariables)
7282
}
7383
call.resolve()
7484
}

ios/Sources/QonversionPlugin/QonversionPlugin.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class QonversionPlugin: CAPPlugin, CAPBridgedPlugin {
1919
CAPPluginMethod(name: "remoteConfigList", returnType: CAPPluginReturnPromise),
2020
CAPPluginMethod(name: "userInfo", returnType: CAPPluginReturnPromise),
2121
CAPPluginMethod(name: "userProperties", returnType: CAPPluginReturnPromise),
22+
CAPPluginMethod(name: "forceSendProperties", returnType: CAPPluginReturnPromise),
2223
CAPPluginMethod(name: "restore", returnType: CAPPluginReturnPromise),
2324
CAPPluginMethod(name: "offerings", returnType: CAPPluginReturnPromise),
2425
CAPPluginMethod(name: "setDefinedUserProperty", returnType: CAPPluginReturnPromise),
@@ -138,6 +139,12 @@ public class QonversionPlugin: CAPPlugin, CAPBridgedPlugin {
138139
qonversionSandwich?.userProperties(getDefaultCompletion(call))
139140
}
140141

142+
@objc func forceSendProperties(_ call: CAPPluginCall) {
143+
qonversionSandwich?.forceSendProperties {
144+
call.resolve()
145+
}
146+
}
147+
141148
@objc func restore(_ call: CAPPluginCall) {
142149
qonversionSandwich?.restore(getDefaultCompletion(call))
143150
}
@@ -276,6 +283,10 @@ extension QonversionPlugin: QonversionEventListener {
276283
self.notifyListeners("entitlementsUpdatedEvent", data: entitlements)
277284
}
278285

286+
public func qonversionDidCompleteDeferredPurchase(_ transaction: [String : Any]) {
287+
self.notifyListeners("deferredPurchaseCompletedEvent", data: transaction)
288+
}
289+
279290
public func shouldPurchasePromoProduct(with productId: String) {
280291
self.notifyListeners("shouldPurchasePromoProductEvent", data: ["productId": productId])
281292
}

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
testMatch: ['<rootDir>/src/**/__tests__/**/*.test.ts'],
6+
moduleFileExtensions: ['ts', 'js'],
7+
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qonversion/capacitor-plugin",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "Qonversion provides full in-app purchases infrastructure, so you do not need to build your own server for receipt validation. Implement in-app subscriptions, validate user receipts, check subscription status, and provide access to your app features and content using our StoreKit wrapper and Google Play Billing wrapper.",
55
"main": "dist/plugin.cjs.js",
66
"module": "dist/esm/index.js",
@@ -55,6 +55,7 @@
5555
"build": "npm run clean && tsc && rollup -c rollup.config.js",
5656
"clean": "./node_modules/rimraf/bin.js ./dist",
5757
"watch": "tsc --watch",
58+
"test": "jest",
5859
"prepublishOnly": "npm run build",
5960
"deploy": "npm publish"
6061
},
@@ -66,12 +67,15 @@
6667
"@ionic/eslint-config": "^0.4.0",
6768
"@ionic/prettier-config": "^1.0.1",
6869
"@ionic/swiftlint-config": "^1.1.2",
70+
"@types/jest": "^30.0.0",
6971
"eslint": "^8.57.0",
72+
"jest": "^30.3.0",
7073
"prettier": "~2.3.0",
7174
"prettier-plugin-java": "~1.0.2",
7275
"rimraf": "^3.0.2",
7376
"rollup": "^2.32.0",
7477
"swiftlint": "^1.0.1",
78+
"ts-jest": "^29.4.9",
7579
"typescript": "^5.0.0",
7680
"yarn": "^1.22.22"
7781
},

src/NoCodesApi.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ export interface NoCodesApi {
2121

2222
/**
2323
* Show the screen using its context key.
24-
* @param contextKey the context key of the screen which must be shown
24+
* @param contextKey the context key of the screen which must be shown.
25+
* @param customVariables optional map of custom variables that will be injected
26+
* into the screen's JavaScript context. Variables are scoped
27+
* to the provided contextKey and only applied to that screen.
2528
*/
26-
showScreen(contextKey: string): void;
29+
showScreen(contextKey: string, customVariables?: Record<string, string>): void;
2730

2831
/**
2932
* Close the current opened No-Code screen.

src/NoCodesNativePlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface NoCodesNativePlugin {
2121
contextKey?: string;
2222
}): Promise<void>;
2323

24-
showScreen(params: { contextKey: string }): Promise<void>;
24+
showScreen(params: { contextKey: string; customVariables?: Record<string, string> }): Promise<void>;
2525

2626
close(): Promise<void>;
2727

0 commit comments

Comments
 (0)