Skip to content

Commit

Permalink
InAppPurchases: handle the case with AppStore where purchase time in …
Browse files Browse the repository at this point in the history
…a receipt is a string.
  • Loading branch information
lukaszkozakiewicz committed Oct 24, 2017
1 parent 523a599 commit e0088c1
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions modules/juce_product_unlocking/native/juce_ios_InAppPurchases.cpp
Expand Up @@ -588,12 +588,14 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
{
if (auto productId = getAs<NSString> (purchaseData[nsStringLiteral ("product_id")]))
{
if (auto purchaseTime = getAs<NSNumber> (purchaseData[nsStringLiteral ("purchase_date_ms")]))
auto purchaseTime = getPurchaseDateMs (purchaseData[nsStringLiteral ("purchase_date_ms")]);

if (purchaseTime > 0)
{
purchases.add ({ { nsStringToJuce (transactionId),
nsStringToJuce (productId),
nsStringToJuce (bundleId),
Time ([purchaseTime integerValue]).toString (true, true, true, true),
Time (purchaseTime).toString (true, true, true, true),
{} }, {} });
}
else
Expand Down Expand Up @@ -625,6 +627,26 @@ struct InAppPurchases::Pimpl : public SKDelegateAndPaymentObserver
{}, false, NEEDS_TRANS ("Receipt fetch failed")); });
}

static int64 getPurchaseDateMs (id date)
{
if (auto dateAsNumber = getAs<NSNumber> (date))
{
return [dateAsNumber longLongValue];
}
else if (auto dateAsString = getAs<NSString> (date))
{
auto* formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle: NSNumberFormatterDecimalStyle];
dateAsNumber = [formatter numberFromString: dateAsString];
[formatter release];
return [dateAsNumber longLongValue];
}
else
{
return -1;
}
}

//==============================================================================
static Product SKProductToIAPProduct (SKProduct* skProduct)
{
Expand Down

0 comments on commit e0088c1

Please sign in to comment.