Skip to content

Commit

Permalink
Merge pull request #14 from Busuu/handle-unauthorized-receipts-code
Browse files Browse the repository at this point in the history
Create a specific exception for the case where the receipt returns st…
  • Loading branch information
tdidierjean authored Sep 6, 2018
2 parents 691dcb4 + b3910ad commit 1bbfda9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Exception/UnauthorizedReceiptException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Busuu\IosReceiptsApi\Exception;

class UnauthorizedReceiptException extends InvalidReceiptException {}
13 changes: 12 additions & 1 deletion lib/ValidatorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Busuu\IosReceiptsApi;

use Busuu\IosReceiptsApi\Exception\InvalidReceiptException;
use Busuu\IosReceiptsApi\Exception\UnauthorizedReceiptException;

/**
* You can see the apple response documentation here: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1
Expand Down Expand Up @@ -46,6 +47,13 @@ class ValidatorService
* Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
*/
const EXPIRED_SUBSCRIPTION_CODE = 21006;

/*
* "This receipt could not be authorized. Treat this the same as if a purchase was never made."
* Unclear what causes this, but we're seeing it on some receipts.
*/
const UNAUTHORIZED_RECEIPT = 21010;

// 0 if the receipt is valid
const SUCCESS_RECEIPT_CODE = 0;

Expand Down Expand Up @@ -79,6 +87,9 @@ public function validateReceipt(array $receiptInfo)
case self::SUCCESS_RECEIPT_CODE:
$return = self::SUCCESS_VALIDATION_RESPONSE;
break;
case self::UNAUTHORIZED_RECEIPT:
throw new UnauthorizedReceiptException('This receipt could not be authorized. Treat this the same as if a purchase was never made.', $receiptInfo['status']);
break;
case self::INVALID_REQUEST_JSON_ERROR_CODE:
throw new InvalidReceiptException('The App Store could not read the JSON object you provided.', $receiptInfo['status']);
break;
Expand All @@ -102,4 +113,4 @@ public function validateReceipt(array $receiptInfo)

return $return;
}
}
}

0 comments on commit 1bbfda9

Please sign in to comment.