简体   繁体   中英

Can I test real In-App Purchases before submitting to the Store?

Building In-App Purchases in a Windows Store App requires using the In-App Purchase Simulator. It is almost identical to the real In-App Purchase Namespace. While building my app, I use the simulator. I have reserved my name in the Store. I have even created an In-App Purchase in the Store for my App. Is there a way to test the real IAP before submitting my app for Certification?

No, In-App Purchases are not "real" in the Windows Store until your app is submitted for Certification. That means your final step before submission is to swap out the Simulator code for the real code. And, yes, it means you cannot test your real code - the Store tester will be the first to test it for you.

One more thing

Having said that, I created a helper class that wraps both the real and the simulator API. Though it will only help 90% of the use cases out there, it is perfect for those 90%. I have validated the code with the IAP product team and submitted real apps that use it.

You can find this helper here: http://codepaste.net/rqwtcy

Here's the syntax if you want to remove advertisements, for example...

I add it to my View Model like this:

public async Task Start()
{
    // in app purchase setup
    m_HideAdsFeature = await new InAppPurchaseHelper(HIDEADSFAETURENAME,
        System.Diagnostics.Debugger.IsAttached).Setup();
    this.HideAds = m_HideAdsFeature.IsPurchased;
}

bool m_HideAds = false;
public bool HideAds { get { return m_HideAds; } set { SetProperty(ref m_HideAds, value); } }

const string HIDEADSFAETURENAME = "HideAds";
InAppPurchaseHelper m_HideAdsFeature;

// http://codepaste.net/ho9s5a
DelegateCommand m_PurchaseHideAdsCommand = null;
public DelegateCommand PurchaseHideAdsCommand
{
    get
    {
        if (m_PurchaseHideAdsCommand != null)
            return m_PurchaseHideAdsCommand;
        m_PurchaseHideAdsCommand = new DelegateCommand(
            PurchaseHideAdsCommandExecute, PurchaseHideAdsCommandCanExecute);
        this.PropertyChanged += (s, e) => m_PurchaseHideAdsCommand.RaiseCanExecuteChanged();
        return m_PurchaseHideAdsCommand;
    }
}
async void PurchaseHideAdsCommandExecute()
{
    PauseCommandExecute();
    await m_HideAdsFeature.Purchase();
    HideAds = m_HideAdsFeature.IsPurchased;
}
bool PurchaseHideAdsCommandCanExecute()
{
    if (m_HideAdsFeature == null)
        return false;
    return !m_HideAdsFeature.IsPurchased;
}

I add it to my XAML like this:

<UI:AdControl x:Name="MyAdControl"
    Width="250" Height="250"
    HorizontalAlignment="Left" VerticalAlignment="Top"
    AdUnitId="10043107" ApplicationId="d25517cb-12d4-4699-8bdc-52040c712cab"
    Visibility="{Binding HideAds,
            Converter={StaticResource CollapsedWhenTrueConverter}}" />

Best of luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM