tikhop / Mercato

Lightweight StoreKit 2 Wrapper
MIT License
61 stars 13 forks source link

Is this Production ready? #5

Closed sabiland closed 1 year ago

sabiland commented 1 year ago

In the examples I do not see anywhere switch cases for failed purchasings (as in SwiftyStoreKit, etc.) ?

How about restoring purchases? How to check if IAP was already purchased before? Reinstalling the app, etc.

tikhop commented 1 year ago

Hi @sabiland, thanks for asking. Yes, it's production ready and I have been using it since I released it. Failed transaction will throw an error from StoreKit framework. Restoring purchases works differently in store kit 2 and Mercato supports it as well. With store kit 2 you can only track non-consumable + subscriptions iaps, Mercato only support subscriptions, but I will add support for non-consumable.

sabiland commented 1 year ago

Thx for quick reply. About non-consumable, can I make non-consumable purchase with Mercato? I have already checked about restoring purchases with StoreKit 2, will do it manually for now probably.

And where is Mercato.purchase completion block? Success, etc.? Maybe I don’t yet understand how StoreKit2 and/or Mercato works. EDIT: I saw the StoreKit 2 is handling error messages via popups right?

sabiland commented 1 year ago

Ok I think I have managed to refactor first of my apps to StoreKit 2 with the help of Mercato.

tikhop commented 1 year ago

Sounds good!

sabiland commented 1 year ago

@tikhop Will you allow another question, where are string messages defined for your errors?

I get this for example if I simulate IAP and then cancel it. I know Apple does not allow those kind of messages for the user. The operation couldn’t be completed. (Mercato.MercatoError error 2.)

public enum MercatoError: Error
{
    case storeKit(error: StoreKitError)
    case purchase(error: Product.PurchaseError)
    case purchaseCanceledByUser
    case userCancelledRefundProcess
    case purchaseIsPending
    case failedVerification
    case genericError
}
tikhop commented 1 year ago

@sabiland the message comes from the system.

sabiland commented 1 year ago

Yes, but it adds extra info e.g. (Mercato.MercatoError error 0.). Apple would not allow this kind of message.

So I fixed this by checking for "(" character and remove everything behind.

func cleanPossibleStoreKitAndExtraAddedMessage(input: String) -> String
        {
            // NOTE: Input can be like this ---> "The operation couldn’t be completed. (Mercato.MercatoError error 0.)"
            let splitted = Array(input.components(separatedBy: "("))
            return (splitted.first ?? input).fullTrim()
        }