Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Converting InAppBilling.Plugin to Amazon

Converting InAppBilling.Plugin to Amazon

Scheduled Pinned Locked Moved C#
androidmobilehelpquestionlearning
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Exoskeletor
    wrote on last edited by
    #1

    Hello Guys, I have create a Android application in Xamarin and i would like to also have in on Amazon store. It uses in App purchases Currently im implementing those purchases with this code:

    public async Task WasItemPurchased(string productId)
    {
    var billing = CrossInAppBilling.Current;
    var result = false;
    try
    {
    var connected = await billing.ConnectAsync(ItemType.InAppPurchase);

    if (!connected)
    {
    //Couldn't connect
    return false;
    }

    //check purchases
    var verify = new InAppBillingVerify();
    var purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase, verify);

    //check for null just incase
    if (purchases?.Any(p => p.ProductId == productId) ?? false)
    {
    //Purchase restored
    Preferences.Set(productId, true);
    return true;
    }
    else
    {
    //no purchases found
    //Toast.MakeText(this, GetString(Resource.String.Options_RestoreUnavailable), ToastLength.Long);
    return false;
    }
    }
    catch (InAppBillingPurchaseException purchaseEx)
    {
    var message = string.Empty;
    switch (purchaseEx.PurchaseError)
    {
    case PurchaseError.AppStoreUnavailable:
    RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
    break;
    case PurchaseError.BillingUnavailable:
    RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorBillingUnavailable);
    break;
    case PurchaseError.PaymentInvalid:
    RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentInvalid);
    break;
    case PurchaseError.PaymentNotAllowed:
    RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentNotAllowed);
    break;
    case PurchaseError.AlreadyOwned:
    RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAlreadyOwned);
    Preferences.Set(productId, true);
    result = true;
    break;
    }

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

    //Display message to user
    //Toast.MakeText(this, message, ToastLength.Long);
    }
    catch (Exception exception)
    {
    Crashes.TrackError(exception);
    //Something has gone wrong
    RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
    //Toast.MakeText(this, GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable), ToastLength.Long);
    }
    finally
    {
    await billing.DisconnectAsync();
    }

    OriginalGriffO K 2 Replies Last reply
    0
    • E Exoskeletor

      Hello Guys, I have create a Android application in Xamarin and i would like to also have in on Amazon store. It uses in App purchases Currently im implementing those purchases with this code:

      public async Task WasItemPurchased(string productId)
      {
      var billing = CrossInAppBilling.Current;
      var result = false;
      try
      {
      var connected = await billing.ConnectAsync(ItemType.InAppPurchase);

      if (!connected)
      {
      //Couldn't connect
      return false;
      }

      //check purchases
      var verify = new InAppBillingVerify();
      var purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase, verify);

      //check for null just incase
      if (purchases?.Any(p => p.ProductId == productId) ?? false)
      {
      //Purchase restored
      Preferences.Set(productId, true);
      return true;
      }
      else
      {
      //no purchases found
      //Toast.MakeText(this, GetString(Resource.String.Options_RestoreUnavailable), ToastLength.Long);
      return false;
      }
      }
      catch (InAppBillingPurchaseException purchaseEx)
      {
      var message = string.Empty;
      switch (purchaseEx.PurchaseError)
      {
      case PurchaseError.AppStoreUnavailable:
      RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
      break;
      case PurchaseError.BillingUnavailable:
      RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorBillingUnavailable);
      break;
      case PurchaseError.PaymentInvalid:
      RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentInvalid);
      break;
      case PurchaseError.PaymentNotAllowed:
      RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentNotAllowed);
      break;
      case PurchaseError.AlreadyOwned:
      RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAlreadyOwned);
      Preferences.Set(productId, true);
      result = true;
      break;
      }

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

      //Display message to user
      //Toast.MakeText(this, message, ToastLength.Long);
      }
      catch (Exception exception)
      {
      Crashes.TrackError(exception);
      //Something has gone wrong
      RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
      //Toast.MakeText(this, GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable), ToastLength.Long);
      }
      finally
      {
      await billing.DisconnectAsync();
      }

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you. So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in! Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      E 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you. So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in! Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

        E Offline
        E Offline
        Exoskeletor
        wrote on last edited by
        #3

        Well i cant understand the API, at all and that is why i dont have code to demonstrate. Can you give me an example of a successful purchase and a check if a purchase exist already? What is this function: GetPurchaseUpdates? Update to what? What is the Response of the Purchase function? How i can know of a purchase was successful? Where i can find a list will all possible responses?

        OriginalGriffO 1 Reply Last reply
        0
        • E Exoskeletor

          Well i cant understand the API, at all and that is why i dont have code to demonstrate. Can you give me an example of a successful purchase and a check if a purchase exist already? What is this function: GetPurchaseUpdates? Update to what? What is the Response of the Purchase function? How i can know of a purchase was successful? Where i can find a list will all possible responses?

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          If you are trying to handle anything to do with real money - and you are - then you shouldn't be getting code (or anything else) from a "random website"! Never, ever, accept code from a insecure website to handle anything to do with real money. You do not know who is giving you the code, you do not know what it does, you do not know that it places the monies correctly into the appropriate account, without passing the details to any third parties. Only get such code from Amazon themselves - the scope for fraud otherwise is far too large. And remember, you personally could be liable for any monies lost if your action is seen to be negligent - which getting your code from a public forum would most certainly be! So start looking for API tutorials which explain how to do it, and then check that against the official API documentation. You need to understand this stuff if you are going to use it - or you could well end up coding from a cell ... :laugh:

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          E 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            If you are trying to handle anything to do with real money - and you are - then you shouldn't be getting code (or anything else) from a "random website"! Never, ever, accept code from a insecure website to handle anything to do with real money. You do not know who is giving you the code, you do not know what it does, you do not know that it places the monies correctly into the appropriate account, without passing the details to any third parties. Only get such code from Amazon themselves - the scope for fraud otherwise is far too large. And remember, you personally could be liable for any monies lost if your action is seen to be negligent - which getting your code from a public forum would most certainly be! So start looking for API tutorials which explain how to do it, and then check that against the official API documentation. You need to understand this stuff if you are going to use it - or you could well end up coding from a cell ... :laugh:

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

            E Offline
            E Offline
            Exoskeletor
            wrote on last edited by
            #5

            I ask for an example of an API i dont know where this danger that will put you in a cell come from :P

            1 Reply Last reply
            0
            • E Exoskeletor

              Hello Guys, I have create a Android application in Xamarin and i would like to also have in on Amazon store. It uses in App purchases Currently im implementing those purchases with this code:

              public async Task WasItemPurchased(string productId)
              {
              var billing = CrossInAppBilling.Current;
              var result = false;
              try
              {
              var connected = await billing.ConnectAsync(ItemType.InAppPurchase);

              if (!connected)
              {
              //Couldn't connect
              return false;
              }

              //check purchases
              var verify = new InAppBillingVerify();
              var purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase, verify);

              //check for null just incase
              if (purchases?.Any(p => p.ProductId == productId) ?? false)
              {
              //Purchase restored
              Preferences.Set(productId, true);
              return true;
              }
              else
              {
              //no purchases found
              //Toast.MakeText(this, GetString(Resource.String.Options_RestoreUnavailable), ToastLength.Long);
              return false;
              }
              }
              catch (InAppBillingPurchaseException purchaseEx)
              {
              var message = string.Empty;
              switch (purchaseEx.PurchaseError)
              {
              case PurchaseError.AppStoreUnavailable:
              RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
              break;
              case PurchaseError.BillingUnavailable:
              RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorBillingUnavailable);
              break;
              case PurchaseError.PaymentInvalid:
              RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentInvalid);
              break;
              case PurchaseError.PaymentNotAllowed:
              RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorPaymentNotAllowed);
              break;
              case PurchaseError.AlreadyOwned:
              RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAlreadyOwned);
              Preferences.Set(productId, true);
              result = true;
              break;
              }

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

              //Display message to user
              //Toast.MakeText(this, message, ToastLength.Long);
              }
              catch (Exception exception)
              {
              Crashes.TrackError(exception);
              //Something has gone wrong
              RestorePurchasesStatusMessage = GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable);
              //Toast.MakeText(this, GetString(Resource.String.Options_PaidFunctions_ErrorAppStoreUnavailable), ToastLength.Long);
              }
              finally
              {
              await billing.DisconnectAsync();
              }

              K Offline
              K Offline
              Kris Lantz
              wrote on last edited by
              #6

              Many of the calls from your original link are explained a bit further here. IAP Plugin Methods and Events | Cross-Platform Plugins[^] You may have some luck finding some examples by exploring the iap forum here: All Posts in In-App Purchasing (IAP) 2.0 - Forums[^], or the app store forum from either link.

              E 1 Reply Last reply
              0
              • K Kris Lantz

                Many of the calls from your original link are explained a bit further here. IAP Plugin Methods and Events | Cross-Platform Plugins[^] You may have some luck finding some examples by exploring the iap forum here: All Posts in In-App Purchasing (IAP) 2.0 - Forums[^], or the app store forum from either link.

                E Offline
                E Offline
                Exoskeletor
                wrote on last edited by
                #7

                Okz thanks

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups