sarani/cryptopay 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sarani/cryptopay

Composer 安装命令:

composer require sarani/cryptopay

包简介

Multicurrency Crypto Payment. Pay with cryptocurrency whenever you want.

README 文档

README

cryptopay is a php library for Cryptocurrency Payment with support of accepting multiple cryptocurrencies. with this library you can add and support crypto payment to your sites, Apps and Telegram bot.

Get Start

To use this library, you need to create free Telegram account with CryptoBot.

Installation

Use the package manager composer to install sarani/cryptopay.

composer require sarani/cryptopay

Usage and Methods

// use Sarani\CryptoBot;

# init
$cryp_payment_token = 'token';
$mode = 'test'; // empty for real account 
$crypto = new Sarani\CryptoPay\Api($cryp_payment_token, 'test');

getMe

Use this method to test your app's authentication token. Requires no parameters. On success, returns basic information about an app.

$me = $crypto->getMe();

createInvoice

Use this method to create a new invoice. On success, returns an object of the created invoice.

  • asset (String) Currency code. Supported assets: “BTC”, “TON”, “ETH” (testnet only), “USDT”, “USDC” and “BUSD”.

  • amount (String)Amount of the invoice in float. For example: 125.50

  • description (String) Optional. Description for the invoice. User will see this description when they pay the invoice. Up to 1024 characters.

  • hidden_message (String) Optional. Text of the message that will be shown to a user after the invoice is paid. Up to 2o48 characters.

  • paid_btn_name (String) Optional. Name of the button that will be shown to a user after the invoice is paid. Supported names: viewItem – “View Item”, openChannel – “Open Channel”, openBot – “Open Bot”, callback – “Return”

  • paid_btn_url (String) Optional. Required if paid_btn_name is used. URL to be opened when the button is pressed. You can set any success link (for example, a link to your bot). Starts with https or http.

  • payload (String) Optional. Any data you want to attach to the invoice (for example, user ID, payment ID, ect). Up to 4kb.

  • allow_comments (Boolean) Optional. Allow a user to add a comment to the payment. Default is true.

  • allow_anonymous (Boolean) Optional. Allow a user to pay the invoice anonymously. Default is true.

  • expires_in (Number) Optional. You can set a payment time limit for the invoice in seconds. Values between 1-2678400 are accepted.

# create invoice, return Invoices object 
  $inv = $crypto->createInvoice($params = [
    'asset'   => 'USDT',
    'amount'  => '2.50',
    'payload' =>  '11158', # subscription id
    'allow_comments' => False,
    'allow_anonymous' => True,
    'paid_btn_name' => 'openBot',
    'paid_btn_url' => 'https://t.me/demobot',
    'hidden_message' => 'Thanks for your payment',
    'description' => 'Monthly Subscription'
  ]);
  echo $inv->id();
  echo $inv->url();

getInvoices

  • asset (String) Optional. Currency codes separated by comma. Supported assets: “BTC”, “TON”, “ETH” (testnet only), “USDT”, “USDC” and “BUSD”. Defaults to all assets.
  • invoice_ids (String) Optional. Invoice IDs separated by comma.
  • status (String) Optional. Status of invoices to be returned. Available statuses: “active” and “paid”. Defaults to all statuses.
  • offset (Number) Optional. Offset needed to return a specific subset of invoices. Default is 0.
  • count (Number) Optional. Number of invoices to be returned. Values between 1-1000 are accepted. Defaults to 100.
# get invoice, return array of Invoices object 
$res = $crypto->getInvoices($params = [
  'asset'  =>  'TON', // Crypto symbols
  'invoice_ids'   => '12600,12626,12745', // ids seperated by comma
]);

transfer

Use this method to send coins from your app's balance to a user. On success, returns object of completed transfer.

  • user_id (Number) Telegram user ID. User must have previously used CryptoBot(@CryptoTestnetBot for testnet).
  • asset (String) Currency code. Supported assets: “BTC”, “TON”, “ETH” (testnet only), “USDT”, “USDC” and “BUSD”.
  • amount (String) Amount of the transfer in float. The minimum and maximum amounts for each of the support asset roughly correspond to the limit of 0.01-25000 USD. Use getExchangeRates to convert amounts. For example: 125.50
  • spend_id (String) Unique ID to make your request idempotent and ensure that only one of the transfers with the same spend_id will be accepted by Crypto Pay API. This parameter is useful when the transfer should be retried (i.e. request timeout, connection reset, 500 HTTP status, etc). It can be some unique withdrawal identifier for example. Up to 64 symbols.
  • comment (String) Optional. Comment for the transfer. Users will see this comment when they receive a notification about the transfer. Up to 1024 symbols.
  • disable_send_notification (Boolean) Optional. Pass true if the user should not receive a notification about the transfer. Default is false.
# transfer to user, return Transfer object 
$transfer = $crypto->transfer($params = [
  'user_id'  =>  '1111111', // telegram user_id
  'asset'   => 'USDT', // Crypto
  'amount'  => '2.50', // amount
  'spend_id' =>  '1001', # reequest uniqe id to avoid double transfer
  'disable_send_notification'  =>  False,
  'comment' =>  'gift transfer'
]);

getBalance

Use this method to get a balance of your app. Returns array of assets.

getExchangeRates

Use this method to get exchange rates of supported currencies. Returns array of currencies.

getCurrencies

Use this method to get a list of supported currencies. Returns array of currencies.

Webhooks getUpdate

Use Webhooks to get updates for your app. Webhook request may be sent at least one time.

To make sure that the Webhook request was sent by Crypto Pay API, use a secret path in the URL, e.g. https://www.example.com/. Since nobody else knows your app's token, you can be pretty sure it's CryptoBot.

How to enable Webhooks? Open CryptoBot (@CryptoTestnetBot for testnet), go to Crypto Pay → My Apps, choose an app, open ‘Webhooks’ and tap ‘Enable Webhooks’. Then send HTTPS url used to receive updates.

# webhook, return Webhook object with Update and Invoice 
$hook = new Sarani\CryptoPay\Webhook();
$update = $hook->getUpdate(); // Update object
$nvoice =   $update->getPayload(); // Invoice Object
echo( $nvoice->status()); 

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Disclaimer

This project and its author is not associated with CryptoBot.

Financial Support

This Library is free for uses, But if you like it, any Supports are Wellcome.

You can support with this invoice or Join CryptoBot with affiliated link .

Or send directly:

  • TON: UQC09HtKpaK0prsE1X-V7cnk5JE_NrSy4bgTxVeCU8kfO1A6
  • BTC: 17sL8eapiCs1eeq2nRVAZozsn6ws9HCToP
  • BTC, TON, USDT, USDC, BUSD, BNB: Transfer with CryptoBot

License

This project is released under the MIT License License.

sarani/cryptopay 适用场景与选型建议

sarani/cryptopay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「crypto」 「cryptocurrency」 「telegram crypto payment」 「telegram bot payment」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sarani/cryptopay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sarani/cryptopay 我们能提供哪些服务?
定制开发 / 二次开发

基于 sarani/cryptopay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-29