clem/stancer-fork
Composer 安装命令:
composer require clem/stancer-fork
包简介
Stancer PHP library
README 文档
README
Requirement
We only support current PHP version, so this library needs at least PHP 8.1.
Installation
To keep it simple, we uses Composer. You only need to run the following commmand :
composer require stancer/stancer
The library uses cURL internaly to connect to the API.
You need the php extension phpX.Y-curl, where X.Y correspond to your PHP version, to be installed on your server.
You may also use Guzzle or every PSR7 compatible client to replace the internal cURL instance. You only need to provider the client instance to the API config.
<?php $config = Stancer\Config::init($key); $config->setHttpClient($guzzle);
Usage
All you need is a valid API key.
<?php $key = 'my_api_key_kSp7hBH3hyDQ36izsyKR'; Stancer\Config::init($key); $card = new Stancer\Card(); $card->setNumber('4111111111111111'); $card->setExpMonth(12); $card->setExpYear(2022); $card->setCvc('999'); $card->setName('John Doe'); $payment = new Stancer\Payment(); $payment->setCard($card); $payment->setAmount(1000); // You must put an integer, here we wanted USD$10.00 $payment->setCurrency('USD'); $payment->description('My first payment'); $payment->send();
Retrieve an object
To retrieve an object, just put an identifier when creating a new instance.
<?php $payment = new Stancer\Payment('paym_KIVaaHi7G8QAYMQpQOYBrUQE');
Creating an object
To create an object, like a payment, use the send method.
<?php $payment = new Stancer\Payment(); $payment->setCard($card); // Pay with a card // or $payment->setSepa($sepa); // Pay with a bank account (SEPA, uses BIC and IBAN) // Do not forget to complete your payment informations $payment->send();
Refund a payment
The easiest way to do it, use Payment::refund() method.
There is a simple example :
<?php $payment = new Stancer\Payment('paym_KIVaaHi7G8QAYMQpQOYBrUQE'); $payment->refund(); // To refund the full payment // or $payment->refund($amount); // To refund a particular amount $payment->getRefunds(); // Will return all refunds made on a payment
Exceptions
Every exceptions thrown by this project extend from Stancer\Exceptions\Exception.
Some exceptions are related to the connection with the API :
Stancer\Exceptions\TooManyRedirectsExceptionon 310 HTTP errorsStancer\Exceptions\BadRequestExceptionon 400 HTTP errorsStancer\Exceptions\NotAuthorizedExceptionon 401 HTTP errors (basically bad credential)Stancer\Exceptions\NotFoundExceptionon 404 HTTP errorsStancer\Exceptions\ConflictExceptionon 409 HTTP errors
Or with less specificity :
Stancer\Exceptions\RedirectionExceptionon 3** HTTP errors (technically only Too many redirection)Stancer\Exceptions\ClientExceptionon 4** HTTP errorsStancer\Exceptions\ServerExceptionon 5** HTTP errors
You can see other exceptions, not related to HTTP traffic :
Stancer\Exceptions\BadMethodCallExceptionwhen you are calling an unknown methodStancer\Exceptions\InvalidArgumentExceptionwhen you are using a method without the right arguments
For these two exceptions, you need to check you code, they should never appear in real world.
To see every available exceptions, simply take a look in src/Exceptions folder.
Logger
You can add a PSR3 compatible logger.
We suggeset monolog but anything implementing log interfaces can be use.
<?php $log = new Monolog\Logger('Stancer'); $log->pushHandler(new Monolog\Handler\StreamHandler('path/to/your.log', Monolog\Logger::INFO)); $config->setLogger($logger);
Security
-
Never, never, NEVER register a card or a bank account number in your database.
-
Always uses HTTPS in card/SEPA in communication.
-
Our API will never give you a complete card/SEPA number, only the last four digits. If you need to keep track, use these last four digit.
Contribute
We can contribute and modify everything, you just need to follow some rules :
- Fork the project
- Make a topic branch (aka one branch for one feature or one bug)
- Test locally
- Complete the
Unreleasedpart of the changelog - Make a merge/pull request
Every MR/PR MUST have unit test and CHANGELOG entries to be approved.
Our unit testing framework is atoum. It is fast and easy to learn. Go see the documentation.
clem/stancer-fork 适用场景与选型建议
clem/stancer-fork 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 191 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payments」 「card」 「sepa」 「payment solution」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 clem/stancer-fork 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 clem/stancer-fork 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 clem/stancer-fork 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Creates an XML file for a Single Euro Payments Area (SEPA) Credit Transfer.
Simple classes for creating SEPA transfer and direct debit xml files. No dependencies
This package parses and validates International Bank Account Number (IBAN).
Creates an XML file for a Single Euro Payments Area (SEPA) Credit Transfer.
Settings Card for Laravel Nova.
Multishipping support for the Mollie Payment Module for Magento 2
统计信息
- 总下载量: 191
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-07