承接 andisiahaan/digiflazz-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

andisiahaan/digiflazz-php

最新稳定版本:1.2.0

Composer 安装命令:

composer require andisiahaan/digiflazz-php

包简介

Modern PHP client for Digiflazz API - Prepaid, Postpaid, PLN, and more

README 文档

README

Packagist Version PHP Version License CI PHPStan Level

Modern PHP client for the Digiflazz API. Supports prepaid topup, postpaid bill payment, PLN inquiry, and more.

Requirements

  • PHP 8.1 or higher
  • ext-json
  • Guzzle 7.0+

Installation

composer require andisiahaan/digiflazz-php

Quick Start

use AndiSiahaan\Digiflazz\DigiflazzClient;

// Create client with credentials
$client = new DigiflazzClient('your_username', 'your_api_key');

// Check balance
$balance = $client->checkBalance();
print_r($balance);

// Or create from environment variables
$client = DigiflazzClient::fromEnvironment();

Configuration

Using Environment Variables

Set your credentials:

# Linux/macOS
export DIGIFLAZZ_USERNAME='your_username'
export DIGIFLAZZ_APIKEY='your_api_key'

# PowerShell
$env:DIGIFLAZZ_USERNAME='your_username'
$env:DIGIFLAZZ_APIKEY='your_api_key'

Then:

$client = DigiflazzClient::fromEnvironment();

Using Configuration Object

use AndiSiahaan\Digiflazz\Config\Configuration;

$config = new Configuration(
    username: 'your_username',
    apiKey: 'your_api_key',
    timeout: 30.0,
    verifySsl: true,
);

$client = new DigiflazzClient($config);

Usage

Check Balance

$balance = $client->checkBalance();
// or
$balance = $client->balance()->check();

Price List

// Prepaid products
$prepaid = $client->priceListPrepaid();

// Postpaid products
$postpaid = $client->priceListPasca();

// With filters
$filtered = $client->priceList()->prepaid([
    'category' => 'Pulsa',
    'brand' => 'TELKOMSEL',
]);

// Get all at once
$all = $client->priceList()->all();

Prepaid Transaction (Topup)

// Using array
$result = $client->topup([
    'buyer_sku_code' => 'xld10',
    'customer_no' => '087800001230',
    'ref_id' => 'unique-ref-123',
    'testing' => true, // Use sandbox
]);

// Using typed method
$result = $client->transaction()->topup(
    skuCode: 'xld10',
    customerNo: '087800001230',
    refId: 'unique-ref-123',
    testing: true,
);

// Generate unique ref_id
use AndiSiahaan\Digiflazz\Services\TransactionService;
$refId = TransactionService::generateRefId('TRX');

Postpaid Bill (Pascabayar)

// Step 1: Inquiry (check bill)
$inquiry = $client->inqPasca([
    'buyer_sku_code' => 'pln',
    'customer_no' => '530000000001',
    'ref_id' => 'ref-001',
    'testing' => true,
]);

// Step 2: Pay the bill
if ($inquiry['data']['status'] === 'Sukses') {
    $payment = $client->payPasca([
        'buyer_sku_code' => 'pln',
        'customer_no' => '530000000001',
        'ref_id' => 'ref-001',
        'testing' => true,
    ]);
}

// Check status
$status = $client->statusPasca([...]);

PLN Inquiry

// Quick inquiry
$pln = $client->inquiryPln('530000000001');

// Check if valid
$isValid = $client->pln()->isValidCustomer('530000000001');

Deposit Request

$deposit = $client->requestDeposit([
    'amount' => 1000000,
    'Bank' => 'BCA',
    'owner_name' => 'John Doe',
]);

// Or using typed method
$deposit = $client->deposit()->withdraw(1000000, 'BCA', 'John Doe');

Error Handling

The library throws specific exceptions for different error types:

use AndiSiahaan\Digiflazz\Exceptions\DigiflazzException;
use AndiSiahaan\Digiflazz\Exceptions\ApiException;
use AndiSiahaan\Digiflazz\Exceptions\HttpException;
use AndiSiahaan\Digiflazz\Exceptions\ValidationException;

try {
    $result = $client->topup([...]);
} catch (ValidationException $e) {
    // Missing or invalid parameters
    echo "Validation error: " . $e->getMessage();
    print_r($e->getErrors());
} catch (ApiException $e) {
    // API returned an error
    echo "API error: " . $e->getMessage();
    echo "Error code: " . $e->getErrorCode();
    
    if ($e->isInsufficientBalance()) {
        echo "Please top up your balance";
    }
    
    if ($e->isRetryable()) {
        // Safe to retry
    }
} catch (HttpException $e) {
    // Network or HTTP error
    echo "HTTP error: " . $e->getMessage();
    echo "Status code: " . $e->getStatusCode();
} catch (DigiflazzException $e) {
    // Base exception (catch all library exceptions)
    echo "Error: " . $e->getMessage();
}

Service Classes

Direct access to service classes for more control:

$balanceService = $client->balance();
$transactionService = $client->transaction();
$priceListService = $client->priceList();
$depositService = $client->deposit();
$plnService = $client->pln();

Development

Install Dependencies

composer install

Run Tests

# All tests
composer test

# With coverage
composer test:coverage

Static Analysis

composer analyse

Code Style

# Check code style
composer cs-check

# Fix code style
composer cs-fix

Architecture

src/
├── Config/
│   └── Configuration.php       # Immutable configuration
├── Contracts/
│   ├── ClientInterface.php     # Client contract
│   ├── HttpClientInterface.php # HTTP abstraction
│   └── ServiceInterface.php    # Service contract
├── Exceptions/
│   ├── DigiflazzException.php  # Base exception
│   ├── ApiException.php        # API errors
│   ├── AuthenticationException.php
│   ├── HttpException.php       # HTTP errors
│   └── ValidationException.php # Validation errors
├── Http/
│   └── GuzzleHttpClient.php    # Guzzle adapter
├── Services/
│   ├── Concerns/
│   │   └── ValidatesParameters.php
│   ├── AbstractService.php     # Base service
│   ├── BalanceService.php
│   ├── DepositService.php
│   ├── PlnService.php
│   ├── PriceListService.php
│   └── TransactionService.php
├── Support/
│   └── Signature.php           # Signature generator
└── DigiflazzClient.php         # Main client

Notes

  • IP Whitelist: Digiflazz requires your server IP to be whitelisted. Contact Digiflazz support.
  • Testing Mode: Use testing: true for sandbox transactions.
  • Credentials: Never commit credentials. Use environment variables or .env file.

License

MIT - see LICENSE file.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-15