mirror of
git://jb55.com/damus
synced 2024-09-29 16:30:44 +00:00
Compare commits
18 Commits
9511ba767a
...
122775e586
Author | SHA1 | Date | |
---|---|---|---|
|
122775e586 | ||
|
d83d618829 | ||
|
669ca0d91c | ||
|
ad8d30ded1 | ||
|
f738aaf358 | ||
|
5f4c342131 | ||
|
fa738c4303 | ||
|
034f31797e | ||
|
adb6f66a4f | ||
|
a5f438b9c7 | ||
|
d7f04d9ab9 | ||
|
0b2ea46ef4 | ||
|
331ed96d57 | ||
|
701a747ed6 | ||
|
118c2bf2b2 | ||
|
7a4f82c97b | ||
|
d1e3a06cc6 | ||
|
b9d960b54b |
@ -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.8;
|
||||
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.8;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
|
@ -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)
|
||||
@ -175,7 +177,7 @@ class DamusPurple: StoreObserverDelegate {
|
||||
|
||||
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,
|
||||
@ -197,6 +199,32 @@ 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")
|
||||
|
@ -21,6 +21,7 @@ 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()
|
||||
|
Loading…
Reference in New Issue
Block a user