https://github.com/calibr/ms-receipt-validator
Validate purchase receipts from Microsoft Store
https://github.com/calibr/ms-receipt-validator
Last synced: 5 months ago
JSON representation
Validate purchase receipts from Microsoft Store
- Host: GitHub
- URL: https://github.com/calibr/ms-receipt-validator
- Owner: calibr
- Created: 2016-12-18T20:40:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-12-20T13:46:39.000Z (over 9 years ago)
- Last Synced: 2025-08-20T00:24:01.611Z (10 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Why?
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
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](#receipt).
# Validator#setPublicKey method
If you want to set public key directly you need to pass the public key string to this method.
| Field |
|----------------|
| date |
| deviceId |
| [productReceipt](#product-receipt) |
| [appReceipt](#app-receipt) |
| publicKey |
| xmlDoc ([DOMDocument](http://php.net/manual/class.domdocument.php) created from XML string) |
## Product receipt object format
| Field |
|----------------|
| id |
| appId |
| productId |
| purchaseDate |
| productType |
| purchasePrice |
| expirationDate |
| Field |
|----------------|
| id |
| appId |
| purchaseDate |
| licenseType |
# 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 message
- `Calibr\MSReceiptValidator\MalformedReceiptException` - Receipt is invalid, see details in the exception message
- `Calibr\MSReceiptValidator\ValidationFailedException` - Receipt didn't pass signature verification process