Skip to content

Commit

Permalink
Merge pull request #532 from jamesmontemagno/android-v5
Browse files Browse the repository at this point in the history
start implementing v5
  • Loading branch information
jamesmontemagno committed Aug 4, 2023
2 parents 283f279 + b8d4743 commit 40c0aef
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 173 deletions.
8 changes: 8 additions & 0 deletions nuget/readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
In-App Billing Plugin for .NET MAUI, Xamarin, & Windows

Version 7.0+ - Major Android updates
1.) You must compile and target against Android 12 or higher
2.) Android: Now using Android Billing v6
3.) Android: Major changes to Android product details, subscriptions, and more

Please read through: https://developer.android.com/google/play/billing/migrate-gpblv6


Version 5.0+ has significant updates!
1.) We have removed IInAppBillingVerifyPurchase from all methods. All data required to handle this yourself is returned.
2.) iOS ReceiptURL data is avaialble via ReceiptData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@
<Project>{6D4D9135-F225-4626-A9CE-32BDF97AEA89}</Project>
<Name>InAppBillingTests</Name>
</ProjectReference>
<ProjectReference Include="..\..\Plugin.InAppBilling\Plugin.InAppBilling.csproj">
<Project>{C570E25E-259F-4D4C-88F0-B2982815192D}</Project>
<Name>Plugin.InAppBilling</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,5 @@
<Project>{6D4D9135-F225-4626-A9CE-32BDF97AEA89}</Project>
<Name>InAppBillingTests</Name>
</ProjectReference>
<ProjectReference Include="..\..\Plugin.InAppBilling\Plugin.InAppBilling.csproj">
<Project>{C570E25E-259F-4D4C-88F0-B2982815192D}</Project>
<Name>Plugin.InAppBilling</Name>
</ProjectReference>
</ItemGroup>
</Project>
49 changes: 31 additions & 18 deletions src/Plugin.InAppBilling/Converters.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ internal static InAppBillingPurchase ToIABPurchase(this Purchase purchase)
Signature = purchase.Signature,
IsAcknowledged = purchase.IsAcknowledged,
Payload = purchase.DeveloperPayload,
ProductId = purchase.Skus.FirstOrDefault(),
ProductId = purchase.Products?.FirstOrDefault(),
Quantity = purchase.Quantity,
ProductIds = purchase.Skus,
ProductIds = purchase.Products,
PurchaseToken = purchase.PurchaseToken,
TransactionDateUtc = DateTimeOffset.FromUnixTimeMilliseconds(purchase.PurchaseTime).DateTime,
ObfuscatedAccountId = purchase.AccountIdentifiers?.ObfuscatedAccountId,
Expand All @@ -44,37 +44,50 @@ internal static InAppBillingPurchase ToIABPurchase(this PurchaseHistoryRecord pu
OriginalJson = purchase.OriginalJson,
Signature = purchase.Signature,
Payload = purchase.DeveloperPayload,
ProductId = purchase.Skus.FirstOrDefault(),
ProductId = purchase.Products?.FirstOrDefault(),
Quantity = purchase.Quantity,
ProductIds = purchase.Skus,
ProductIds = purchase.Products,
PurchaseToken = purchase.PurchaseToken,
TransactionDateUtc = DateTimeOffset.FromUnixTimeMilliseconds(purchase.PurchaseTime).DateTime,
State = PurchaseState.Unknown,
TransactionIdentifier = purchase.PurchaseToken
};
}

internal static InAppBillingProduct ToIAPProduct(this SkuDetails product)
internal static InAppBillingProduct ToIAPProduct(this ProductDetails product)
{
var oneTime = product.GetOneTimePurchaseOfferDetails();
var subs = product.GetSubscriptionOfferDetails()?.Select(s => new SubscriptionOfferDetail
{
BasePlanId = s.BasePlanId,
OfferId = s.OfferId,
OfferTags = s.OfferTags?.ToList(),
OfferToken = s.OfferToken,
PricingPhases = s?.PricingPhases?.PricingPhaseList?.Select(p =>
new PricingPhase
{
BillingCycleCount = p.BillingCycleCount,
BillingPeriod = p.BillingPeriod,
FormattedPrice = p.FormattedPrice,
PriceAmountMicros = p.PriceAmountMicros,
PriceCurrencyCode = p.PriceCurrencyCode,
RecurrenceMode = p.RecurrenceMode
}).ToList()
}).ToList();

var firstSub = subs?.FirstOrDefault()?.PricingPhases?.FirstOrDefault();

return new InAppBillingProduct
{
Name = product.Title,
Description = product.Description,
CurrencyCode = product.PriceCurrencyCode,
LocalizedPrice = product.Price,
ProductId = product.Sku,
MicrosPrice = product.PriceAmountMicros,
CurrencyCode = oneTime?.PriceCurrencyCode ?? firstSub?.PriceCurrencyCode,
LocalizedPrice = oneTime?.FormattedPrice ?? firstSub?.FormattedPrice,
ProductId = product.ProductId,
MicrosPrice = oneTime?.PriceAmountMicros ?? firstSub?.PriceAmountMicros ?? 0,
AndroidExtras = new InAppBillingProductAndroidExtras
{
SubscriptionPeriod = product.SubscriptionPeriod,
LocalizedIntroductoryPrice = product.IntroductoryPrice,
MicrosIntroductoryPrice = product.IntroductoryPriceAmountMicros,
FreeTrialPeriod = product.FreeTrialPeriod,
IconUrl = product.IconUrl,
IntroductoryPriceCycles = product.IntroductoryPriceCycles,
IntroductoryPricePeriod = product.IntroductoryPricePeriod,
MicrosOriginalPriceAmount = product.OriginalPriceAmountMicros,
OriginalPrice = product.OriginalPrice
SubscriptionOfferDetails = subs
}
};
}
Expand Down
Loading

0 comments on commit 40c0aef

Please sign in to comment.