EmilAlipiev / XFInAppBilling

MIT License
12 stars 3 forks source link

Crashes on PurchaseAsync #13

Closed LesWoodland closed 2 years ago

LesWoodland commented 3 years ago

Hello , I'm pretty new to all this so please bear with me. I'm debugging my app on an IPhone and trying to test out in-app billing. However, no matter what I try, it simply crashes on Purchase Async, with no exceptions or any clue what is wrong.

Would you have any ideas what might be causing that?

static public async Task PurchaseItem(string productId, string payload) { try { var connected = await GetIAPbilling().ConnectAsync(); if (!connected) { //we are offline or can't connect, don't try to purchase return false; }

        var id = "perfexpurchase";

            //check purchases
            var purchase = await GetIAPbilling().PurchaseAsync(id, ItemType.InAppPurchase,"fred99");

            //possibility that a null came through.
            if (purchase == null)
            {
                //did not purchase

            }
            else if (purchase.PurchaseState == PurchaseState.Purchased)
            {
                //purchased!

                return true;

            }
        }
        catch (InAppBillingPurchaseException purchaseEx)
        {
            var message = string.Empty;
            switch (purchaseEx.PurchaseError)
            {
                case PurchaseError.AppStoreUnavailable:
                    message = "Currently the app store seems to be unavailble. Try again later.";
                    break;
                case PurchaseError.BillingUnavailable:
                    message = "Billing seems to be unavailable, please try again later.";
                    break;
                case PurchaseError.PaymentInvalid:
                    message = "Payment seems to be invalid, please try again.";
                    break;
                case PurchaseError.PaymentNotAllowed:
                    message = "Payment does not seem to be enabled/allowed, please try again.";
                    break;
            }

            //Decide if it is an error we care about
            if (string.IsNullOrWhiteSpace(message))
                return false;

            //Display message to user

            Debug.WriteLine("Error: " + purchaseEx);
        }
        catch (Exception ex)
        {
            //Something else has gone wrong, log it
            Debug.WriteLine("Issue connecting: " + ex);
        }
        finally
        {
            GetIAPbilling().Disconnect();
        }
        return false;

    }

Thanks, Les Woodland

EmilAlipiev commented 2 years ago

Hey Les, sorry for coming back to here so late. If you still use the library, i would love to help you if you have any issue currently latest version works fine on Ios. please feel free to open this if there is any issue. thanks.