Commit ffbc6b92c807a5b281bad648885fc9c1e23a9dea

Authored by 权海
1 parent 89245012

feat(ui):调整支付返回值,增加errorCode

@@ -79,20 +79,6 @@ class FlutterError ( @@ -79,20 +79,6 @@ class FlutterError (
79 val details: Any? = null 79 val details: Any? = null
80 ) : Throwable() 80 ) : Throwable()
81 81
82 -enum class AppleProductPaymentErrorMsg(val raw: Int) {  
83 - MISSING_UUID(0),  
84 - PRODUCT_NOT_FOUND(1),  
85 - USER_CANCELLED(2),  
86 - FAILED_VERIFICATION(3),  
87 - UNKNOWN(4);  
88 -  
89 - companion object {  
90 - fun ofRaw(raw: Int): AppleProductPaymentErrorMsg? {  
91 - return values().firstOrNull { it.raw == raw }  
92 - }  
93 - }  
94 -}  
95 -  
96 /** Generated class from Pigeon that represents data sent in messages. */ 82 /** Generated class from Pigeon that represents data sent in messages. */
97 data class AppleSignInModel ( 83 data class AppleSignInModel (
98 val userId: String, 84 val userId: String,
@@ -193,13 +179,18 @@ data class AppleProductPaymentResult ( @@ -193,13 +179,18 @@ data class AppleProductPaymentResult (
193 val appAccountToken: String? = null, 179 val appAccountToken: String? = null,
194 val originalTransactionId: String? = null, 180 val originalTransactionId: String? = null,
195 val transactionId: String? = null, 181 val transactionId: String? = null,
  182 + /**
  183 + * success 为空时是支付pending状态,不需要处理
  184 + * 只有 true/false时才是支付结果出来的时候
  185 + */
196 val success: Boolean? = null, 186 val success: Boolean? = null,
197 /** 187 /**
198 - * 错误描述:  
199 - * 和AppleProductPaymentErrorMsg匹配的flutter处理,  
200 - * 不匹配的则是StoreKit 直接给的错误描述,直接展示即可 188 + * 错误描述, success = false时取用:
  189 + * 优先取 errorCode: -1: UUID格式错误, -2: productID查询商品失败,-3:用户取消支付, -4:支付校验失败,-5:未知错误(Apple未知错误)
  190 + * errorCode 为空时,取用 errorMessage
201 */ 191 */
202 - val errorMessage: String? = null 192 + val errorMessage: String? = null,
  193 + val errorCode: Long? = null
203 ) 194 )
204 { 195 {
205 companion object { 196 companion object {
@@ -210,7 +201,8 @@ data class AppleProductPaymentResult ( @@ -210,7 +201,8 @@ data class AppleProductPaymentResult (
210 val transactionId = pigeonVar_list[3] as String? 201 val transactionId = pigeonVar_list[3] as String?
211 val success = pigeonVar_list[4] as Boolean? 202 val success = pigeonVar_list[4] as Boolean?
212 val errorMessage = pigeonVar_list[5] as String? 203 val errorMessage = pigeonVar_list[5] as String?
213 - return AppleProductPaymentResult(productId, appAccountToken, originalTransactionId, transactionId, success, errorMessage) 204 + val errorCode = pigeonVar_list[6] as Long?
  205 + return AppleProductPaymentResult(productId, appAccountToken, originalTransactionId, transactionId, success, errorMessage, errorCode)
214 } 206 }
215 } 207 }
216 fun toList(): List<Any?> { 208 fun toList(): List<Any?> {
@@ -221,6 +213,7 @@ data class AppleProductPaymentResult ( @@ -221,6 +213,7 @@ data class AppleProductPaymentResult (
221 transactionId, 213 transactionId,
222 success, 214 success,
223 errorMessage, 215 errorMessage,
  216 + errorCode,
224 ) 217 )
225 } 218 }
226 override fun equals(other: Any?): Boolean { 219 override fun equals(other: Any?): Boolean {
@@ -238,21 +231,16 @@ private open class PlatformApiPigeonCodec : StandardMessageCodec() { @@ -238,21 +231,16 @@ private open class PlatformApiPigeonCodec : StandardMessageCodec() {
238 override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { 231 override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
239 return when (type) { 232 return when (type) {
240 129.toByte() -> { 233 129.toByte() -> {
241 - return (readValue(buffer) as Long?)?.let {  
242 - AppleProductPaymentErrorMsg.ofRaw(it.toInt())  
243 - }  
244 - }  
245 - 130.toByte() -> {  
246 return (readValue(buffer) as? List<Any?>)?.let { 234 return (readValue(buffer) as? List<Any?>)?.let {
247 AppleSignInModel.fromList(it) 235 AppleSignInModel.fromList(it)
248 } 236 }
249 } 237 }
250 - 131.toByte() -> { 238 + 130.toByte() -> {
251 return (readValue(buffer) as? List<Any?>)?.let { 239 return (readValue(buffer) as? List<Any?>)?.let {
252 AppleProductInfo.fromList(it) 240 AppleProductInfo.fromList(it)
253 } 241 }
254 } 242 }
255 - 132.toByte() -> { 243 + 131.toByte() -> {
256 return (readValue(buffer) as? List<Any?>)?.let { 244 return (readValue(buffer) as? List<Any?>)?.let {
257 AppleProductPaymentResult.fromList(it) 245 AppleProductPaymentResult.fromList(it)
258 } 246 }
@@ -262,20 +250,16 @@ private open class PlatformApiPigeonCodec : StandardMessageCodec() { @@ -262,20 +250,16 @@ private open class PlatformApiPigeonCodec : StandardMessageCodec() {
262 } 250 }
263 override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { 251 override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
264 when (value) { 252 when (value) {
265 - is AppleProductPaymentErrorMsg -> {  
266 - stream.write(129)  
267 - writeValue(stream, value.raw)  
268 - }  
269 is AppleSignInModel -> { 253 is AppleSignInModel -> {
270 - stream.write(130) 254 + stream.write(129)
271 writeValue(stream, value.toList()) 255 writeValue(stream, value.toList())
272 } 256 }
273 is AppleProductInfo -> { 257 is AppleProductInfo -> {
274 - stream.write(131) 258 + stream.write(130)
275 writeValue(stream, value.toList()) 259 writeValue(stream, value.toList())
276 } 260 }
277 is AppleProductPaymentResult -> { 261 is AppleProductPaymentResult -> {
278 - stream.write(132) 262 + stream.write(131)
279 writeValue(stream, value.toList()) 263 writeValue(stream, value.toList())
280 } 264 }
281 else -> super.writeValue(stream, value) 265 else -> super.writeValue(stream, value)
@@ -3,15 +3,15 @@ @@ -3,15 +3,15 @@
3 archiveVersion = 1; 3 archiveVersion = 1;
4 classes = { 4 classes = {
5 }; 5 };
6 - objectVersion = 54; 6 + objectVersion = 77;
7 objects = { 7 objects = {
8 8
9 /* Begin PBXBuildFile section */ 9 /* Begin PBXBuildFile section */
10 0798E27DB95F2A823881D75A /* Pods_Runner_Watch_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A488EFC0BD642ED604C4E43 /* Pods_Runner_Watch_App.framework */; }; 10 0798E27DB95F2A823881D75A /* Pods_Runner_Watch_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A488EFC0BD642ED604C4E43 /* Pods_Runner_Watch_App.framework */; };
11 20A3C4994C9B0F60D1F3BCBE /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8DC48B3736B7FEB548D0E65 /* Pods_Runner.framework */; }; 11 20A3C4994C9B0F60D1F3BCBE /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8DC48B3736B7FEB548D0E65 /* Pods_Runner.framework */; };
12 - 66FB19002FDBC80100F515B4 /* DFWatchFigmaTokens.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66FB19032FDBC80100F515B4 /* DFWatchFigmaTokens.swift */; };  
13 - 66FB19012FDBC80100F515B4 /* DFWatchFigmaHomeViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66FB19042FDBC80100F515B4 /* DFWatchFigmaHomeViews.swift */; };  
14 - 66FB19022FDBC80100F515B4 /* DFWatchFigmaDetailViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66FB19052FDBC80100F515B4 /* DFWatchFigmaDetailViews.swift */; }; 12 + 66FB19002FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaTokens.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66FB19032FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaTokens.swift */; };
  13 + 66FB19012FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaHomeViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66FB19042FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaHomeViews.swift */; };
  14 + 66FB19022FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaDetailViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66FB19052FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaDetailViews.swift */; };
15 66FBE58C2FDA4F0F00F515B4 /* Runner Watch App.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 66FBE58B2FDA4F0F00F515B4 /* Runner Watch App.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 15 66FBE58C2FDA4F0F00F515B4 /* Runner Watch App.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 66FBE58B2FDA4F0F00F515B4 /* Runner Watch App.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
16 /* End PBXBuildFile section */ 16 /* End PBXBuildFile section */
17 17
@@ -54,9 +54,9 @@ @@ -54,9 +54,9 @@
54 27E4D5A8995AB1EC91E7330E /* Pods-Runner Watch App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner Watch App.debug.xcconfig"; path = "Target Support Files/Pods-Runner Watch App/Pods-Runner Watch App.debug.xcconfig"; sourceTree = "<group>"; }; 54 27E4D5A8995AB1EC91E7330E /* Pods-Runner Watch App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner Watch App.debug.xcconfig"; path = "Target Support Files/Pods-Runner Watch App/Pods-Runner Watch App.debug.xcconfig"; sourceTree = "<group>"; };
55 4A9B7C102FDB0A1200F515B4 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; }; 55 4A9B7C102FDB0A1200F515B4 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
56 4A9B7C112FDB0A1200F515B4 /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; }; 56 4A9B7C112FDB0A1200F515B4 /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
57 - 66FB19032FDBC80100F515B4 /* DFWatchFigmaTokens.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Runner Watch App/FigmaHome/DFWatchFigmaTokens.swift"; sourceTree = "<group>"; };  
58 - 66FB19042FDBC80100F515B4 /* DFWatchFigmaHomeViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Runner Watch App/FigmaHome/DFWatchFigmaHomeViews.swift"; sourceTree = "<group>"; };  
59 - 66FB19052FDBC80100F515B4 /* DFWatchFigmaDetailViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Runner Watch App/FigmaHome/DFWatchFigmaDetailViews.swift"; sourceTree = "<group>"; }; 57 + 66FB19032FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaTokens.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Runner Watch App/FigmaHome/DFWatchFigmaTokens.swift"; sourceTree = "<group>"; };
  58 + 66FB19042FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaHomeViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Runner Watch App/FigmaHome/DFWatchFigmaHomeViews.swift"; sourceTree = "<group>"; };
  59 + 66FB19052FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaDetailViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Runner Watch App/FigmaHome/DFWatchFigmaDetailViews.swift"; sourceTree = "<group>"; };
60 66FBE57E2FDA4F0E00F515B4 /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 60 66FBE57E2FDA4F0E00F515B4 /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
61 66FBE58B2FDA4F0F00F515B4 /* Runner Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Runner Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 61 66FBE58B2FDA4F0F00F515B4 /* Runner Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Runner Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
62 66FBE5A72FDA518C00F515B4 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; }; 62 66FBE5A72FDA518C00F515B4 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
@@ -97,8 +97,6 @@ @@ -97,8 +97,6 @@
97 }; 97 };
98 66FBE58F2FDA4F0F00F515B4 /* Runner Watch App */ = { 98 66FBE58F2FDA4F0F00F515B4 /* Runner Watch App */ = {
99 isa = PBXFileSystemSynchronizedRootGroup; 99 isa = PBXFileSystemSynchronizedRootGroup;
100 - exceptions = (  
101 - );  
102 path = "Runner Watch App"; 100 path = "Runner Watch App";
103 sourceTree = "<group>"; 101 sourceTree = "<group>";
104 }; 102 };
@@ -136,9 +134,9 @@ @@ -136,9 +134,9 @@
136 66FB19072FDBC80100F515B4 /* FigmaHome Preview Sources */ = { 134 66FB19072FDBC80100F515B4 /* FigmaHome Preview Sources */ = {
137 isa = PBXGroup; 135 isa = PBXGroup;
138 children = ( 136 children = (
139 - 66FB19052FDBC80100F515B4 /* DFWatchFigmaDetailViews.swift */,  
140 - 66FB19042FDBC80100F515B4 /* DFWatchFigmaHomeViews.swift */,  
141 - 66FB19032FDBC80100F515B4 /* DFWatchFigmaTokens.swift */, 137 + 66FB19052FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaDetailViews.swift */,
  138 + 66FB19042FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaHomeViews.swift */,
  139 + 66FB19032FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaTokens.swift */,
142 ); 140 );
143 name = "FigmaHome Preview Sources"; 141 name = "FigmaHome Preview Sources";
144 sourceTree = "<group>"; 142 sourceTree = "<group>";
@@ -305,10 +303,14 @@ @@ -305,10 +303,14 @@
305 inputFileListPaths = ( 303 inputFileListPaths = (
306 "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", 304 "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
307 ); 305 );
  306 + inputPaths = (
  307 + );
308 name = "[CP] Copy Pods Resources"; 308 name = "[CP] Copy Pods Resources";
309 outputFileListPaths = ( 309 outputFileListPaths = (
310 "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", 310 "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
311 ); 311 );
  312 + outputPaths = (
  313 + );
312 runOnlyForDeploymentPostprocessing = 0; 314 runOnlyForDeploymentPostprocessing = 0;
313 shellPath = /bin/sh; 315 shellPath = /bin/sh;
314 shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; 316 shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
@@ -379,10 +381,14 @@ @@ -379,10 +381,14 @@
379 inputFileListPaths = ( 381 inputFileListPaths = (
380 "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", 382 "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
381 ); 383 );
  384 + inputPaths = (
  385 + );
382 name = "[CP] Embed Pods Frameworks"; 386 name = "[CP] Embed Pods Frameworks";
383 outputFileListPaths = ( 387 outputFileListPaths = (
384 "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", 388 "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
385 ); 389 );
  390 + outputPaths = (
  391 + );
386 runOnlyForDeploymentPostprocessing = 0; 392 runOnlyForDeploymentPostprocessing = 0;
387 shellPath = /bin/sh; 393 shellPath = /bin/sh;
388 shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; 394 shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
@@ -396,10 +402,14 @@ @@ -396,10 +402,14 @@
396 inputFileListPaths = ( 402 inputFileListPaths = (
397 "${PODS_ROOT}/Target Support Files/Pods-Runner Watch App/Pods-Runner Watch App-frameworks-${CONFIGURATION}-input-files.xcfilelist", 403 "${PODS_ROOT}/Target Support Files/Pods-Runner Watch App/Pods-Runner Watch App-frameworks-${CONFIGURATION}-input-files.xcfilelist",
398 ); 404 );
  405 + inputPaths = (
  406 + );
399 name = "[CP] Embed Pods Frameworks"; 407 name = "[CP] Embed Pods Frameworks";
400 outputFileListPaths = ( 408 outputFileListPaths = (
401 "${PODS_ROOT}/Target Support Files/Pods-Runner Watch App/Pods-Runner Watch App-frameworks-${CONFIGURATION}-output-files.xcfilelist", 409 "${PODS_ROOT}/Target Support Files/Pods-Runner Watch App/Pods-Runner Watch App-frameworks-${CONFIGURATION}-output-files.xcfilelist",
402 ); 410 );
  411 + outputPaths = (
  412 + );
403 runOnlyForDeploymentPostprocessing = 0; 413 runOnlyForDeploymentPostprocessing = 0;
404 shellPath = /bin/sh; 414 shellPath = /bin/sh;
405 shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner Watch App/Pods-Runner Watch App-frameworks.sh\"\n"; 415 shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner Watch App/Pods-Runner Watch App-frameworks.sh\"\n";
@@ -441,9 +451,9 @@ @@ -441,9 +451,9 @@
441 isa = PBXSourcesBuildPhase; 451 isa = PBXSourcesBuildPhase;
442 buildActionMask = 2147483647; 452 buildActionMask = 2147483647;
443 files = ( 453 files = (
444 - 66FB19022FDBC80100F515B4 /* DFWatchFigmaDetailViews.swift in Sources */,  
445 - 66FB19012FDBC80100F515B4 /* DFWatchFigmaHomeViews.swift in Sources */,  
446 - 66FB19002FDBC80100F515B4 /* DFWatchFigmaTokens.swift in Sources */, 454 + 66FB19022FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaDetailViews.swift in Sources */,
  455 + 66FB19012FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaHomeViews.swift in Sources */,
  456 + 66FB19002FDBC80100F515B4 /* Runner Watch App/FigmaHome/DFWatchFigmaTokens.swift in Sources */,
447 ); 457 );
448 runOnlyForDeploymentPostprocessing = 0; 458 runOnlyForDeploymentPostprocessing = 0;
449 }; 459 };
@@ -112,14 +112,6 @@ func deepHashPlatformApi(value: Any?, hasher: inout Hasher) { @@ -112,14 +112,6 @@ func deepHashPlatformApi(value: Any?, hasher: inout Hasher) {
112 112
113 113
114 114
115 -enum AppleProductPaymentErrorMsg: Int {  
116 - case missingUUID = 0  
117 - case productNotFound = 1  
118 - case userCancelled = 2  
119 - case failedVerification = 3  
120 - case unknown = 4  
121 -}  
122 -  
123 /// Generated class from Pigeon that represents data sent in messages. 115 /// Generated class from Pigeon that represents data sent in messages.
124 struct AppleSignInModel: Hashable { 116 struct AppleSignInModel: Hashable {
125 var userId: String 117 var userId: String
@@ -224,11 +216,14 @@ struct AppleProductPaymentResult: Hashable { @@ -224,11 +216,14 @@ struct AppleProductPaymentResult: Hashable {
224 var appAccountToken: String? = nil 216 var appAccountToken: String? = nil
225 var originalTransactionId: String? = nil 217 var originalTransactionId: String? = nil
226 var transactionId: String? = nil 218 var transactionId: String? = nil
  219 + /// success 为空时是支付pending状态,不需要处理
  220 + /// 只有 true/false时才是支付结果出来的时候
227 var success: Bool? = nil 221 var success: Bool? = nil
228 - /// 错误描述:  
229 - /// 和AppleProductPaymentErrorMsg匹配的flutter处理,  
230 - /// 不匹配的则是StoreKit 直接给的错误描述,直接展示即可 222 + /// 错误描述, success = false时取用:
  223 + /// 优先取 errorCode: -1: UUID格式错误, -2: productID查询商品失败,-3:用户取消支付, -4:支付校验失败,-5:未知错误(Apple未知错误)
  224 + /// errorCode 为空时,取用 errorMessage
231 var errorMessage: String? = nil 225 var errorMessage: String? = nil
  226 + var errorCode: Int64? = nil
232 227
233 228
234 // swift-format-ignore: AlwaysUseLowerCamelCase 229 // swift-format-ignore: AlwaysUseLowerCamelCase
@@ -239,6 +234,7 @@ struct AppleProductPaymentResult: Hashable { @@ -239,6 +234,7 @@ struct AppleProductPaymentResult: Hashable {
239 let transactionId: String? = nilOrValue(pigeonVar_list[3]) 234 let transactionId: String? = nilOrValue(pigeonVar_list[3])
240 let success: Bool? = nilOrValue(pigeonVar_list[4]) 235 let success: Bool? = nilOrValue(pigeonVar_list[4])
241 let errorMessage: String? = nilOrValue(pigeonVar_list[5]) 236 let errorMessage: String? = nilOrValue(pigeonVar_list[5])
  237 + let errorCode: Int64? = nilOrValue(pigeonVar_list[6])
242 238
243 return AppleProductPaymentResult( 239 return AppleProductPaymentResult(
244 productId: productId, 240 productId: productId,
@@ -246,7 +242,8 @@ struct AppleProductPaymentResult: Hashable { @@ -246,7 +242,8 @@ struct AppleProductPaymentResult: Hashable {
246 originalTransactionId: originalTransactionId, 242 originalTransactionId: originalTransactionId,
247 transactionId: transactionId, 243 transactionId: transactionId,
248 success: success, 244 success: success,
249 - errorMessage: errorMessage 245 + errorMessage: errorMessage,
  246 + errorCode: errorCode
250 ) 247 )
251 } 248 }
252 func toList() -> [Any?] { 249 func toList() -> [Any?] {
@@ -257,6 +254,7 @@ struct AppleProductPaymentResult: Hashable { @@ -257,6 +254,7 @@ struct AppleProductPaymentResult: Hashable {
257 transactionId, 254 transactionId,
258 success, 255 success,
259 errorMessage, 256 errorMessage,
  257 + errorCode,
260 ] 258 ]
261 } 259 }
262 static func == (lhs: AppleProductPaymentResult, rhs: AppleProductPaymentResult) -> Bool { 260 static func == (lhs: AppleProductPaymentResult, rhs: AppleProductPaymentResult) -> Bool {
@@ -270,16 +268,10 @@ private class PlatformApiPigeonCodecReader: FlutterStandardReader { @@ -270,16 +268,10 @@ private class PlatformApiPigeonCodecReader: FlutterStandardReader {
270 override func readValue(ofType type: UInt8) -> Any? { 268 override func readValue(ofType type: UInt8) -> Any? {
271 switch type { 269 switch type {
272 case 129: 270 case 129:
273 - let enumResultAsInt: Int? = nilOrValue(self.readValue() as! Int?)  
274 - if let enumResultAsInt = enumResultAsInt {  
275 - return AppleProductPaymentErrorMsg(rawValue: enumResultAsInt)  
276 - }  
277 - return nil  
278 - case 130:  
279 return AppleSignInModel.fromList(self.readValue() as! [Any?]) 271 return AppleSignInModel.fromList(self.readValue() as! [Any?])
280 - case 131: 272 + case 130:
281 return AppleProductInfo.fromList(self.readValue() as! [Any?]) 273 return AppleProductInfo.fromList(self.readValue() as! [Any?])
282 - case 132: 274 + case 131:
283 return AppleProductPaymentResult.fromList(self.readValue() as! [Any?]) 275 return AppleProductPaymentResult.fromList(self.readValue() as! [Any?])
284 default: 276 default:
285 return super.readValue(ofType: type) 277 return super.readValue(ofType: type)
@@ -289,17 +281,14 @@ private class PlatformApiPigeonCodecReader: FlutterStandardReader { @@ -289,17 +281,14 @@ private class PlatformApiPigeonCodecReader: FlutterStandardReader {
289 281
290 private class PlatformApiPigeonCodecWriter: FlutterStandardWriter { 282 private class PlatformApiPigeonCodecWriter: FlutterStandardWriter {
291 override func writeValue(_ value: Any) { 283 override func writeValue(_ value: Any) {
292 - if let value = value as? AppleProductPaymentErrorMsg { 284 + if let value = value as? AppleSignInModel {
293 super.writeByte(129) 285 super.writeByte(129)
294 - super.writeValue(value.rawValue)  
295 - } else if let value = value as? AppleSignInModel {  
296 - super.writeByte(130)  
297 super.writeValue(value.toList()) 286 super.writeValue(value.toList())
298 } else if let value = value as? AppleProductInfo { 287 } else if let value = value as? AppleProductInfo {
299 - super.writeByte(131) 288 + super.writeByte(130)
300 super.writeValue(value.toList()) 289 super.writeValue(value.toList())
301 } else if let value = value as? AppleProductPaymentResult { 290 } else if let value = value as? AppleProductPaymentResult {
302 - super.writeByte(132) 291 + super.writeByte(131)
303 super.writeValue(value.toList()) 292 super.writeValue(value.toList())
304 } else { 293 } else {
305 super.writeValue(value) 294 super.writeValue(value)
@@ -72,7 +72,7 @@ final class PlatformHostApiImpl: PlatformHostApi { @@ -72,7 +72,7 @@ final class PlatformHostApiImpl: PlatformHostApi {
72 displayPrice = offer.displayPrice 72 displayPrice = offer.displayPrice
73 } 73 }
74 74
75 - let unitPrice = price/Decimal(baseUnit) 75 + let unitPrice = originPrice/Decimal(baseUnit)
76 let currencyCode = product.priceFormatStyle.currencyCode 76 let currencyCode = product.priceFormatStyle.currencyCode
77 77
78 let productInfo = AppleProductInfo( 78 let productInfo = AppleProductInfo(
@@ -9,6 +9,14 @@ import Foundation @@ -9,6 +9,14 @@ import Foundation
9 import StoreKit 9 import StoreKit
10 10
11 11
  12 +enum AppleProductPaymentErrorMsg: Int64 {
  13 + case missingUUID = -1
  14 + case productNotFound = -2
  15 + case userCancelled = -3
  16 + case failedVerification = -4
  17 + case unknown = -5
  18 +}
  19 +
12 enum StoreKitError: Error, LocalizedError { 20 enum StoreKitError: Error, LocalizedError {
13 case productNotFound 21 case productNotFound
14 case failedVerification 22 case failedVerification
@@ -46,7 +54,7 @@ class ApplePayment { @@ -46,7 +54,7 @@ class ApplePayment {
46 return paymentResult( 54 return paymentResult(
47 productId: productId, 55 productId: productId,
48 success: false, 56 success: false,
49 - errorMessage: String(describing: AppleProductPaymentErrorMsg.missingUUID) 57 + errorCode: AppleProductPaymentErrorMsg.missingUUID.rawValue
50 ) 58 )
51 } 59 }
52 let appleProduct = try await requestProducts(productId) 60 let appleProduct = try await requestProducts(productId)
@@ -78,26 +86,24 @@ class ApplePayment { @@ -78,26 +86,24 @@ class ApplePayment {
78 originalTransactionId: String(transaction.originalID), 86 originalTransactionId: String(transaction.originalID),
79 transactionId: String(transaction.id), 87 transactionId: String(transaction.id),
80 success: false, 88 success: false,
81 - errorMessage: String(describing: AppleProductPaymentErrorMsg.unknown) 89 + errorCode: AppleProductPaymentErrorMsg.failedVerification.rawValue
82 ) 90 )
83 } 91 }
84 case .userCancelled: 92 case .userCancelled:
85 return paymentResult( 93 return paymentResult(
86 productId: productId, 94 productId: productId,
87 success: false, 95 success: false,
88 - errorMessage: String(describing: AppleProductPaymentErrorMsg.userCancelled) 96 + errorCode: AppleProductPaymentErrorMsg.userCancelled.rawValue
89 ) 97 )
90 case .pending: 98 case .pending:
91 return paymentResult( 99 return paymentResult(
92 - productId: productId,  
93 - success: false,  
94 - errorMessage: String(describing: AppleProductPaymentErrorMsg.unknown) 100 + productId: productId
95 ) 101 )
96 @unknown default: 102 @unknown default:
97 return paymentResult( 103 return paymentResult(
98 productId: productId, 104 productId: productId,
99 success: false, 105 success: false,
100 - errorMessage: String(describing: AppleProductPaymentErrorMsg.unknown) 106 + errorCode: AppleProductPaymentErrorMsg.unknown.rawValue
101 ) 107 )
102 } 108 }
103 } catch { 109 } catch {
@@ -272,8 +278,9 @@ class ApplePayment { @@ -272,8 +278,9 @@ class ApplePayment {
272 appAccountToken: String? = nil, 278 appAccountToken: String? = nil,
273 originalTransactionId: String? = nil, 279 originalTransactionId: String? = nil,
274 transactionId: String? = nil, 280 transactionId: String? = nil,
275 - success: Bool?,  
276 - errorMessage: String? = nil 281 + success: Bool? = nil,
  282 + errorMessage: String? = nil,
  283 + errorCode: Int64? = nil,
277 ) -> AppleProductPaymentResult { 284 ) -> AppleProductPaymentResult {
278 AppleProductPaymentResult( 285 AppleProductPaymentResult(
279 productId: productId, 286 productId: productId,
@@ -281,7 +288,8 @@ class ApplePayment { @@ -281,7 +288,8 @@ class ApplePayment {
281 originalTransactionId: originalTransactionId, 288 originalTransactionId: originalTransactionId,
282 transactionId: transactionId, 289 transactionId: transactionId,
283 success: success, 290 success: success,
284 - errorMessage: errorMessage 291 + errorMessage: errorMessage,
  292 + errorCode: errorCode
285 ) 293 )
286 } 294 }
287 295
@@ -30,14 +30,6 @@ bool _deepEquals(Object? a, Object? b) { @@ -30,14 +30,6 @@ bool _deepEquals(Object? a, Object? b) {
30 } 30 }
31 31
32 32
33 -enum AppleProductPaymentErrorMsg {  
34 - missingUUID,  
35 - productNotFound,  
36 - userCancelled,  
37 - failedVerification,  
38 - unknown,  
39 -}  
40 -  
41 class AppleSignInModel { 33 class AppleSignInModel {
42 AppleSignInModel({ 34 AppleSignInModel({
43 required this.userId, 35 required this.userId,
@@ -186,6 +178,7 @@ class AppleProductPaymentResult { @@ -186,6 +178,7 @@ class AppleProductPaymentResult {
186 this.transactionId, 178 this.transactionId,
187 this.success, 179 this.success,
188 this.errorMessage, 180 this.errorMessage,
  181 + this.errorCode,
189 }); 182 });
190 183
191 String productId; 184 String productId;
@@ -196,13 +189,17 @@ class AppleProductPaymentResult { @@ -196,13 +189,17 @@ class AppleProductPaymentResult {
196 189
197 String? transactionId; 190 String? transactionId;
198 191
  192 + /// success 为空时是支付pending状态,不需要处理
  193 + /// 只有 true/false时才是支付结果出来的时候
199 bool? success; 194 bool? success;
200 195
201 - /// 错误描述:  
202 - /// 和AppleProductPaymentErrorMsg匹配的flutter处理,  
203 - /// 不匹配的则是StoreKit 直接给的错误描述,直接展示即可 196 + /// 错误描述, success = false时取用:
  197 + /// 优先取 errorCode: -1: UUID格式错误, -2: productID查询商品失败,-3:用户取消支付, -4:支付校验失败,-5:未知错误(Apple未知错误)
  198 + /// errorCode 为空时,取用 errorMessage
204 String? errorMessage; 199 String? errorMessage;
205 200
  201 + int? errorCode;
  202 +
206 List<Object?> _toList() { 203 List<Object?> _toList() {
207 return <Object?>[ 204 return <Object?>[
208 productId, 205 productId,
@@ -211,6 +208,7 @@ class AppleProductPaymentResult { @@ -211,6 +208,7 @@ class AppleProductPaymentResult {
211 transactionId, 208 transactionId,
212 success, 209 success,
213 errorMessage, 210 errorMessage,
  211 + errorCode,
214 ]; 212 ];
215 } 213 }
216 214
@@ -226,6 +224,7 @@ class AppleProductPaymentResult { @@ -226,6 +224,7 @@ class AppleProductPaymentResult {
226 transactionId: result[3] as String?, 224 transactionId: result[3] as String?,
227 success: result[4] as bool?, 225 success: result[4] as bool?,
228 errorMessage: result[5] as String?, 226 errorMessage: result[5] as String?,
  227 + errorCode: result[6] as int?,
229 ); 228 );
230 } 229 }
231 230
@@ -255,17 +254,14 @@ class _PigeonCodec extends StandardMessageCodec { @@ -255,17 +254,14 @@ class _PigeonCodec extends StandardMessageCodec {
255 if (value is int) { 254 if (value is int) {
256 buffer.putUint8(4); 255 buffer.putUint8(4);
257 buffer.putInt64(value); 256 buffer.putInt64(value);
258 - } else if (value is AppleProductPaymentErrorMsg) {  
259 - buffer.putUint8(129);  
260 - writeValue(buffer, value.index);  
261 } else if (value is AppleSignInModel) { 257 } else if (value is AppleSignInModel) {
262 - buffer.putUint8(130); 258 + buffer.putUint8(129);
263 writeValue(buffer, value.encode()); 259 writeValue(buffer, value.encode());
264 } else if (value is AppleProductInfo) { 260 } else if (value is AppleProductInfo) {
265 - buffer.putUint8(131); 261 + buffer.putUint8(130);
266 writeValue(buffer, value.encode()); 262 writeValue(buffer, value.encode());
267 } else if (value is AppleProductPaymentResult) { 263 } else if (value is AppleProductPaymentResult) {
268 - buffer.putUint8(132); 264 + buffer.putUint8(131);
269 writeValue(buffer, value.encode()); 265 writeValue(buffer, value.encode());
270 } else { 266 } else {
271 super.writeValue(buffer, value); 267 super.writeValue(buffer, value);
@@ -276,13 +272,10 @@ class _PigeonCodec extends StandardMessageCodec { @@ -276,13 +272,10 @@ class _PigeonCodec extends StandardMessageCodec {
276 Object? readValueOfType(int type, ReadBuffer buffer) { 272 Object? readValueOfType(int type, ReadBuffer buffer) {
277 switch (type) { 273 switch (type) {
278 case 129: 274 case 129:
279 - final int? value = readValue(buffer) as int?;  
280 - return value == null ? null : AppleProductPaymentErrorMsg.values[value];  
281 - case 130:  
282 return AppleSignInModel.decode(readValue(buffer)!); 275 return AppleSignInModel.decode(readValue(buffer)!);
283 - case 131: 276 + case 130:
284 return AppleProductInfo.decode(readValue(buffer)!); 277 return AppleProductInfo.decode(readValue(buffer)!);
285 - case 132: 278 + case 131:
286 return AppleProductPaymentResult.decode(readValue(buffer)!); 279 return AppleProductPaymentResult.decode(readValue(buffer)!);
287 default: 280 default:
288 return super.readValueOfType(type, buffer); 281 return super.readValueOfType(type, buffer);
@@ -50,25 +50,20 @@ class AppleProductInfo { @@ -50,25 +50,20 @@ class AppleProductInfo {
50 }); 50 });
51 } 51 }
52 52
53 -enum AppleProductPaymentErrorMsg {  
54 - missingUUID,  
55 - productNotFound,  
56 - userCancelled,  
57 - failedVerification,  
58 - unknown,  
59 -}  
60 -  
61 class AppleProductPaymentResult { 53 class AppleProductPaymentResult {
62 final String productId; 54 final String productId;
63 final String? appAccountToken; 55 final String? appAccountToken;
64 final String? originalTransactionId; 56 final String? originalTransactionId;
65 final String? transactionId; 57 final String? transactionId;
  58 + /// success 为空时是支付pending状态,不需要处理
  59 + /// 只有 true/false时才是支付结果出来的时候
66 final bool? success; 60 final bool? success;
67 61
68 - /// 错误描述:  
69 - /// 和AppleProductPaymentErrorMsg匹配的flutter处理,  
70 - /// 不匹配的则是StoreKit 直接给的错误描述,直接展示即可 62 + /// 错误描述, success = false时取用:
  63 + /// 优先取 errorCode: -1: UUID格式错误, -2: productID查询商品失败,-3:用户取消支付, -4:支付校验失败,-5:未知错误(Apple未知错误)
  64 + /// errorCode 为空时,取用 errorMessage
71 final String? errorMessage; 65 final String? errorMessage;
  66 + final int? errorCode;
72 67
73 AppleProductPaymentResult({ 68 AppleProductPaymentResult({
74 required this.productId, 69 required this.productId,
@@ -77,6 +72,7 @@ class AppleProductPaymentResult { @@ -77,6 +72,7 @@ class AppleProductPaymentResult {
77 this.transactionId, 72 this.transactionId,
78 this.success, 73 this.success,
79 this.errorMessage, 74 this.errorMessage,
  75 + this.errorCode,
80 }); 76 });
81 } 77 }
82 78