@capgo/native-purchases 0.0.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.
- package/NativePurchases.podspec +17 -0
- package/README.md +137 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/ee/forgr/nativepurchases/NativePurchasesPlugin.java +195 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +371 -0
- package/dist/esm/definitions.d.ts +305 -0
- package/dist/esm/definitions.js +128 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +19 -0
- package/dist/esm/web.js +28 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +162 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +165 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/NativePurchasesPlugin.h +10 -0
- package/ios/Plugin/NativePurchasesPlugin.m +10 -0
- package/ios/Plugin/NativePurchasesPlugin.swift +102 -0
- package/ios/Plugin/Product+CapacitorPurchasesPlugin.swift +52 -0
- package/package.json +78 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
|
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
+
CAP_PLUGIN(NativePurchasesPlugin, "NativePurchases",
|
|
7
|
+
CAP_PLUGIN_METHOD(getProducts, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(purchaseProduct, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(restorePurchases, CAPPluginReturnPromise);
|
|
10
|
+
)
|
|
@@ -0,0 +1,102 @@
|
|
|
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(NativePurchasesPlugin)
|
|
10
|
+
public class NativePurchasesPlugin: CAPPlugin {
|
|
11
|
+
|
|
12
|
+
private let PLUGIN_VERSION = "2.0.13"
|
|
13
|
+
|
|
14
|
+
@objc func purchaseProduct(_ call: CAPPluginCall) async {
|
|
15
|
+
if #available(iOS 15, *) {
|
|
16
|
+
print("purchaseProduct")
|
|
17
|
+
let productIdentifier = call.getString("productIdentifier", "")
|
|
18
|
+
let quantity = call.getInt("quantity", 1)
|
|
19
|
+
if (productIdentifier.isEmpty) {
|
|
20
|
+
call.reject("productIdentifier is Empty, give an id")
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
do {
|
|
24
|
+
let products = try await Product.products(for: [productIdentifier])
|
|
25
|
+
let product = products[0]
|
|
26
|
+
var purchaseOptions = Set<Product.PurchaseOption>()
|
|
27
|
+
purchaseOptions.insert(Product.PurchaseOption.quantity(quantity))
|
|
28
|
+
let result = try await product.purchase(options: purchaseOptions)
|
|
29
|
+
print("purchaseProduct result \(result)")
|
|
30
|
+
switch result {
|
|
31
|
+
case let .success(.verified(transaction)):
|
|
32
|
+
// Successful purhcase
|
|
33
|
+
await transaction.finish()
|
|
34
|
+
call.resolve(["transactionId": transaction.id])
|
|
35
|
+
break
|
|
36
|
+
case let .success(.unverified(_, error)):
|
|
37
|
+
// Successful purchase but transaction/receipt can't be verified
|
|
38
|
+
// Could be a jailbroken phone
|
|
39
|
+
call.reject(error.localizedDescription)
|
|
40
|
+
break
|
|
41
|
+
case .pending:
|
|
42
|
+
// Transaction waiting on SCA (Strong Customer Authentication) or
|
|
43
|
+
// approval from Ask to Buy
|
|
44
|
+
call.reject("Transaction pending")
|
|
45
|
+
break
|
|
46
|
+
case .userCancelled:
|
|
47
|
+
// ^^^
|
|
48
|
+
call.reject("User cancelled")
|
|
49
|
+
break
|
|
50
|
+
@unknown default:
|
|
51
|
+
call.reject("Unknown error")
|
|
52
|
+
break
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
print(error)
|
|
56
|
+
call.reject(error.localizedDescription)
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
print("Not implemented under ios 15")
|
|
60
|
+
call.reject("Not implemented under ios 15")
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@objc func restorePurchases(_ call: CAPPluginCall) async {
|
|
66
|
+
if #available(iOS 15.0, *) {
|
|
67
|
+
print("restorePurchases")
|
|
68
|
+
do {
|
|
69
|
+
try await AppStore.sync()
|
|
70
|
+
call.resolve()
|
|
71
|
+
} catch {
|
|
72
|
+
print(error)
|
|
73
|
+
call.reject(error.localizedDescription)
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
print("Not implemented under ios 15")
|
|
77
|
+
call.reject("Not implemented under ios 15")
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@objc func getProducts(_ call: CAPPluginCall) async {
|
|
82
|
+
if #available(iOS 15.0, *) {
|
|
83
|
+
let productIdentifiers = call.getArray("productIdentifiers", String.self) ?? []
|
|
84
|
+
do {
|
|
85
|
+
let products = try await Product.products(for: productIdentifiers)
|
|
86
|
+
let productsJson = products.map { (product) -> [String: Any] in
|
|
87
|
+
return product.dictionary
|
|
88
|
+
}
|
|
89
|
+
call.resolve([
|
|
90
|
+
"products": productsJson
|
|
91
|
+
])
|
|
92
|
+
} catch {
|
|
93
|
+
print(error)
|
|
94
|
+
call.reject(error.localizedDescription)
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
print("Not implemented under ios 15")
|
|
98
|
+
call.reject("Not implemented under ios 15")
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Extensions.swift
|
|
3
|
+
// CapgoCapacitorPurchases
|
|
4
|
+
//
|
|
5
|
+
// Created by Martin DONADIEU on 2023-08-08.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import StoreKit
|
|
10
|
+
|
|
11
|
+
@available(iOS 15.0, *)
|
|
12
|
+
extension Product {
|
|
13
|
+
|
|
14
|
+
var dictionary: [String: Any] {
|
|
15
|
+
// /**
|
|
16
|
+
// * Currency code for price and original price.
|
|
17
|
+
// */
|
|
18
|
+
// readonly currencyCode: string;
|
|
19
|
+
// /**
|
|
20
|
+
// * Currency symbol for price and original price.
|
|
21
|
+
// */
|
|
22
|
+
// readonly currencySymbol: string;
|
|
23
|
+
// /**
|
|
24
|
+
// * Boolean indicating if the product is sharable with family
|
|
25
|
+
// */
|
|
26
|
+
// readonly isFamilyShareable: boolean;
|
|
27
|
+
// /**
|
|
28
|
+
// * Group identifier for the product.
|
|
29
|
+
// */
|
|
30
|
+
// readonly subscriptionGroupIdentifier: string;
|
|
31
|
+
// /**
|
|
32
|
+
// * The Product subcription group identifier.
|
|
33
|
+
// */
|
|
34
|
+
// readonly subscriptionPeriod: SubscriptionPeriod;
|
|
35
|
+
// /**
|
|
36
|
+
// * The Product introductory Price.
|
|
37
|
+
// */
|
|
38
|
+
// readonly introductoryPrice: SKProductDiscount | null;
|
|
39
|
+
// /**
|
|
40
|
+
// * The Product discounts list.
|
|
41
|
+
// */
|
|
42
|
+
// readonly discounts: SKProductDiscount[];
|
|
43
|
+
return [
|
|
44
|
+
"identifier": self.id,
|
|
45
|
+
"description": self.description,
|
|
46
|
+
"title": self.displayName,
|
|
47
|
+
"price": self.price,
|
|
48
|
+
"priceString": self.displayPrice,
|
|
49
|
+
"isFamilyShareable": self.isFamilyShareable,
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capgo/native-purchases",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "In-app Subscriptions Made Easy",
|
|
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
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"NativePurchases.podspec"
|
|
15
|
+
],
|
|
16
|
+
"author": "Martin donadieu",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Cap-go/native-purchases.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/Cap-go/native-purchases/issues"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"capacitor",
|
|
27
|
+
"plugin",
|
|
28
|
+
"native"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
32
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
33
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
34
|
+
"verify:web": "npm run build",
|
|
35
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
36
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
37
|
+
"eslint": "eslint . --ext ts",
|
|
38
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
39
|
+
"swiftlint": "node-swiftlint",
|
|
40
|
+
"docgen": "docgen --api NativePurchasesPlugin --output-readme README.md --output-json dist/docs.json",
|
|
41
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
|
|
42
|
+
"clean": "rimraf ./dist",
|
|
43
|
+
"watch": "tsc --watch",
|
|
44
|
+
"prepublishOnly": "npm run build"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@capacitor/android": "^5.0.0",
|
|
48
|
+
"@capacitor/core": "^5.0.0",
|
|
49
|
+
"@capacitor/docgen": "^0.0.18",
|
|
50
|
+
"@capacitor/ios": "^5.0.0",
|
|
51
|
+
"@ionic/eslint-config": "^0.3.0",
|
|
52
|
+
"@ionic/prettier-config": "^1.0.1",
|
|
53
|
+
"@ionic/swiftlint-config": "^1.1.2",
|
|
54
|
+
"eslint": "^7.11.0",
|
|
55
|
+
"prettier": "~2.3.0",
|
|
56
|
+
"prettier-plugin-java": "~1.0.2",
|
|
57
|
+
"rimraf": "^3.0.2",
|
|
58
|
+
"rollup": "^2.32.0",
|
|
59
|
+
"swiftlint": "^1.0.1",
|
|
60
|
+
"typescript": "~4.1.5"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@capacitor/core": "^5.0.0"
|
|
64
|
+
},
|
|
65
|
+
"prettier": "@ionic/prettier-config",
|
|
66
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
67
|
+
"eslintConfig": {
|
|
68
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
69
|
+
},
|
|
70
|
+
"capacitor": {
|
|
71
|
+
"ios": {
|
|
72
|
+
"src": "ios"
|
|
73
|
+
},
|
|
74
|
+
"android": {
|
|
75
|
+
"src": "android"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|