Compare commits

...

18 Commits

Author SHA1 Message Date
William Casarin 122775e586 Kick off v1.8 (1)
Signed-off-by: William Casarin <jb55@jb55.com>
2024-03-11 09:59:21 +00:00
William Casarin d83d618829 Merge branch 'v1.7-madeira-release' 2024-03-11 09:58:50 +00:00
William Casarin 669ca0d91c v1.7.2
Fix a few appstore iap-subscription purple ux issues

Signed-off-by: William Casarin <jb55@jb55.com>
2024-03-11 09:38:29 +00:00
Daniel D’Aquino ad8d30ded1 Improve mechanism of IAP verification with the server right after purchase
It was observed that sending the receipt to the server right after
performing the StoreKit purchase caused issues due to the receipt not
being completely ready when it got sent, causing rejections by the
server.

This commit, in conjuction with backend changes, implements purchase
verification through transaction IDs directly.

Testing
--------

PASS

Device: iPhone 13 Mini (physical device)
iOS: 17.3.1
Damus: This commit
damus-api: `a878da5598a9344a4d351f9a9da16712ce0615b7`
Setup:
- Local server Setup
- Local testing mode on Damus developer settings
- Clean Sandbox account (Create new sandbox account if clearing purchase history does not work)
- Fresh DB
- App is closed before starting.
- Run app on release target
- MOCK_VERIFY=false on server, with all IAP environment correctly setup
Steps:
1. Make Purple IAP purchase. Make sure that:
    - Server logs indicate `/apple-iap/transaction-id` is being hit and returning HTTP 200. PASS
    - No errors appear on the iOS side. After purchase the welcome sheet should appear, and then the account info. PASS

Part of: https://github.com/damus-io/damus/issues/2036
Changelog-Fixed: Fix in-app purchase issue that would trigger an error on purchase before confirming the account information.

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>
2024-03-11 09:29:02 +00:00
Daniel D’Aquino f738aaf358 Increase verbosity of IAP-related logs
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
2024-03-11 09:28:15 +00:00
William Casarin 5f4c342131 Revert "Merge remote-tracking branch 'github/translations'"
Reverting due to CI error:

```
damus file:///Volumes/workspace/repository/damus/cs.lproj/Localizable.stringsdict

validation failed: Couldn't parse property list because the input data
was in an invalid format (1)
```

This reverts commit fa738c4303, reversing
changes made to 9511ba767a.
2024-03-04 18:31:55 +00:00
William Casarin fa738c4303 Merge remote-tracking branch 'github/translations'
034f31797e Translate Localizable.strings in de
adb6f66a4f Translate Localizable.strings in zh_TW
a5f438b9c7 Translate Localizable.strings in zh_HK
d7f04d9ab9 Translate Localizable.strings in zh_HK
0b2ea46ef4 Translate Localizable.strings in zh_HK
331ed96d57 Translate Localizable.strings in zh_CN
701a747ed6 Translate Localizable.strings in cs
118c2bf2b2 Translate Localizable.stringsdict in cs
7a4f82c97b Translate Localizable.strings in de
d1e3a06cc6 Translate Localizable.strings in de
b9d960b54b Translate InfoPlist.strings in cs
2024-03-04 17:36:52 +00:00
transifex-integration[bot] 034f31797e
Translate Localizable.strings in de
100% translated source file: 'Localizable.strings'
on 'de'.
2024-02-29 17:35:11 +00:00
transifex-integration[bot] adb6f66a4f
Translate Localizable.strings in zh_TW
100% translated source file: 'Localizable.strings'
on 'zh_TW'.
2024-02-13 07:39:33 +00:00
transifex-integration[bot] a5f438b9c7
Translate Localizable.strings in zh_HK
100% translated source file: 'Localizable.strings'
on 'zh_HK'.
2024-02-13 07:34:28 +00:00
transifex-integration[bot] d7f04d9ab9
Translate Localizable.strings in zh_HK
100% translated source file: 'Localizable.strings'
on 'zh_HK'.
2024-02-13 07:34:05 +00:00
transifex-integration[bot] 0b2ea46ef4
Translate Localizable.strings in zh_HK
100% translated source file: 'Localizable.strings'
on 'zh_HK'.
2024-02-13 07:29:25 +00:00
transifex-integration[bot] 331ed96d57
Translate Localizable.strings in zh_CN
100% translated source file: 'Localizable.strings'
on 'zh_CN'.
2024-02-13 07:29:00 +00:00
transifex-integration[bot] 701a747ed6
Translate Localizable.strings in cs
100% translated source file: 'Localizable.strings'
on 'cs'.
2024-02-12 06:16:42 +00:00
transifex-integration[bot] 118c2bf2b2
Translate Localizable.stringsdict in cs
100% translated source file: 'Localizable.stringsdict'
on 'cs'.
2024-02-09 19:28:54 +00:00
transifex-integration[bot] 7a4f82c97b
Translate Localizable.strings in de
100% translated source file: 'Localizable.strings'
on 'de'.
2024-02-09 17:59:18 +00:00
transifex-integration[bot] d1e3a06cc6
Translate Localizable.strings in de
100% translated source file: 'Localizable.strings'
on 'de'.
2024-02-09 17:58:50 +00:00
transifex-integration[bot] b9d960b54b
Translate InfoPlist.strings in cs
100% translated source file: 'InfoPlist.strings'
on 'cs'.
2024-02-09 10:05:08 +00:00
3 changed files with 41 additions and 12 deletions

View File

@ -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;

View File

@ -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")

View File

@ -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()
}