Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eligiblePromotionalOffers: don't log error if response is ineligible #2019

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/Misc/Purchases+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ extension Purchases {
forProductDiscount: discount,
product: product
)
} catch RevenueCat.ErrorCode.ineligibleError {
return nil
} catch {
Logger.error(
Strings.purchase.check_eligibility_failed(
Expand Down
44 changes: 41 additions & 3 deletions Tests/StoreKitUnitTests/PurchasesOrchestratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ class PurchasesOrchestratorTests: StoreKitConfigTestCase {
expect(self.backend.invokedPostReceiptDataParameters?.productData).toNot(beNil())
}

func testPurchaseSK1PromotionalOffer() async throws {
func testGetSK1PromotionalOffer() async throws {
customerInfoManager.stubbedCachedCustomerInfoResult = mockCustomerInfo
backend.stubbedPostReceiptResult = .success(mockCustomerInfo)
offerings.stubbedPostOfferCompletionResult = .success(("signature", "identifier", UUID(), 12345))

let product = try await fetchSk1Product()
Expand All @@ -210,16 +209,55 @@ class PurchasesOrchestratorTests: StoreKitConfigTestCase {
numberOfPeriods: 2,
type: .promotional)

_ = try await Async.call { completion in
let result = try await Async.call { completion in
orchestrator.promotionalOffer(forProductDiscount: storeProductDiscount,
product: StoreProduct(sk1Product: product),
completion: completion)
}

expect(result.signedData.identifier) == storeProductDiscount.offerIdentifier

expect(self.offerings.invokedPostOfferCount) == 1
expect(self.offerings.invokedPostOfferParameters?.offerIdentifier) == storeProductDiscount.offerIdentifier
}

func testGetSK1PromotionalOfferFailsWithIneligibleDiscount() async throws {
self.customerInfoManager.stubbedCachedCustomerInfoResult = mockCustomerInfo
self.offerings.stubbedPostOfferCompletionResult = .failure(
.networkError(
.errorResponse(
.init(code: .userIneligibleForPromoOffer),
.success
)
)
)

let product = try await self.fetchSk1Product()

let storeProductDiscount = MockStoreProductDiscount(offerIdentifier: "offerid1",
currencyCode: product.priceLocale.currencyCode,
price: 11.1,
localizedPriceString: "$11.10",
paymentMode: .payAsYouGo,
subscriptionPeriod: .init(value: 1, unit: .month),
numberOfPeriods: 2,
type: .promotional)

do {
_ = try await Async.call { completion in
self.orchestrator.promotionalOffer(forProductDiscount: storeProductDiscount,
product: StoreProduct(sk1Product: product),
completion: completion)
}

fail("Expected error")
} catch let purchasesError as PurchasesError {
expect(purchasesError.error).to(matchError(ErrorCode.ineligibleError))
} catch {
fail("Unexpected error: \(error)")
}
}

func testPurchaseSK1PackageWithDiscountSendsReceiptToBackendIfSuccessful() async throws {
customerInfoManager.stubbedCachedCustomerInfoResult = mockCustomerInfo
offerings.stubbedPostOfferCompletionResult = .success(("signature", "identifier", UUID(), 12345))
Expand Down