The following code sample shows how to get the system to display a UI that enables the user to complete or cancel out of a purchase flow. The sample function takes a string representing an offer and calls Product.ShowPurchaseAsync Method to display the purchase dialog.
HRESULT Sample::PurchaseItem( const std::wstring& wstrSignedOffer )
{
auto pAsyncOp = Store::Product::ShowPurchaseAsync( User::Users->GetAt( m_iUserIndex )
, ref new Platform::String( wstrSignedOffer.c_str() ) );
create_task( pAsyncOp )
.then( [ this ] ( )
{
try
{
XboxSampleFramework::DebugPrint( "SAMPLE: ShowPurchaseAsync returned\n" );
}
catch (Platform::Exception^ ex)
{
XboxSampleFramework::DebugPrint( "SAMPLE: Failed purchase of signed offer 0x%x\n", ex->HResult );
m_hrDisplayError = ex->HResult;
m_appState = APP_DONE_ERROR;
}
});
return S_OK;
}