@dicty/payment 2.0.0
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/DictyPayment.podspec +17 -0
- package/README.md +249 -0
- package/android/build.gradle +66 -0
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/java/app/dicty/plugins/stripe/GooglePayEvents.java +21 -0
- package/android/src/main/java/app/dicty/plugins/stripe/MetaData.java +38 -0
- package/android/src/main/java/app/dicty/plugins/stripe/PaymentPlugin.java +90 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +425 -0
- package/dist/esm/definitions.d.ts +98 -0
- package/dist/esm/definitions.js +2 -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/provider/react/PaymentPluginProvider.d.ts +7 -0
- package/dist/esm/provider/react/PaymentPluginProvider.js +52 -0
- package/dist/esm/provider/react/PaymentPluginProvider.js.map +1 -0
- package/dist/esm/web.d.ts +17 -0
- package/dist/esm/web.js +31 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +45 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +48 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/PaymentPlugin/InAppPurchaseStatus.swift +6 -0
- package/ios/Sources/PaymentPlugin/Info.plist +24 -0
- package/ios/Sources/PaymentPlugin/PaymentPlugin.swift +256 -0
- package/package.json +93 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const Payment = core.registerPlugin('Payment', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PaymentWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class PaymentWeb extends core.WebPlugin {
|
|
10
|
+
/**
|
|
11
|
+
* Apple
|
|
12
|
+
*/
|
|
13
|
+
isAppleInAppPurchaseAvailable() {
|
|
14
|
+
return Promise.reject('Not supported');
|
|
15
|
+
}
|
|
16
|
+
getAppleInAppPurchaseProducts(_opts) {
|
|
17
|
+
return Promise.reject('Not supported');
|
|
18
|
+
}
|
|
19
|
+
buyAppleInAppPurchase(_opts) {
|
|
20
|
+
return Promise.reject('Not supported');
|
|
21
|
+
}
|
|
22
|
+
restoreAppleInAppPurchase() {
|
|
23
|
+
return Promise.reject('Not supported');
|
|
24
|
+
}
|
|
25
|
+
getAppleInAppPurchaseReceipt() {
|
|
26
|
+
return Promise.reject('Not supported');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Google
|
|
30
|
+
*/
|
|
31
|
+
isGooglePayAvailable() {
|
|
32
|
+
return Promise.reject('Not supported');
|
|
33
|
+
}
|
|
34
|
+
handleGooglePay(_opts) {
|
|
35
|
+
return Promise.reject('Not supported');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
40
|
+
__proto__: null,
|
|
41
|
+
PaymentWeb: PaymentWeb
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
exports.Payment = Payment;
|
|
45
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Payment = registerPlugin('Payment', {\n web: () => import('./web').then((m) => new m.PaymentWeb()),\n});\nexport * from './definitions';\nexport { Payment };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PaymentWeb extends WebPlugin {\n /**\n * Apple\n */\n isAppleInAppPurchaseAvailable() {\n return Promise.reject('Not supported');\n }\n getAppleInAppPurchaseProducts(_opts) {\n return Promise.reject('Not supported');\n }\n buyAppleInAppPurchase(_opts) {\n return Promise.reject('Not supported');\n }\n restoreAppleInAppPurchase() {\n return Promise.reject('Not supported');\n }\n getAppleInAppPurchaseReceipt() {\n return Promise.reject('Not supported');\n }\n /**\n * Google\n */\n isGooglePayAvailable() {\n return Promise.reject('Not supported');\n }\n handleGooglePay(_opts) {\n return Promise.reject('Not supported');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,OAAO,GAAGA,mBAAc,CAAC,SAAS,EAAE;AAC1C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;AAC9D,CAAC;;ACFM,MAAM,UAAU,SAASC,cAAS,CAAC;AAC1C;AACA;AACA;AACA,IAAI,6BAA6B,GAAG;AACpC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;AAC9C,IAAI;AACJ,IAAI,6BAA6B,CAAC,KAAK,EAAE;AACzC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;AAC9C,IAAI;AACJ,IAAI,qBAAqB,CAAC,KAAK,EAAE;AACjC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;AAC9C,IAAI;AACJ,IAAI,yBAAyB,GAAG;AAChC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;AAC9C,IAAI;AACJ,IAAI,4BAA4B,GAAG;AACnC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;AAC9C,IAAI;AACJ;AACA;AACA;AACA,IAAI,oBAAoB,GAAG;AAC3B,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;AAC9C,IAAI;AACJ,IAAI,eAAe,CAAC,KAAK,EAAE;AAC3B,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;AAC9C,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var capacitorPayment = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const Payment = core.registerPlugin('Payment', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PaymentWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class PaymentWeb extends core.WebPlugin {
|
|
9
|
+
/**
|
|
10
|
+
* Apple
|
|
11
|
+
*/
|
|
12
|
+
isAppleInAppPurchaseAvailable() {
|
|
13
|
+
return Promise.reject('Not supported');
|
|
14
|
+
}
|
|
15
|
+
getAppleInAppPurchaseProducts(_opts) {
|
|
16
|
+
return Promise.reject('Not supported');
|
|
17
|
+
}
|
|
18
|
+
buyAppleInAppPurchase(_opts) {
|
|
19
|
+
return Promise.reject('Not supported');
|
|
20
|
+
}
|
|
21
|
+
restoreAppleInAppPurchase() {
|
|
22
|
+
return Promise.reject('Not supported');
|
|
23
|
+
}
|
|
24
|
+
getAppleInAppPurchaseReceipt() {
|
|
25
|
+
return Promise.reject('Not supported');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Google
|
|
29
|
+
*/
|
|
30
|
+
isGooglePayAvailable() {
|
|
31
|
+
return Promise.reject('Not supported');
|
|
32
|
+
}
|
|
33
|
+
handleGooglePay(_opts) {
|
|
34
|
+
return Promise.reject('Not supported');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
39
|
+
__proto__: null,
|
|
40
|
+
PaymentWeb: PaymentWeb
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
exports.Payment = Payment;
|
|
44
|
+
|
|
45
|
+
return exports;
|
|
46
|
+
|
|
47
|
+
})({}, capacitorExports);
|
|
48
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Payment = registerPlugin('Payment', {\n web: () => import('./web').then((m) => new m.PaymentWeb()),\n});\nexport * from './definitions';\nexport { Payment };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class PaymentWeb extends WebPlugin {\n /**\n * Apple\n */\n isAppleInAppPurchaseAvailable() {\n return Promise.reject('Not supported');\n }\n getAppleInAppPurchaseProducts(_opts) {\n return Promise.reject('Not supported');\n }\n buyAppleInAppPurchase(_opts) {\n return Promise.reject('Not supported');\n }\n restoreAppleInAppPurchase() {\n return Promise.reject('Not supported');\n }\n getAppleInAppPurchaseReceipt() {\n return Promise.reject('Not supported');\n }\n /**\n * Google\n */\n isGooglePayAvailable() {\n return Promise.reject('Not supported');\n }\n handleGooglePay(_opts) {\n return Promise.reject('Not supported');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,OAAO,GAAGA,mBAAc,CAAC,SAAS,EAAE;IAC1C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;IAC9D,CAAC;;ICFM,MAAM,UAAU,SAASC,cAAS,CAAC;IAC1C;IACA;IACA;IACA,IAAI,6BAA6B,GAAG;IACpC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAC9C,IAAI;IACJ,IAAI,6BAA6B,CAAC,KAAK,EAAE;IACzC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAC9C,IAAI;IACJ,IAAI,qBAAqB,CAAC,KAAK,EAAE;IACjC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAC9C,IAAI;IACJ,IAAI,yBAAyB,GAAG;IAChC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAC9C,IAAI;IACJ,IAAI,4BAA4B,GAAG;IACnC,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAC9C,IAAI;IACJ;IACA;IACA;IACA,IAAI,oBAAoB,GAAG;IAC3B,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAC9C,IAAI;IACJ,IAAI,eAAe,CAAC,KAAK,EAAE;IAC3B,QAAQ,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;IAC9C,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import PassKit
|
|
4
|
+
import StoreKit
|
|
5
|
+
|
|
6
|
+
@objc(PaymentPlugin)
|
|
7
|
+
public class PaymentPlugin: CAPPlugin, CAPBridgedPlugin, SKProductsRequestDelegate {
|
|
8
|
+
public let identifier = "PaymentPlugin"
|
|
9
|
+
public let jsName = "Payment"
|
|
10
|
+
private var delayedCallId: String?
|
|
11
|
+
private var productsRequest: SKProductsRequest?
|
|
12
|
+
|
|
13
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
14
|
+
CAPPluginMethod(name: "isAppleInAppPurchaseAvailable", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "getAppleInAppPurchaseProducts", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "buyAppleInAppPurchase", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "restoreAppleInAppPurchase", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "getAppleInAppPurchaseReceipt", returnType: CAPPluginReturnPromise),
|
|
19
|
+
CAPPluginMethod(name: "isGooglePayAvailable", returnType: CAPPluginReturnPromise),
|
|
20
|
+
CAPPluginMethod(name: "handleGooglePay", returnType: CAPPluginReturnPromise)
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
override public func load() {
|
|
24
|
+
super.load()
|
|
25
|
+
SKPaymentQueue.default().add(self);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc func isAppleInAppPurchaseAvailable(_ call: CAPPluginCall) {
|
|
29
|
+
if (!SKPaymentQueue.canMakePayments()) {
|
|
30
|
+
print("In App purchased are not available")
|
|
31
|
+
call.reject("Can not use on this Device.")
|
|
32
|
+
}
|
|
33
|
+
print("In App purchased are available")
|
|
34
|
+
call.resolve()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@objc func getAppleInAppPurchaseProducts(_ call: CAPPluginCall) {
|
|
38
|
+
guard let productIdentifiers = call.options["id"] as? [String], !productIdentifiers.isEmpty else {
|
|
39
|
+
call.reject("Call must provide \"id\" array")
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
print("Start loading in app purchase products \(productIdentifiers)")
|
|
44
|
+
// save call for processing
|
|
45
|
+
bridge?.saveCall(call)
|
|
46
|
+
delayedCallId = call.callbackId;
|
|
47
|
+
|
|
48
|
+
productsRequest?.cancel()
|
|
49
|
+
productsRequest = SKProductsRequest(productIdentifiers: Set(productIdentifiers))
|
|
50
|
+
productsRequest!.delegate = self
|
|
51
|
+
productsRequest!.start()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@objc func buyAppleInAppPurchase(_ call: CAPPluginCall) {
|
|
55
|
+
if (!SKPaymentQueue.canMakePayments()) {
|
|
56
|
+
call.reject("Can not use on this Device.")
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
guard let productIdentifier = call.options["id"] as? String, !productIdentifier.isEmpty else {
|
|
60
|
+
call.reject("Call must provide \"id\"")
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
print("Start buying in app purchase \(productIdentifier)")
|
|
65
|
+
|
|
66
|
+
bridge?.saveCall(call)
|
|
67
|
+
delayedCallId = call.callbackId;
|
|
68
|
+
|
|
69
|
+
let request = SKMutablePayment();
|
|
70
|
+
request.productIdentifier = productIdentifier;
|
|
71
|
+
SKPaymentQueue.default().add(request);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@objc func restoreAppleInAppPurchase(_ call: CAPPluginCall) {
|
|
75
|
+
print("Start restoring in app purchases")
|
|
76
|
+
bridge?.saveCall(call)
|
|
77
|
+
delayedCallId = call.callbackId;
|
|
78
|
+
SKPaymentQueue.default().restoreCompletedTransactions()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@objc func getAppleInAppPurchaseReceipt(_ call: CAPPluginCall) {
|
|
82
|
+
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL, FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {
|
|
83
|
+
do {
|
|
84
|
+
let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)
|
|
85
|
+
print("Retrieved receipt data")
|
|
86
|
+
print(receiptData)
|
|
87
|
+
let receiptString = receiptData.base64EncodedString(options: [])
|
|
88
|
+
call.resolve(["receiptData": receiptString])
|
|
89
|
+
return
|
|
90
|
+
} catch {
|
|
91
|
+
print("Couldn't read receipt data with error: \(error.localizedDescription)")
|
|
92
|
+
call.reject("Couldn't read receipt data")
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
call.reject("Couldn't get a valid receipt")
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
|
|
100
|
+
|
|
101
|
+
if let callId = delayedCallId, let call = bridge?.savedCall(withID: callId) {
|
|
102
|
+
delayedCallId = nil
|
|
103
|
+
productsRequest = nil
|
|
104
|
+
|
|
105
|
+
if response.products.isEmpty {
|
|
106
|
+
print("No products are available")
|
|
107
|
+
call.reject("No products are available")
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
print("Retrieved products")
|
|
112
|
+
print(response.products)
|
|
113
|
+
|
|
114
|
+
var productsData: [Any] = []
|
|
115
|
+
for product in response.products {
|
|
116
|
+
let productData: [String: Any?] = [
|
|
117
|
+
"id": product.productIdentifier,
|
|
118
|
+
"title": product.localizedTitle,
|
|
119
|
+
"description": product.localizedDescription,
|
|
120
|
+
"price": product.price,
|
|
121
|
+
"localizedPrice": product.localizedPrice,
|
|
122
|
+
"subscriptionPeriod": product.subscriptionPeriod !== nil ? [
|
|
123
|
+
"value": product.subscriptionPeriod?.numberOfUnits ?? nil,
|
|
124
|
+
"unit": product.subscriptionPeriod?.unit.rawValue ?? nil,
|
|
125
|
+
] : nil,
|
|
126
|
+
];
|
|
127
|
+
productsData.append(productData)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
call.resolve(["products": productsData])
|
|
131
|
+
bridge?.releaseCall(withID: callId)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@objc func isGooglePayAvailable(_ call: CAPPluginCall) {
|
|
137
|
+
call.unavailable("Not implemented on iOS")
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@objc func handleGooglePay(_ call: CAPPluginCall) {
|
|
141
|
+
call.unavailable("Not implemented on iOS")
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
extension PaymentPlugin: SKPaymentTransactionObserver {
|
|
146
|
+
public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
|
|
147
|
+
for transaction in transactions {
|
|
148
|
+
switch transaction.transactionState {
|
|
149
|
+
case .purchased:
|
|
150
|
+
print("Product purchased, \(transaction.payment.productIdentifier), \(String(describing: transaction.transactionIdentifier))")
|
|
151
|
+
resolve(
|
|
152
|
+
transaction: transaction,
|
|
153
|
+
status: .Completed,
|
|
154
|
+
productIdentifier: transaction.payment.productIdentifier,
|
|
155
|
+
transactionIdentifier: transaction.transactionIdentifier
|
|
156
|
+
)
|
|
157
|
+
return
|
|
158
|
+
case .failed:
|
|
159
|
+
let productIdentifier = transaction.original?.payment.productIdentifier ?? transaction.payment.productIdentifier;
|
|
160
|
+
if let transactionError = transaction.error as NSError? {
|
|
161
|
+
if (transactionError.code == SKError.paymentCancelled.rawValue) {
|
|
162
|
+
print("Purchasing cancelled, \(productIdentifier)")
|
|
163
|
+
resolve(
|
|
164
|
+
transaction: transaction,
|
|
165
|
+
status: .Cancelled,
|
|
166
|
+
productIdentifier: productIdentifier,
|
|
167
|
+
transactionIdentifier: nil
|
|
168
|
+
)
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
print("Purchasing failed with an error: \(transactionError.code), \(productIdentifier)")
|
|
172
|
+
print("Transaction error: \(transactionError.localizedDescription)")
|
|
173
|
+
resolve(
|
|
174
|
+
transaction: transaction,
|
|
175
|
+
status: .Failed,
|
|
176
|
+
productIdentifier: productIdentifier,
|
|
177
|
+
transactionIdentifier: nil
|
|
178
|
+
)
|
|
179
|
+
return;
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
print("Purchasing failed - no error, \(productIdentifier)")
|
|
183
|
+
resolve(
|
|
184
|
+
transaction: transaction,
|
|
185
|
+
status: .Failed,
|
|
186
|
+
productIdentifier: productIdentifier,
|
|
187
|
+
transactionIdentifier: nil
|
|
188
|
+
)
|
|
189
|
+
return
|
|
190
|
+
case .restored:
|
|
191
|
+
guard let productIdentifier = transaction.original?.payment.productIdentifier else {
|
|
192
|
+
print("Restoring failed - no product identifier")
|
|
193
|
+
resolve(
|
|
194
|
+
transaction: transaction,
|
|
195
|
+
status: .Failed,
|
|
196
|
+
productIdentifier: nil,
|
|
197
|
+
transactionIdentifier: nil
|
|
198
|
+
)
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
print("Product restored, \(productIdentifier), \(String(describing: transaction.transactionIdentifier))")
|
|
202
|
+
resolve(
|
|
203
|
+
transaction: transaction,
|
|
204
|
+
status: .Restored,
|
|
205
|
+
productIdentifier: productIdentifier,
|
|
206
|
+
transactionIdentifier: transaction.transactionIdentifier
|
|
207
|
+
)
|
|
208
|
+
return
|
|
209
|
+
case .purchasing:
|
|
210
|
+
break
|
|
211
|
+
case .deferred:
|
|
212
|
+
break
|
|
213
|
+
@unknown default:
|
|
214
|
+
print("Unexpected transaction state: \(transaction.transactionState), \(transaction.payment.productIdentifier)")
|
|
215
|
+
break
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private func resolve(transaction: SKPaymentTransaction, status: AppleInAppPurchaseStatus, productIdentifier: String?, transactionIdentifier: String?) {
|
|
221
|
+
if let callId = delayedCallId, let call = bridge?.savedCall(withID: callId) {
|
|
222
|
+
call.resolve([
|
|
223
|
+
"status": status.rawValue,
|
|
224
|
+
"transactionIdentifier": transactionIdentifier,
|
|
225
|
+
"productIdentifier": productIdentifier
|
|
226
|
+
])
|
|
227
|
+
bridge?.releaseCall(withID: callId)
|
|
228
|
+
}
|
|
229
|
+
SKPaymentQueue.default().finishTransaction(transaction)
|
|
230
|
+
delayedCallId = nil;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
extension SKProduct {
|
|
235
|
+
private static let formatter: NumberFormatter = {
|
|
236
|
+
let formatter = NumberFormatter()
|
|
237
|
+
formatter.numberStyle = .currency
|
|
238
|
+
return formatter
|
|
239
|
+
}()
|
|
240
|
+
|
|
241
|
+
var isFree: Bool {
|
|
242
|
+
price == 0.00
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
var localizedPrice: String? {
|
|
246
|
+
guard !isFree else {
|
|
247
|
+
return nil
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
let formatter = SKProduct.formatter
|
|
251
|
+
formatter.locale = priceLocale
|
|
252
|
+
|
|
253
|
+
return formatter.string(from: price)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dicty/payment",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Dicty Stripe plugin",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/plugin.cjs.js",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"types": "dist/esm/index.d.ts",
|
|
9
|
+
"unpkg": "dist/plugin.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"android/src/main/",
|
|
12
|
+
"android/build.gradle",
|
|
13
|
+
"dist/",
|
|
14
|
+
"ios/Sources/PaymentPlugin/",
|
|
15
|
+
"DictyPayment.podspec"
|
|
16
|
+
],
|
|
17
|
+
"author": "Dicty",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/wtorsi/stripe.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/wtorsi/stripe/issues"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"type": "./dist/esm/index.d.ts",
|
|
29
|
+
"import": "./dist/esm/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./react": {
|
|
32
|
+
"type": "./dist/esm/provider/react/PaymentPluginProvider.d.ts",
|
|
33
|
+
"import": "./dist/esm/provider/react/PaymentPluginProvider.js"
|
|
34
|
+
},
|
|
35
|
+
"./*": "./*"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"capacitor",
|
|
39
|
+
"plugin",
|
|
40
|
+
"native"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
44
|
+
"verify:ios": "xcodebuild -scheme DictyPayment -destination generic/platform=iOS",
|
|
45
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
46
|
+
"verify:web": "npm run build",
|
|
47
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
48
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
49
|
+
"eslint": "eslint . --ext ts",
|
|
50
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
51
|
+
"swiftlint": "node-swiftlint",
|
|
52
|
+
"docgen": "docgen --api PaymentPlugin --output-readme README.md --output-json dist/docs.json",
|
|
53
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
54
|
+
"clean": "rimraf ./dist",
|
|
55
|
+
"watch": "tsc --watch",
|
|
56
|
+
"prepublishOnly": "npm run build"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@capacitor/android": "^7.4.4",
|
|
60
|
+
"@capacitor/core": "^7.4.4",
|
|
61
|
+
"@capacitor/docgen": "^0.3.0",
|
|
62
|
+
"@capacitor/ios": "^7.4.4",
|
|
63
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
64
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
65
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
66
|
+
"@types/react": "^19.2.2",
|
|
67
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
68
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
69
|
+
"eslint": "^9.39.0",
|
|
70
|
+
"prettier": "^3.6.2",
|
|
71
|
+
"prettier-plugin-java": "^2.7.7",
|
|
72
|
+
"rimraf": "^6.1.0",
|
|
73
|
+
"rollup": "^4.52.5",
|
|
74
|
+
"swiftlint": "^2.0.0",
|
|
75
|
+
"typescript": "^5.9.3"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@capacitor/core": "^5.0.4",
|
|
79
|
+
"react": "^19.2.0"
|
|
80
|
+
},
|
|
81
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
82
|
+
"eslintConfig": {
|
|
83
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
84
|
+
},
|
|
85
|
+
"capacitor": {
|
|
86
|
+
"ios": {
|
|
87
|
+
"src": "ios"
|
|
88
|
+
},
|
|
89
|
+
"android": {
|
|
90
|
+
"src": "android"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|