commit d83d618829e04dca59a258dae7b0fddbd6ac7787
parent 5f4c3421318ae6537a0023282d9e73e14dd716a7
Author: William Casarin <jb55@jb55.com>
Date: Mon, 11 Mar 2024 09:58:50 +0000
Merge branch 'v1.7-madeira-release'
Diffstat:
3 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj
@@ -3856,7 +3856,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
- CURRENT_PROJECT_VERSION = 12;
+ CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
@@ -3877,7 +3877,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MACOSX_DEPLOYMENT_TARGET = 12.3;
- MARKETING_VERSION = 1.7.1;
+ MARKETING_VERSION = 1.7.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
@@ -3923,7 +3923,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
- CURRENT_PROJECT_VERSION = 12;
+ CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -3939,7 +3939,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MACOSX_DEPLOYMENT_TARGET = 12.3;
- MARKETING_VERSION = 1.7.1;
+ MARKETING_VERSION = 1.7.2;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
diff --git a/damus/Models/Purple/DamusPurple.swift b/damus/Models/Purple/DamusPurple.swift
@@ -120,8 +120,10 @@ class DamusPurple: StoreObserverDelegate {
// Record the purchase with the storekit manager, to make sure we have the update on the UIs as soon as possible.
// During testing I found that the purchase initiated via `purchase` was not emitted via the listener `StoreKit.Transaction.updates` until the app was restarted.
self.storekit_manager.record_purchased_product(StoreKitManager.PurchasedProduct(tx: tx, product: product))
- // Send the receipt to the server
- try await self.send_receipt()
+ await tx.finish()
+ // Send the transaction id to the server
+ try await self.send_transaction_id(transaction_id: tx.originalID)
+
default:
// Any time we get a non-verified result, it means that the purchase was not successful, and thus we should throw an error.
throw PurpleError.iap_purchase_error(result: result)
@@ -172,11 +174,11 @@ class DamusPurple: StoreObserverDelegate {
let account_uuid = try await self.get_maybe_cached_uuid_for_account()
let json_text: [String: String] = ["receipt": receipt_base64_string, "account_uuid": account_uuid.uuidString]
let json_data = try JSONSerialization.data(withJSONObject: json_text)
-
+
let url = environment.api_base_url().appendingPathComponent("accounts/\(keypair.pubkey.hex())/apple-iap/app-store-receipt")
-
- Log.info("Sending in-app purchase receipt to Damus Purple server", for: .damus_purple)
-
+
+ Log.info("Sending in-app purchase receipt to Damus Purple server: %s", for: .damus_purple, receipt_base64_string)
+
let (data, response) = try await make_nip98_authenticated_request(
method: .post,
url: url,
@@ -196,7 +198,33 @@ class DamusPurple: StoreObserverDelegate {
}
}
}
-
+
+ func send_transaction_id(transaction_id: UInt64) async throws {
+ let account_uuid = try await self.get_maybe_cached_uuid_for_account()
+ let json_text: [String: Any] = ["transaction_id": transaction_id, "account_uuid": account_uuid.uuidString]
+ let json_data = try JSONSerialization.data(withJSONObject: json_text)
+
+ let url = environment.api_base_url().appendingPathComponent("accounts/\(keypair.pubkey.hex())/apple-iap/transaction-id")
+
+ let (data, response) = try await make_nip98_authenticated_request(
+ method: .post,
+ url: url,
+ payload: json_data,
+ payload_type: .json,
+ auth_keypair: self.keypair
+ )
+
+ if let httpResponse = response as? HTTPURLResponse {
+ switch httpResponse.statusCode {
+ case 200:
+ Log.info("Sent transaction ID to Damus Purple server and activated successfully", for: .damus_purple)
+ default:
+ Log.error("Error in sending or verifying transaction ID with Damus Purple server. HTTP status code: %d; Response: %s", for: .damus_purple, httpResponse.statusCode, String(data: data, encoding: .utf8) ?? "Unknown")
+ throw DamusPurple.PurpleError.iap_receipt_verification_error(status: httpResponse.statusCode, response: data)
+ }
+ }
+ }
+
func translate(text: String, source source_language: String, target target_language: String) async throws -> String {
var url = environment.api_base_url()
url.append(path: "/translate")
diff --git a/damus/Models/Purple/StoreObserver.swift b/damus/Models/Purple/StoreObserver.swift
@@ -21,7 +21,8 @@ class StoreObserver: NSObject, SKPaymentTransactionObserver {
//Observe transaction updates.
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
//Handle transaction states here.
-
+ Log.info("StoreObserver received a transaction update. Notifying to delegate.", for: .damus_purple)
+
Task {
try await self.delegate?.send_receipt()
}