raazpuspa / iap-validator
Composer package to validate in-app purchase receipts made to iTunes or Google through mobile apps.
Installs: 33
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=5.6 || ^7.0
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- illuminate/support: ^5.3
- phpunit/phpunit: ~5.0
- phpunit/phpunit-mock-objects: ~3.0
This package is not auto-updated.
Last update: 2024-04-14 01:23:53 UTC
README
iap-validator is a php composer package to validate in-app purchase receipts received from iTunes App Store. Also, this package provides easy access to all the information and details of purchase identified by provided receipt key.
iap-validator uses Guzzle Http Client in background to make Http request to the iTunes App Store server.
Requirement
- PHP >= 5.6
- Guzzle Http Client >= 6.3
Package will automatically install Guzzle Http Client for your convenience
Installation
We recommend you to install iap-validator through Composer. Move to https://getcomposer.org for detail instructions on installing and using composer or run the following command on your terminal.
curl -sS https://getcomposer.org/installer | php
Run Composer command to install iap-validator
composer require raazpuspa/iap-validator
If you have not linked your composer installer to your bin path, checkout to your directory consisting composer.phar and run composer with php.
php composer.phar require raazpuspa/iap-validator
For smooth running, you need to require Composer's autoloder:
require 'vendor/autoload.php'
To pull latest update of iap-validator use composer update:
composer update
OR
composer.phar update
Usage
Its too easy to use iap-validator. You just need to place single use
statement on your related file to include the package.
use RaazPuspa\IAPValidator\iTunes\IAPValidator;
Next, initialize an object of IAPValidator
class to access any provided
methods.
$iapValidator = new IAPValidator();
We extract your application's secured secret key used to make Http requests to
iTunes App Store from your .env
file. Set IAP_ITUNES_SECRET=<your secured secret key>
in your .env
file.
Two constant values are provided for easy selection of server endpoint.
const PRODUCTION_ENDPOINT = 'https://buy.itunes.apple.com/verifyReceipt'; const SANDBOX_ENDPOINT = 'https://sandbox.itunes.apple.com/verifyReceipt';
Example
# import validator class use RaazPuspa\IAPValidator\iTunes\IAPValidator; # initialize new validator class instance $iapValidator = new IAPValidator(); # Set server end-point for instance of IAPValidator class. # Choose one from the two provided end-point constants. Select production # end-point for live app while sandbox end-point during testing $iapValidator->setEndPoint($iapValidator::PRODUCTION_ENDPOINT); # Validates provided data and returns validation receipt. # @param $receiptData string base64 encoded purchase receipt from App Store # @param $endPoint string server end-point (optional, but is required if you # had not set it earlier) $response = $iapValidator->validateReceipt($receipt, $endPoint); # get validation status code $statusCode = $response->getStatusCode(); # If validated successfully, status code will be 0 (zero). On other scenario, # status codes represent as mentioned in official iTunes documentation.
iTunes Developer Documentation, list of status codes
# if validation is successful, you can get receipt information with following # method calls # get the status of validation $statusCode = $response->getStatusCode(); # get current app environment upon which validation is performed $environment = $response->getEnvironment(); # get just the receipt object $receipt = $response->getReceipt(); # get in-app product information $inApp = $response->getInApp(); # get latest receipt information $latestReceiptInfo = $response->getLatestReceiptInfo(); # get latest base64 encoded receipt string $latestReceipt = $response->getLatestReceipt(); # get pending renewal information if product is renewable/subscription based $pendingRenewalInfo = $response->getPendingRenewalInfo();