calibr / ms-receipt-validator
Microsoft Store Receipt Validator
Installs: 8 749
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- robrichards/xmlseclibs: ^2.0
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is not auto-updated.
Last update: 2024-12-21 21:20:09 UTC
README
This library was created to easily validate Microsoft Store purchase receipts on the server side.
Installation
composer require calibr/ms-receipt-validator
Usage
Assume that client passes receipt to the server side and we receive it in the variable $_POST["receiptXML"]
, validation of the receipt will look like:
<?php use Calibr\MSReceiptValidator\Validator; $validator = new Validator(); // validation(omit exception handling) $receipt = $validator->load($_POST["receiptXML"]); // if we are here receipt has been successfully validated and we have all receipt data in the $receipt variable
Validator#load method
Validation is run by calling load
method on the Validator
class instance. This method takes only one argument - receipt XML string and returns Receipt.
Validator#setPublicKey method
If you want to set public key directly you need to pass the public key string to this method.
Receipt object format
Product receipt object format
App receipt object format
Error handling
Validator#load
method throws an exception if an error occurs. Possible exceptions:
Calibr\MSReceiptValidator\FailFetchPublicKeyException
- Microsoft server didn't respond or respond with an error, see details in the exception messageCalibr\MSReceiptValidator\MalformedReceiptException
- Receipt is invalid, see details in the exception messageCalibr\MSReceiptValidator\ValidationFailedException
- Receipt didn't pass signature verification process