Bladeren bron

【会员系统】Apple pay相关代码导入

lizhe 1 week geleden
bovenliggende
commit
af569d4e76

+ 2 - 0
PDF Office/PDF Master Pro/PDF-Reader-Pro-Edition.entitlements

@@ -2,6 +2,8 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
+	<key>com.apple.developer.in-app-payments</key>
+	<array/>
 	<key>com.apple.security.app-sandbox</key>
 	<true/>
 	<key>com.apple.security.files.user-selected.read-write</key>

+ 67 - 0
PDF Office/PDF Master/Class/Purchase/DMG/ApplePay/KMApplePay.swift

@@ -0,0 +1,67 @@
+//
+//  KMApplePay.swift
+//  PDF Reader Pro
+//
+//  Created by lizhe on 2024/11/13.
+//
+
+import Cocoa
+import PassKit
+
+class KMApplePay: NSObject,PKPaymentAuthorizationViewControllerDelegate {
+    
+    func startApplePayProcess(viewController: NSViewController) {
+        // 1. 检查设备是否支持 Apple Pay
+        guard PKPaymentAuthorizationViewController.canMakePayments() else {
+            print("Apple Pay is not available on this device.")
+            return
+        }
+        
+        // 2. 设置支付请求
+        let paymentRequest = PKPaymentRequest()
+        paymentRequest.merchantIdentifier = "your.merchant.id" // 替换为你的商户 ID
+        paymentRequest.supportedNetworks = [.visa, .masterCard, .amex]
+        paymentRequest.merchantCapabilities = .capability3DS
+        paymentRequest.countryCode = "US" // 设置你的国家代码
+        paymentRequest.currencyCode = "USD" // 设置货币代码
+        
+        // 设置支付摘要项
+        paymentRequest.paymentSummaryItems = [
+            PKPaymentSummaryItem(label: "Product Name", amount: NSDecimalNumber(value: 10.00)),
+            PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(value: 10.00))
+        ]
+        
+        // 3. 初始化并显示支付授权界面
+        if let paymentVC = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest) {
+            paymentVC.delegate = self
+            NSWindow.currentWindow().beginSheet(NSWindow(contentViewController: paymentVC)) { response in
+                
+            }
+//            viewController.presentAsSheet(paymentVC) // 在 macOS 上以模态窗口方式展示
+        } else {
+            print("Unable to present Apple Pay authorization view controller.")
+        }
+    }
+    
+    // MARK: - PKPaymentAuthorizationViewControllerDelegate Methods
+    
+    // 用户授权后调用
+    func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
+                                            didAuthorizePayment payment: PKPayment,
+                                            handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
+        // 在此处处理支付(例如,向你的服务器发送支付数据)
+        
+        // 模拟成功的支付授权
+        let status = PKPaymentAuthorizationStatus.success
+        completion(PKPaymentAuthorizationResult(status: status, errors: nil))
+    }
+    
+    // 用户取消支付时调用
+    func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
+        controller.dismiss(nil) // 关闭支付界面
+    }
+    
+    func paymentAuthorizationViewControllerWillAuthorizePayment(_ controller: PKPaymentAuthorizationViewController) {
+        
+    }
+}

+ 16 - 0
PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

@@ -1646,6 +1646,9 @@
 		AD2D74B929F0D3A100EDC5E4 /* KMCancellationSuccessView.xib in Resources */ = {isa = PBXBuildFile; fileRef = AD2D74B829F0D3A100EDC5E4 /* KMCancellationSuccessView.xib */; };
 		AD2D74BA29F0D3A100EDC5E4 /* KMCancellationSuccessView.xib in Resources */ = {isa = PBXBuildFile; fileRef = AD2D74B829F0D3A100EDC5E4 /* KMCancellationSuccessView.xib */; };
 		AD2D74BB29F0D3A100EDC5E4 /* KMCancellationSuccessView.xib in Resources */ = {isa = PBXBuildFile; fileRef = AD2D74B829F0D3A100EDC5E4 /* KMCancellationSuccessView.xib */; };
+		AD3718AB2CE43498007095A8 /* KMApplePay.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3718AA2CE43498007095A8 /* KMApplePay.swift */; };
+		AD3718AC2CE43498007095A8 /* KMApplePay.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3718AA2CE43498007095A8 /* KMApplePay.swift */; };
+		AD3718AD2CE43498007095A8 /* KMApplePay.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3718AA2CE43498007095A8 /* KMApplePay.swift */; };
 		AD3A3587294C11ED00D72802 /* KMPrintPreviewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3A3586294C11ED00D72802 /* KMPrintPreviewPresenter.swift */; };
 		AD3A3588294C11ED00D72802 /* KMPrintPreviewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3A3586294C11ED00D72802 /* KMPrintPreviewPresenter.swift */; };
 		AD3A3589294C11ED00D72802 /* KMPrintPreviewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD3A3586294C11ED00D72802 /* KMPrintPreviewPresenter.swift */; };
@@ -6286,6 +6289,7 @@
 		AD2D74AC29F0CEB300EDC5E4 /* KMCancellationWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMCancellationWindowController.xib; sourceTree = "<group>"; };
 		AD2D74B429F0D39500EDC5E4 /* KMCancellationSuccessView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCancellationSuccessView.swift; sourceTree = "<group>"; };
 		AD2D74B829F0D3A100EDC5E4 /* KMCancellationSuccessView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMCancellationSuccessView.xib; sourceTree = "<group>"; };
+		AD3718AA2CE43498007095A8 /* KMApplePay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMApplePay.swift; sourceTree = "<group>"; };
 		AD3A3586294C11ED00D72802 /* KMPrintPreviewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPrintPreviewPresenter.swift; sourceTree = "<group>"; };
 		AD3AAD112B0B5B2700DE5FE7 /* KMCompareContentWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMCompareContentWindowController.swift; sourceTree = "<group>"; };
 		AD3AAD122B0B5B2700DE5FE7 /* KMCompareContentWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMCompareContentWindowController.xib; sourceTree = "<group>"; };
@@ -9675,6 +9679,14 @@
 			path = View;
 			sourceTree = "<group>";
 		};
+		AD3718A52CE43444007095A8 /* ApplePay */ = {
+			isa = PBXGroup;
+			children = (
+				AD3718AA2CE43498007095A8 /* KMApplePay.swift */,
+			);
+			path = ApplePay;
+			sourceTree = "<group>";
+		};
 		AD3A358B294C120B00D72802 /* Presenter */ = {
 			isa = PBXGroup;
 			children = (
@@ -13600,6 +13612,7 @@
 		BBA922102B4E77CA0061057A /* DMG */ = {
 			isa = PBXGroup;
 			children = (
+				AD3718A52CE43444007095A8 /* ApplePay */,
 				65EF3A7B2C81C1F500CCFC8F /* Tools */,
 				BBA922122B4E783F0061057A /* KMPurchaseCompareDMGWindowController.h */,
 				BBA922142B4E783F0061057A /* KMPurchaseCompareDMGWindowController.m */,
@@ -17031,6 +17044,7 @@
 				65D88ED22C85826A00DD06E0 /* KMRSAUtils.swift in Sources */,
 				BB67EE202B54FFEF00573BF0 /* ASIDataDecompressor.m in Sources */,
 				65341C7C2C646C6400FE30F9 /* KMSearchReplaceHanddler.swift in Sources */,
+				AD3718AB2CE43498007095A8 /* KMApplePay.swift in Sources */,
 				BB897229294B08720045787C /* KMWatermarkAdjectiveTopBarItemModel.swift in Sources */,
 				BB00301D298CB799002DD1A0 /* KMPreferenceManager.swift in Sources */,
 				BBF729A32B19624500576AC5 /* KMAddBackgroundOperationQueue.swift in Sources */,
@@ -18334,6 +18348,7 @@
 				BB853C832AF8BAF0009C20C1 /* KMSetPasswordObject.swift in Sources */,
 				BBB3FF9D2B56852700145C4A /* NSDocument+KMExtensions.swift in Sources */,
 				BBEC00B0295C2AF300A26C98 /* KMBatesPreviewController.swift in Sources */,
+				AD3718AC2CE43498007095A8 /* KMApplePay.swift in Sources */,
 				BB0A551E2A30793F00B6E84B /* KMDesignTextField.swift in Sources */,
 				BB1969E12B2856A900922736 /* KMSnapshotPDFView.swift in Sources */,
 				BBF170592AE296B90013CE02 /* KMView.swift in Sources */,
@@ -19130,6 +19145,7 @@
 				BBD426812B4FCF1500AC8660 /* KMTextFieldCell.swift in Sources */,
 				BBB789C82BE8BF2400F7E09C /* AIRedoConfirmView.swift in Sources */,
 				BB897260294C5DDA0045787C /* KMWatermarkPropertyInfoController.swift in Sources */,
+				AD3718AD2CE43498007095A8 /* KMApplePay.swift in Sources */,
 				BB0A55162A3052F800B6E84B /* KMCustomTextField.swift in Sources */,
 				9F0201882A1DA28B00C9B673 /* KMAILanguagePopVC.swift in Sources */,
 				BB8F4562295AA39F0037EA22 /* KMHeaderFooterModel.swift in Sources */,