Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to android v7 billing library #635

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions src/ClassLibraryTest/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ClassLibraryTest;

public class Class1
{
public void Test()
{
}
}
13 changes: 13 additions & 0 deletions src/ClassLibraryTest/ClassLibraryTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Plugin.InAppBilling\Plugin.InAppBilling.csproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions src/InAppBilling.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{5124C265
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InAppBillingMauiTest", "InAppBillingTests\InAppBillingMauiTest\InAppBillingMauiTest.csproj", "{BAE4393A-4E17-4E60-BF53-E916505F44E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibraryTest", "ClassLibraryTest\ClassLibraryTest.csproj", "{766E2D00-352E-455F-9717-3F9864F3247A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -47,12 +49,17 @@ Global
{BAE4393A-4E17-4E60-BF53-E916505F44E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAE4393A-4E17-4E60-BF53-E916505F44E1}.Release|Any CPU.Build.0 = Release|Any CPU
{BAE4393A-4E17-4E60-BF53-E916505F44E1}.Release|Any CPU.Deploy.0 = Release|Any CPU
{766E2D00-352E-455F-9717-3F9864F3247A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{766E2D00-352E-455F-9717-3F9864F3247A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{766E2D00-352E-455F-9717-3F9864F3247A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{766E2D00-352E-455F-9717-3F9864F3247A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BAE4393A-4E17-4E60-BF53-E916505F44E1} = {5124C265-C6EF-4415-9497-0EF227E43095}
{766E2D00-352E-455F-9717-3F9864F3247A} = {5124C265-C6EF-4415-9497-0EF227E43095}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {42D18242-8BA9-4238-9D59-10850E1C2C24}
Expand Down
8 changes: 7 additions & 1 deletion src/InAppBillingTests/InAppBillingMauiTest/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
namespace InAppBillingMauiTest
using Plugin.InAppBilling;

namespace InAppBillingMauiTest
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{

#if IOS
var test = new InAppBillingImplementation();
#endif
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
Expand Down
13 changes: 10 additions & 3 deletions src/Plugin.InAppBilling/InAppBilling.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ public override Task<bool> ConnectAsync(bool enablePendingPurchases = true, Canc
BillingClientBuilder = NewBuilder(Context);
BillingClientBuilder.SetListener(OnPurchasesUpdated);
if (enablePendingPurchases)
BillingClient = BillingClientBuilder.EnablePendingPurchases().Build();
{
var pendingParams = PendingPurchasesParams.NewBuilder().EnableOneTimeProducts().EnablePrepaidPlans().Build();
BillingClient = BillingClientBuilder.EnablePendingPurchases(pendingParams).Build();
}
else
BillingClient = BillingClientBuilder.Build();

{
var pendingParams = PendingPurchasesParams.NewBuilder().EnableOneTimeProducts().Build();
BillingClient = BillingClientBuilder.EnablePendingPurchases(pendingParams).Build();
}

BillingClient.StartConnection(OnSetupFinished, OnDisconnected);
// TODO: stop trying
Expand Down Expand Up @@ -133,7 +140,6 @@ public override Task DisconnectAsync(CancellationToken cancellationToken)
return Task.CompletedTask;
}


/// <summary>
/// Gets or sets if in testing mode. Only for UWP
/// </summary>
Expand Down Expand Up @@ -483,6 +489,7 @@ static bool ParseBillingResult(BillingResult result, bool ignoreInvalidProducts
return result.ResponseCode switch
{
BillingResponseCode.Ok => true,
BillingResponseCode.NetworkError => throw new InAppBillingPurchaseException(PurchaseError.NetworkError),
BillingResponseCode.UserCancelled => throw new InAppBillingPurchaseException(PurchaseError.UserCancelled),//User Cancelled, should try again
BillingResponseCode.ServiceUnavailable => throw new InAppBillingPurchaseException(PurchaseError.ServiceUnavailable),//Network connection is down
BillingResponseCode.ServiceDisconnected => throw new InAppBillingPurchaseException(PurchaseError.ServiceDisconnected),//Network connection is down
Expand Down
78 changes: 24 additions & 54 deletions src/Plugin.InAppBilling/Plugin.InAppBilling.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0-macos</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst;net8.0-macos;net9.0;net9.0-android;net9.0-ios;net9.0-maccatalyst;net9.0-macos</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0;net9.0-windows10.0.19041.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<UseMaui Condition="'$(TargetFramework)' != 'net8.0'">true</UseMaui>
<UseMauiEssentials Condition="'$(TargetFramework)' != 'net8.0'">true</UseMauiEssentials>
<SingleProject>true</SingleProject>
<AssemblyName>Plugin.InAppBilling</AssemblyName>
<RootNamespace>Plugin.InAppBilling</RootNamespace>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyFileVersion>7.0.0.0</AssemblyFileVersion>
<Version>7.0.0.0</Version>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyFileVersion>9.0.0.0</AssemblyFileVersion>
<Version>9.0.0.0</Version>
<Authors>James Montemagno</Authors>
<IsPackable>True</IsPackable>
<PackageId>Plugin.InAppBilling</PackageId>
Expand Down Expand Up @@ -44,12 +42,12 @@

<!-- platform version number information -->
<PropertyGroup>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('ios'))">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('maccatalyst'))">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('macos'))">13.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('android'))">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('windows'))">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$(TargetFramework.Contains('windows'))">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
Expand Down Expand Up @@ -94,48 +92,20 @@
<!-- Android -->

<ItemGroup Condition=" $(TargetFramework.Contains('-android')) ">
<PackageReference Include="Microsoft.Maui.Essentials" Version="$(MauiVersion)" />
<PackageReference Include="Xamarin.Android.Google.BillingClient" Version="6.2.1" />
<PackageReference Include="Xamarin.AndroidX.Activity">
<Version>1.9.0.4</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Activity.Ktx">
<Version>1.9.0.4</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Collection">
<Version>1.4.0.6</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx">
<Version>1.4.0.5</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Ktx">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Core">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Runtime">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Runtime.Ktx">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModel">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModel.Ktx">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModelSavedState">
<Version>2.8.3.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Android.Google.BillingClient" Version="7.1.1.1" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData.Core">
<Version>2.8.7.1</Version>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.Contains('net8.0-android')) ">
<PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.100" />
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.Contains('net9.0-android')) ">
<PackageReference Include="Microsoft.Maui.Essentials" Version="9.0.10" />
</ItemGroup>


<ItemGroup Condition="$(TargetFramework.StartsWith('net')) == true AND $(TargetFramework.Contains('-android')) != true">
<Compile Remove="**\**\*.android.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public enum PurchaseError
FeatureNotSupported,
ServiceDisconnected,
ServiceTimeout,
AppleTermsConditionsChanged
}
AppleTermsConditionsChanged,
NetworkError
}

/// <summary>
/// Purchase exception
Expand Down