PHPackages                             stafox/huawei-iap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. stafox/huawei-iap

ActiveLibrary[Payment Processing](/categories/payments)

stafox/huawei-iap
=================

Huawei In-App Purchase (IAP) verification library

1.0.0(5y ago)614.1k↓42.3%21MITPHPPHP &gt;=7.2

Since Nov 29Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Stafox/huawei-iap)[ Packagist](https://packagist.org/packages/stafox/huawei-iap)[ Docs](https://github.com/Stafox/huawei-iap)[ RSS](/packages/stafox-huawei-iap/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

Huawei IAP
==========

[](#huawei-iap)

[![Latest Stable Version](https://camo.githubusercontent.com/be9641e6e96ab48cc45f9b3965f2633a908bef8d8ec5a44cc972ee2e859454cf/68747470733a2f2f706f7365722e707567782e6f72672f737461666f782f6875617765692d6961702f76)](//packagist.org/packages/stafox/huawei-iap)[![Total Downloads](https://camo.githubusercontent.com/7aab3564e9a1980ed0f0092c55ffc36f8d32cadb984ef580790e58c51ede8d5e/68747470733a2f2f706f7365722e707567782e6f72672f737461666f782f6875617765692d6961702f646f776e6c6f616473)](//packagist.org/packages/stafox/huawei-iap)[![Build Status](https://camo.githubusercontent.com/c15d30934ea051570e4751f68db96165fed18a46ff3a92b62cf66b3a039e80a9/68747470733a2f2f7472617669732d63692e6f72672f737461666f782f6875617765692d6961702e706e673f6272616e63683d6d61696e)](https://travis-ci.org/stafox/huawei-iap)[![Code Coverage](https://camo.githubusercontent.com/33233707f7751f1f55565894b024bf3b4ac743ca381bd6ef68c2fd0e49531fe5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537461666f782f6875617765692d6961702f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/stafox/huawei-iap/?branch=main)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fe964602efd2e38063338df25bf1257fb8792243baa602ca105752d5de15cc55/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f737461666f782f6875617765692d6961702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/stafox/huawei-iap/?branch=main)[![License](https://camo.githubusercontent.com/2b8c99c3b64c8e58704618bd7debfef1783d84ea8b0f6e965547da3389fbcb5b/68747470733a2f2f706f7365722e707567782e6f72672f737461666f782f6875617765692d6961702f6c6963656e7365)](//packagist.org/packages/stafox/huawei-iap)

PHP library that can be used for verifying In-App Purchases for the Huawei's Order and Subscription services.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2
- ext-json
- ext-curl

Getting Started
---------------

[](#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.

If you're not familiar with Composer, please see .

1. Add `huawei-iap` to your application's composer.json.

    ```
     {
         ...
         "require": {
             "stafox/huawei-iap": "main"
         },
         ...
     }

    ```
2. Run `php composer install`.
3. If you haven't already, add the Composer autoload to your project's initialization file. (example)

    ```
     require 'vendor/autoload.php';

    ```

Quick Usage Examples
--------------------

[](#quick-usage-examples)

### Subscription validation

[](#subscription-validation)

```
use Huawei\IAP\AuthorizationCredentials;
use Huawei\IAP\Validator as HuaweiValidator;

$validator = new HuaweiValidator();

$appId = 123456789; // Your application ID
$appKey = 'XXXYYYZZZ'; // Your app key

$authCredentials = new AuthorizationCredentials($appId, $appKey);

$type = HuaweiValidator::TYPE_SUBSCRIPTION;
$subscriptionId = 'AAABBBCCC';
$productId = 'com.your.app.subscription';
$purchaseToken = 'purchaseTokenHere';

$purchaseData = new PurchaseData($type, $subscriptionId, $purchaseToken, $productId);

$subscriptionResponse = $validator->validate($authCredentials, $purchaseData);

$isSubscriptionValid = $subscriptionResponse->isSubValid();
$expirationDateMs = $subscriptionResponse->getExpirationDate();
```

### Order (one-time purchase) validation

[](#order-one-time-purchase-validation)

```
use Huawei\IAP\AuthorizationCredentials;
use Huawei\IAP\Validator as HuaweiValidator;

$validator = new HuaweiValidator();

$appId = 123456789; // Your application ID
$appKey = 'XXXYYYZZZ'; // Your app key

$authCredentials = new AuthorizationCredentials($appId, $appKey);

$type = HuaweiValidator::TYPE_ORDER;
$productId = 'com.your.app.subscription';
$purchaseToken = 'purchaseTokenHere';

$purchaseData = new PurchaseData($type, null, $purchaseToken, $productId);

$orderResponse = $validator->validate($authCredentials, $purchaseData);

$pruchaseKind = $orderResponse->getKind();
$orderId = $orderResponse->getOrderId();
$consumptionState = $orderResponse->getConsumptionState();
```

### Use custom AuthorizationStorage

[](#use-custom-authorizationstorage)

By default auth token stored in-memory. To reduce number of authorization requests you can extend AuthorizationStorage to store data for longer period of time.

For example:

```
use Huawei\IAP\AuthorizationStorage;
use Redis;

class RedisAuthorizationStorage extends AuthorizationStorage
{
    private $redisClient;

    public function __construct(Redis $redisClient)
    {
        $this->redisClient = $redisClient;
    }

    public function fetch(AuthorizationCredentials $credentials): ?string
    {
        $key = $this->transformCredentialsToKey($credentials);

        $at = $this->redisClient->get($key);
        return $at === false ? null : $at;
    }

    public function save(AuthorizationCredentials $credentials, string $accessToken): void
    {
        $key = $this->transformCredentialsToKey($credentials);

        $this->redisClient->set($key, $accessToken);
    }
}
```

And then pass it into Validator.

```
use Huawei\IAP\Validator as HuaweiValidator;

$redisAuthStorage = new RedisAuthorizationStorage($redisClient);

$validator = new HuaweiValidator();
$validator->setAuthorizationStorage($redisAuthStorage);
```

### Select store site

[](#select-store-site)

By default Germany store site will be used. It may be useful to use different store sites to reduce request time.

To do that you need to extend `Validator` and override

- `createSubscriptionVerificationRequest(PurchaseData $purchaseData)`
- `createOrderVerificationRequest(PurchaseData $purchaseData)`

And extend `PurchaseDate` to be able get country, for example.

Then pass needed country to `Validator::getClient()` method.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1996d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1101646?v=4)[Stan Kuryan](/maintainers/Stafox)[@Stafox](https://github.com/Stafox)

---

Top Contributors

[![Stafox](https://avatars.githubusercontent.com/u/1101646?v=4)](https://github.com/Stafox "Stafox (2 commits)")

---

Tags

storepurchasesubscriptionin appiaphuaweihms

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stafox-huawei-iap/health.svg)

```
[![Health](https://phpackages.com/badges/stafox-huawei-iap/health.svg)](https://phpackages.com/packages/stafox-huawei-iap)
```

###  Alternatives

[unicodeveloper/laravel-paystack

A Laravel Package for Paystack

650975.6k11](/packages/unicodeveloper-laravel-paystack)[yanlongli/app-store-server-api

PHP client for App Store Server API. Manage your customers’ App Store transactions from your server.The App Store Server API is a REST API that you call from your server to request and provide information about your customers' in-app purchases. The App Store signs the transaction and subscription renewal information that this API returns using the JSON Web Signature (JWS) specification.App Store Server API is independent of the app’s installation status on the customer’s devices. The App Store server returns information based on the customer’s in-app purchase history regardless of whether the customer installed, removed, or reinstalled the app on their devices.To request transaction and subscription status information with this API, provide any original transaction identifier that belongs to the customer. The transaction history API responds with a complete list of transactions, 20 at a time, starting with the oldest first. The subscription status API returns the status for all of the customer’s subscriptions, organized by their subscription group identifier.Use the Send Consumption Information endpoint to send information to the App Store when customers request a refund for a consumable in-app purchase, after you receive the CONSUMPTION\_REQUEST App Store server notification. Your data helps inform refund decisions.

2532.0k](/packages/yanlongli-app-store-server-api)[prevailexcel/laravel-nowpayments

A Laravel Package for NOWPayments

1414.2k](/packages/prevailexcel-laravel-nowpayments)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
