承接 spezia/crypto-api-processor 相关项目开发

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

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

spezia/crypto-api-processor

最新稳定版本:1.1.2

Composer 安装命令:

composer require spezia/crypto-api-processor

包简介

This package is an unofficial integration of the BlockBee cryptocurrency payment gateway for Laravel applications.

README 文档

README

Introduction

This package is an unofficial integration of the Blockbee cryptocurrency payment gateway for Laravel applications.

This version of the package does not cover all Blockbee API endpoints. It supports only the most important features. To explore all API endpoints, refer to the Blockbee Documentation.

Installation

Use Composer to install the package.

composer require spezia/crypto-api-processor

If you don't use auto-discovery, add the CryptoApiProcessorServiceProvider to the providers list in config/app.php.

'providers' => [
    ...
    Spezia\CryptoApiProcessor\Providers\CryptoApiProcessorServiceProvider::class,
],

The package includes a configuration file. Publish it with the following command:

php artisan vendor:publish --tag=blockbee-config

To integrate Blockbee into a Laravel app, you need to open Blockbee account and fetch API key. Add this key to your .env file.

BLOCKBEE_API_KEY=example

Usage

use Spezia\CryptoApiProcessor\CryptoApiAdapter;

$blockBeeAdapter = new CryptoApiAdapter();

You can take advantage of helper methods via the included trait:

use Spezia\CryptoApiProcessor\Helpers\CryptoApiAdapterHelper;

Please open both files to see available methods.

Examples

Here are a couple of examples of how to use the CryptoApiAdapter. You can copy this code into your Laravel controller and test it.

<?php

namespace App\Http\Controllers;

use Spezia\CryptoApiProcessor\CryptoApiAdapter;
use Spezia\CryptoApiProcessor\Exceptions\CryptoApiProcessorException;
use Spezia\CryptoApiProcessor\Helpers\CryptoApiAdapterHelper;

class SampleController extends Controller
{
    use CryptoApiAdapterHelper;

    /**
     * Fetch info for LTC currency
     */
    public function info(CryptoApiAdapter $blockBeeAdapter)
    {
        $response = $blockBeeAdapter->getInfoByTicker('LTC');

        return response()->json($response);
    }

    /**
     * Fetch qr_code or payment_uri for payment
     */
    public function payin(CryptoApiAdapter $blockBeeAdapter)
    {
        $ticker   = 'LTC';
        $amount   =  0.5;
        $callback = 'https://example.com/callback/product/123';

        // fetch a new  wallet address instead of the real one, we will get a new unique address for every transaction
        $responseAddress = $blockBeeAdapter->getNewAddress($ticker, $callback);

        if (strtolower($responseAddress['status']) === config('blockbee.statuses.success')) {
            $response = $blockBeeAdapter->getQRCode($ticker, $responseAddress['address_in'], $amount);
        }

        return response()->json($response['payment_uri'] ?? 'Payment uri not found.');
    }

    public function payout(CryptoApiAdapter $blockBeeAdapter)
    {
        $ticker  = 'LTC';
        $address = 'receiver_wallet_address';
        $amount  = 0.001;

        try {
            $response = $blockBeeAdapter->processPayout($ticker, $address, $amount);

            if ($response['status'] === config('blockbee.statuses.success')) {
                while ($response['payout_info']['status'] === config('blockbee.statuses.processing')) {
                    $response = $blockBeeAdapter->statusPayout($response['payout_info']['id']);
                    sleep(30);
                }

                $msg = $response['payout_info']['status'] ===  config('blockbee.statuses.done') ? 'Update transaction status to done.' : 'Payment failed.';
                return response()->json($msg);
            }
        } catch (CryptoApiProcessorException $e) {
            return response()->json($e->getMessage());
        }

        return response()->json('Error.');
    }

    /**
     * Fetch fee for LTC currency for given blockbee account wallet address
     */
    public function fee(CryptoApiAdapter $blockBeeAdapter)
    {
        $ticker   = 'LTC';
        $response = $blockBeeAdapter->getBlockchainFee($ticker);

        return response()->json('Fee is ' . $response['estimated_cost'] ?? 'Not found.');
    }

    /**
     * Fetch fee for LTC currency using CryptoApiAdapterHelper
     */
    public function fiatFee()
    {
        $ticker   = 'LTC';
        $response = $this->estimatedBlockchainFiatFee($ticker, 'USD');

        return response()->json('USD fee is ' . $response);
    }

    /**
     * Check if the amount has exceeded the balance using CryptoApiAdapterHelper
     */
    public function validateAmount()
    {
        try {
            $ticker = 'LTC';
            $amount = 0.5;

            $response = $this->hasExceedBalance($amount, $ticker);

            return response()->json($response ? 'Amount exceeds balance.' : 'Amount is valid.');
        } catch (CryptoApiProcessorException $e) {
            return response()->json($e->getMessage());
        }
    }
}

Testing

./vendor/bin/phpunit

Contributing

Pull requests are welcome.

License

Crypto API Processor is released under the MIT License. See the MIT file for details.

统计信息

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

GitHub 信息

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

其他信息

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