capacitor-native-purchases 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ import Foundation
2
+ import Capacitor
3
+ import StoreKit
4
+
5
+ /**
6
+ * Please read the Capacitor iOS Plugin Development Guide
7
+ * here: https://capacitorjs.com/docs/plugins/ios
8
+ */
9
+ @objc(PurchasesPlugin)
10
+ public class PurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
11
+ public let identifier = "PurchasesPlugin"
12
+ public let jsName = "Purchases"
13
+ public let pluginMethods: [CAPPluginMethod] = [
14
+ CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
15
+ CAPPluginMethod(name: "getProductDetails", returnType: CAPPluginReturnPromise),
16
+ CAPPluginMethod(name: "purchaseProduct", returnType: CAPPluginReturnPromise),
17
+ CAPPluginMethod(name: "getCurrentEntitlements", returnType: CAPPluginReturnPromise),
18
+ CAPPluginMethod(name: "restorePurchases", returnType: CAPPluginReturnPromise),
19
+ CAPPluginMethod(name: "getLatestTransaction", returnType: CAPPluginReturnPromise),
20
+ CAPPluginMethod(name: "manageSubscriptions", returnType: CAPPluginReturnPromise),
21
+ ]
22
+ private let implementation = Purchases()
23
+
24
+ @objc func echo(_ call: CAPPluginCall) {
25
+ let value = call.getString("value") ?? ""
26
+ call.resolve([
27
+ "value": implementation.echo(value)
28
+ ])
29
+ }
30
+
31
+ @available(iOS 15.0.0, *)
32
+ @objc func getProductDetails(_ call: CAPPluginCall) {
33
+ guard let productIdentifier = call.getString("productIdentifier") else {
34
+ call.reject("Must provide a productID")
35
+ return
36
+ }
37
+
38
+ Task {
39
+ do {
40
+ let response = await implementation.getProductDetails(productIdentifier)
41
+ call.resolve(response)
42
+ }
43
+ }
44
+ }
45
+
46
+ @available(iOS 15.0.0, *)
47
+ @objc func purchaseProduct(_ call: CAPPluginCall) {
48
+ guard let productIdentifier = call.getString("productIdentifier") else {
49
+ call.reject("Must provide a productID")
50
+ return
51
+ }
52
+
53
+ let userId = call.getString("userId")
54
+
55
+ Task {
56
+ do {
57
+ let response = await implementation.purchaseProduct(productIdentifier, userId: userId)
58
+ call.resolve(response)
59
+ }
60
+ }
61
+ }
62
+
63
+ @available(iOS 15.0.0, *)
64
+ @objc func getCurrentEntitlements(_ call: CAPPluginCall) {
65
+ Task {
66
+ do {
67
+ let response = await implementation.getCurrentEntitlements()
68
+ call.resolve(response)
69
+ }
70
+ }
71
+ }
72
+
73
+
74
+ @available(iOS 15.0.0, *)
75
+ @objc func restorePurchases(_ call: CAPPluginCall) {
76
+ Task {
77
+ do {
78
+ try await AppStore.sync()
79
+ // Optionally alert the user that restore succeeded
80
+
81
+ call.resolve(["completed": true])
82
+ } catch {
83
+ print("Restore purchases failed:", error)
84
+ // Handle error (e.g., show alert)
85
+ call.resolve(["completed": false])
86
+ }
87
+ }
88
+ }
89
+
90
+
91
+ @available(iOS 15.0.0, *)
92
+ @objc func getLatestTransaction(_ call: CAPPluginCall) {
93
+ guard let productIdentifier = call.getString("productIdentifier") else {
94
+ call.reject("Must provide a productID")
95
+ return;
96
+ }
97
+
98
+ Task {
99
+ do {
100
+ let response = await implementation.getLatestTransaction(productIdentifier)
101
+ call.resolve(response)
102
+ }
103
+ }
104
+ }
105
+
106
+ @available(iOS 15.0.0, *)
107
+ @objc func manageSubscriptions(_ call: CAPPluginCall) {
108
+ Task {
109
+ do {
110
+ await implementation.manageSubscriptions()
111
+ call.resolve(["Success": "Opened"])
112
+ }
113
+ }
114
+ }
115
+
116
+ }
@@ -0,0 +1,15 @@
1
+ import XCTest
2
+ @testable import PurchasesPlugin
3
+
4
+ class PurchasesTests: XCTestCase {
5
+ func testEcho() {
6
+ // This is an example of a functional test case for a plugin.
7
+ // Use XCTAssert and related functions to verify your tests produce the correct results.
8
+
9
+ let implementation = Purchases()
10
+ let value = "Hello, World!"
11
+ let result = implementation.echo(value)
12
+
13
+ XCTAssertEqual(value, result)
14
+ }
15
+ }
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "capacitor-native-purchases",
3
+ "version": "0.1.1",
4
+ "description": "IAP Purchases integration for iOS and Android",
5
+ "main": "dist/plugin.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "unpkg": "dist/plugin.js",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "files": [
13
+ "android/src/main/",
14
+ "android/build.gradle",
15
+ "dist/",
16
+ "ios/Sources",
17
+ "ios/Tests",
18
+ "Package.swift",
19
+ "CapacitorPurchases.podspec"
20
+ ],
21
+ "author": "Jok Entertainers, Inc.",
22
+ "license": "MIT",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/jokio/capacitor-purchases.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/jokio/capacitor-purchases/issues"
29
+ },
30
+ "keywords": [
31
+ "capacitor",
32
+ "plugin",
33
+ "native"
34
+ ],
35
+ "scripts": {
36
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
37
+ "verify:ios": "xcodebuild -scheme CapacitorPurchases -destination generic/platform=iOS",
38
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
39
+ "verify:web": "npm run build",
40
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
41
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
42
+ "eslint": "eslint . --ext ts",
43
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
44
+ "swiftlint": "node-swiftlint",
45
+ "docgen": "docgen --api PurchasesPlugin --output-readme README.md --output-json dist/docs.json",
46
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
47
+ "clean": "rimraf ./dist",
48
+ "watch": "tsc --watch",
49
+ "prepublishOnly": "npm run build"
50
+ },
51
+ "devDependencies": {
52
+ "@capacitor/android": "^8.0.0",
53
+ "@capacitor/core": "^8.0.0",
54
+ "@capacitor/docgen": "^0.3.1",
55
+ "@capacitor/ios": "^8.0.0",
56
+ "@ionic/eslint-config": "^0.4.0",
57
+ "@ionic/prettier-config": "^4.0.0",
58
+ "@ionic/swiftlint-config": "^2.0.0",
59
+ "eslint": "^8.57.1",
60
+ "prettier": "^3.6.2",
61
+ "prettier-plugin-java": "^2.7.7",
62
+ "rimraf": "^6.1.0",
63
+ "rollup": "^4.53.2",
64
+ "swiftlint": "^2.0.0",
65
+ "typescript": "^5.9.3"
66
+ },
67
+ "peerDependencies": {
68
+ "@capacitor/core": ">=8.0.0"
69
+ },
70
+ "prettier": "@ionic/prettier-config",
71
+ "swiftlint": "@ionic/swiftlint-config",
72
+ "eslintConfig": {
73
+ "extends": "@ionic/eslint-config/recommended"
74
+ },
75
+ "capacitor": {
76
+ "ios": {
77
+ "src": "ios"
78
+ },
79
+ "android": {
80
+ "src": "android"
81
+ }
82
+ }
83
+ }