myckhel/laravel-iaphub

IAPHUB APIs in laravel

v0.2.1 2024-05-12 08:29 UTC

This package is auto-updated.

Last update: 2024-11-12 09:43:35 UTC


README

Latest Version on Packagist Software License Travis Total Downloads

Iaphub Doc Link

Install

Via Composer

composer require myckhel/laravel-iaphub

Setup

The package will automatically register a service provider.

You need to publish the configuration file:

php artisan vendor:publish --provider="Myckhel\Iaphub\IaphubServiceProvider"

This is the default content of the config file iaphub.php:

<?php
  return [
    "api_key"          => env("IAPHUB_API_KEY"),
    "app_id"           => env("IAPHUB_APP_ID"),
    "env"              => env("IAPHUB_APP_ENV"),
    "hook_token"       => env("IAPHUB_HOOK_TOKEN"),
    // this middleware will be used for IAPHUB routes
    "route_middleware" => 'iaphub_disabled', // comma separated values e.g 'auth:api,auth:web'
  ];

Update Your Projects .env with:

IAPHUB_API_KEY=XXXXXXXXXXXXXXXXX
IAPHUB_APP_ID=XXXXXXXXXXXXXXXXX
IAPHUB_HOOK_TOKEN=XXXXXXXXXXXXXXXXX
IAPHUB_APP_ENV=development

Run the database migration

php artisan migrate

Available Api's

<?php
use Iaphub;

Iaphub::getUser($userId, $params);
Iaphub::postUser($userId, $params);
Iaphub::postUserPricing($userId, $params);
Iaphub::postUserReceipt($userId, $params);
Iaphub::postUserPurchases($userId, $params);
Iaphub::getPurchase($purchaseId, $params);
Iaphub::getReceipt($receiptId, $params);

API Usage Example

<?php

namespace Myckhel\Iaphub\Http\Controllers;

use Illuminate\Routing\Controller;
use Myckhel\Iaphub\Http\Requests\IaphubRequest;
use Illuminate\Http\Request;
use Iaphub;

class IaphubController extends Controller
{
  public function getUser(IaphubRequest $request, $id){
    return Iaphub::getUser($id, $request->all());
  }
}

Middleware

IAPHUB provided 2 middlewares

iaphub_hook_token

For authenticating iaphub hook request

Example:

<?php
Route::any('iaphub/hooks',  [SubscriptionController::class, 'hooks'])->middleware('iaphub_hook_token');

iaphub_disabled

For disabling route request returns 403 response

Example:

<?php
Route::any('iaphub/hooks',  [SubscriptionController::class, 'hooks'])->middleware('iaphub_disabled');
/* returns {
    "message": "This Endpoint Is Disabled \n enable it by replacing the 'iaphub_disabled' middleware from your config",
  }
*/

Todos

  • coming soon

Testing

Run the tests with:

vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

Security

If you discover any security-related issues, please email myckhel1@hotmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.