Skip to content

Commit

Permalink
Handle only subscription in-app purchases
Browse files Browse the repository at this point in the history
- Change `VerifyPurchaseV2ApiHandler` in AppleAppstoreModule to handle 
only `AUTO_RENEWABLE` product type transactions.

- Add purchase type validation to `VerifyPurchaseApiHandler` 
in GooglePlayBillingModule. Handler allows only subscription purchases.

remp/respekt#273
  • Loading branch information
Matus Kalafut committed Nov 12, 2024
1 parent 017c6e2 commit 4558fce
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/Api/VerifyPurchaseV2ApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Nette\Http\IResponse;
use Nette\Utils\Random;
use Readdle\AppStoreServerAPI\Exception\AppStoreServerAPIException;
use Readdle\AppStoreServerAPI\RequestQueryParams\GetTransactionHistoryQueryParams;
use Readdle\AppStoreServerAPI\TransactionInfo;
use Tomaj\NetteApi\Response\JsonApiResponse;
use Tomaj\NetteApi\Response\ResponseInterface;
Expand All @@ -40,18 +41,18 @@ class VerifyPurchaseV2ApiHandler extends ApiHandler
use AppStoreServerDateTimesTrait;

public function __construct(
private AppStoreServerApiFactory $appStoreServerApiFactory,
private PaymentMetaRepository $paymentMetaRepository,
private AccessTokensRepository $accessTokensRepository,
private DeviceTokensRepository $deviceTokensRepository,
private AppleAppstoreOriginalTransactionsRepository $appleAppstoreOriginalTransactionsRepository,
private AppleAppstoreTransactionDeviceTokensRepository $appleAppstoreTransactionDeviceTokensRepository,
private UserMetaRepository $userMetaRepository,
private UnclaimedUser $unclaimedUser,
private AppleAppstoreSubscriptionTypesRepository $appleAppstoreSubscriptionTypesRepository,
private PaymentsRepository $paymentsRepository,
private PaymentGatewaysRepository $paymentGatewaysRepository,
private RecurrentPaymentsRepository $recurrentPaymentsRepository,
private readonly AppStoreServerApiFactory $appStoreServerApiFactory,
private readonly PaymentMetaRepository $paymentMetaRepository,
private readonly AccessTokensRepository $accessTokensRepository,
private readonly DeviceTokensRepository $deviceTokensRepository,
private readonly AppleAppstoreOriginalTransactionsRepository $appleAppstoreOriginalTransactionsRepository,
private readonly AppleAppstoreTransactionDeviceTokensRepository $appleAppstoreTransactionDeviceTokensRepository,
private readonly UserMetaRepository $userMetaRepository,
private readonly UnclaimedUser $unclaimedUser,
private readonly AppleAppstoreSubscriptionTypesRepository $appleAppstoreSubscriptionTypesRepository,
private readonly PaymentsRepository $paymentsRepository,
private readonly PaymentGatewaysRepository $paymentGatewaysRepository,
private readonly RecurrentPaymentsRepository $recurrentPaymentsRepository,
) {
parent::__construct();
}
Expand Down Expand Up @@ -103,7 +104,10 @@ public function handle(array $params): ResponseInterface
$appStoreServerApi = $this->appStoreServerApiFactory->create($gatewayMode);

try {
$transactionHistory = $appStoreServerApi->getTransactionHistory($payload->transaction_id, ['sort' => 'DESCENDING']);
$transactionHistory = $appStoreServerApi->getTransactionHistory($payload->transaction_id, [
'sort' => GetTransactionHistoryQueryParams::SORT__DESCENDING,
'productType' => [GetTransactionHistoryQueryParams::PRODUCT_TYPE__AUTO_RENEWABLE]
]);
$transactionInfo = $transactionHistory->getTransactions()->current();
} catch (AppStoreServerAPIException $e) {
Debugger::log("Unable to get transaction info from App Store Server Api. Error: [{$e->getMessage()}]", Debugger::ERROR);
Expand Down

0 comments on commit 4558fce

Please sign in to comment.