2017 © Pedro Peláez
 

library store-receipt-validator

PHP receipt validator for Apple iTunes, Google Play and Amazon App Store Edit

image

m6web/store-receipt-validator

PHP receipt validator for Apple iTunes, Google Play and Amazon App Store Edit

  • Monday, March 6, 2017
  • by M6Web
  • Repository
  • 25 Watchers
  • 0 Stars
  • 14,852 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 93 Forks
  • 0 Open issues
  • 23 Versions
  • 14 % Grown

The README.md

store-receipt-validator

Latest Stable Version Composer Downloads Build Status Code Coverage Scrutinizer Code Quality License, (*1)

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts., (*2)

Requirements

  • PHP >= 5.5

Getting Started

The easiest way to work with this package is when it's installed as a Composer package inside your project. Composer isn't strictly required, but makes life a lot easier., (*3)

If you're not familiar with Composer, please see http://getcomposer.org/., (*4)

  1. Add iap-validator to your application's composer.json., (*5)

    {
        ...
        "require": {
            "aporat/store-receipt-validator": "dev-master"
        },
        ...
    }
  2. Run php composer install., (*6)

  3. If you haven't already, add the Composer autoload to your project's initialization file. (example), (*7)

    require 'vendor/autoload.php';

Quick Example

iTunes


use ReceiptValidator\iTunes\Validator as iTunesValidator; $validator = new iTunesValidator(iTunesValidator::ENDPOINT_PRODUCTION); $receiptBase64Data = 'ewoJInNpZ25hdHVyZSIgPSAiQXBNVUJDODZBbHpOaWtWNVl0clpBTWlKUWJLOEVkZVhrNjNrV0JBWHpsQzhkWEd1anE0N1puSVlLb0ZFMW9OL0ZTOGNYbEZmcDlZWHQ5aU1CZEwyNTBsUlJtaU5HYnloaXRyeVlWQVFvcmkzMlc5YVIwVDhML2FZVkJkZlcrT3kvUXlQWkVtb05LeGhudDJXTlNVRG9VaFo4Wis0cFA3MHBlNWtVUWxiZElWaEFBQURWekNDQTFNd2dnSTdvQU1DQVFJQ0NHVVVrVTNaV0FTMU1BMEdDU3FHU0liM0RRRUJCUVVBTUg4eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUtEQXBCY0hCc1pTQ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qZ2lPd29KSW5CMWNtTm9ZWE5sTFdSaGRHVWlJRDBnSWpJd01USXRNRFF0TXpBZ01UVTZNRFU2TlRVZ1JYUmpMMGROVkNJN0Nna2ljSFZ5WTJoaGMyVXRaR0YwWlMxd2MzUWlJRDBnSWpJd01USXRNRFF0TXpBZ01EZzZNRFU2TlRVZ1FXMWxjbWxqWVM5TWIzTmZRVzVuWld4bGN5STdDZ2tpYjNKcFoybHVZV3d0Y0hWeVkyaGhjMlV0WkdGMFpTSWdQU0FpTWpBeE1pMHdOQzB6TUNBeE5Ub3dOVG8xTlNCRmRHTXZSMDFVSWpzS2ZRPT0iOwoJImVudmlyb25tZW50IiA9ICJTYW5kYm94IjsKCSJwb2QiID0gIjEwMCI7Cgkic2lnbmluZy1zdGF0dXMiID0gIjAiOwp9'; try { $response = $validator->setReceiptData($receiptBase64Data)->validate(); } catch (Exception $e) { echo 'got error = ' . $e->getMessage() . PHP_EOL; } if ($response->isValid()) { echo 'Receipt is valid.' . PHP_EOL; echo 'Receipt data = ' . print_r($response->getReceipt()) . PHP_EOL; } else { echo 'Receipt is not valid.' . PHP_EOL; echo 'Receipt result code = ' . $response->getResultCode() . PHP_EOL; }

Play Store

Get the refresh token from OAuth2 flow., (*8)

use ReceiptValidator\GooglePlay\Validator as PlayValidator;

$client = new \Google_Client();
$client->setApplicationName('...');
$client->setAuthConfig('...');
$client->setScopes('...');

$validator = new PlayValidator(new \Google_Service_AndroidPublisher($client));

try {
  $response = $validator->setPackageName('PACKAGE_NAME')
    ->setProductId('PRODUCT_ID')
    ->setPurchaseToken('PURCHASE_TOKEN')
    ->validatePurchase();
} catch (Exception $e){
  var_dump($e->getMessage());
  // example message: Error calling GET ....: (404) Product not found for this application.
}
// success

Or Using a service account, (*9)

Create service account Service Account flow, (*10)

use ReceiptValidator\GooglePlay\ServiceAccountValidator as PlayValidator;
$validator = new PlayValidator([
    'client_email' => 'xxxxxx@developer.gserviceaccount.com',
    'p12_key_path' => 'MyProject.p12',
]);

try {
  $response = $validator->setPackageName('PACKAGE_NAME')
    ->setProductId('PRODUCT_ID')
    ->setPurchaseToken('PURCHASE_TOKEN')
    ->validate();
} catch (Exception $e){
  var_dump($e->getMessage());
  // example message: Error calling GET ....: (404) Product not found for this application.
}
// success

Amazon App Store

use ReceiptValidator\Amazon\Validator as AmazonValidator;
use ReceiptValidator\Amazon\Response as ValidatorResponse;

$validator = new AmazonValidator;

$response = null;
try {
  $response = $validator->setDeveloperSecret("DEVELOPER_SECRET")->setReceiptId("RECEIPT_ID")->setUserId("USER_ID")->validate();

} catch (Exception $e) {
  echo 'got error = ' . $e->getMessage() . PHP_EOL;
}

if ($response instanceof ValidatorResponse && $response->isValid()) {

  echo 'Receipt is valid.' . PHP_EOL;


  foreach ($response->getPurchases() as $purchase) {
    echo 'getProductId: ' . $purchase->getProductId() . PHP_EOL;

    if ($purchase->getPurchaseDate() != null) {
      echo 'getPurchaseDate: ' . $purchase->getPurchaseDate()->toIso8601String() . PHP_EOL;
    }
  }
} else {
  echo 'Receipt is not valid.' . PHP_EOL;
  echo 'Receipt result code = ' . $response->getResultCode() . PHP_EOL;
}

The Versions

06/03 2017

dev-master

9999999-dev https://github.com/aporat/store-receipt-validator

PHP receipt validator for Apple iTunes, Google Play and Amazon App Store Edit

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

06/03 2017

2.0.0

2.0.0.0 https://github.com/aporat/store-receipt-validator

PHP receipt validator for Apple iTunes, Google Play and Amazon App Store Edit

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

15/12 2016

1.5.0

1.5.0.0 https://github.com/stanimir-kukudov/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

11/05 2016

1.4.1

1.4.1.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

28/04 2016

1.4.0

1.4.0.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

24/03 2016

1.3.1

1.3.1.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

21/12 2015

1.3.0

1.3.0.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

20/11 2015

1.2.1

1.2.1.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

15/10 2015

1.2.0

1.2.0.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

17/09 2015

1.1.1

1.1.1.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

19/04 2015

1.1.0

1.1.0.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

03/03 2015

1.0.13

1.0.13.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

26/02 2015

1.0.12

1.0.12.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

25/02 2015

1.0.11

1.0.11.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

04/02 2015

1.0.10

1.0.10.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

30/01 2015

1.0.9

1.0.9.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

09/12 2014

1.0.8

1.0.8.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

21/11 2014

1.0.7

1.0.7.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

31/10 2014

1.0.6

1.0.6.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

13/08 2014

1.0.5

1.0.5.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

13/08 2014

1.0.4

1.0.4.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

08/08 2014

1.0.2

1.0.2.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app

08/08 2014

1.0.0

1.0.0.0 https://github.com/aporat/store-receipt-validator

PHP library that can be used to validate base64 encoded iTunes in app purchase receipts.

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

purchase apple receipt itunes in app