定制 sjaakp/yii2-donate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sjaakp/yii2-donate

Composer 安装命令:

composer require sjaakp/yii2-donate

包简介

Donate form for Yii2, uses Mollie.

README 文档

README

Donation widget for Yii2

Latest Stable Version Total Downloads License

Yii2-donate is a module for the Yii 2.0 PHP Framework to handle donations. It makes use of the payment service provider Mollie, which is mainly active in Western European countries.

Yii2-donate sports a widget, which can be placed on any page (or even all pages).

Basic functionality

If a visitor selects an amount and presses the 'Donate'-button, she is transfered to a Mollie payment page. If she successfully completes the payment, she is redirected to the site's donate/thanks page, where she is rewarded with a joyful shower of confetti. If the visitor did supply an email address, she receives a 'Thank you' mail. The 'thanks' page also sports a button to resume her visit to the site.

If the visitor cancels the payment, she is redirected to the site's donate/cancel page, from where she can resume her surfing.

At any time, the site's administrator can get an overview of granted donations on the donate page.

Prerequisites

You'll need a Mollie account. It's free, but depending on your country, you may need a valid registration as a (small) business. You'll get two API keys, one for testing purposes and one for the real work. One of the API keys is used tot initialize the module.

It is strongly advised that the app uses Pretty URLs.

Because Yii2-donate may send emails, the mailer component of the application has to be up and running. Be sure that the 'adminEmail' parameter of the application has a sensible value. If you prefer, you may set the 'supportEmail' parameter as well; if set, Yii2-donate will use this.

Installation

Install Yii2-donate in the usual way with Composer. Add the following to the require section of your composer.json file:

"sjaakp/yii2-donate": "*"

or run:

composer require sjaakp/yii2-donate

You can manually install yii2-comus by downloading the source in ZIP-format.

Module

Yii2-donate is a module in the Yii2 framework. It has to be configured in the main configuration file, usually called web.php or main.php in the config directory. Add the following to the configuration array:

<?php
// ...
'modules' => [
    'donate' => [
        'class' => sjaakp\donate\Module::class,
        // several options
    ],
],
// ...

The module has to be bootstrapped. Do this by adding the following to the application configuration array:

<php
// ...
'bootstrap' => [
    'donate',
]
// ...

There probably already is a bootstrap property in your configuration file; just add 'donate' to it.

Important: the module should also be set up in the same way in the console configuration (usually called console.php).

Console command

To complete the installation, a console command have to be run. This will create a database table for the donations:

yii migrate

The migration applied is called sjaakp\donate\migrations\m000000_000000_init.

The Donate widget

Placing the Donate widget in any view is trivial:

<?php
use sjaakp\donate\DonateWidget;
?>
...
<?= DonateWidget::widget() ?>
...

The small, collapsed variant is obtained by:

<?php
use sjaakp\donate\DonateWidget;
?>
...
<?= DonateWidget::widget([
    'small' => true
]) ?>
...

Module options

The Donate module has a range of options. They are set in the application configuration like so:

 <?php
 // ...
 'modules' => [
     'donate' => [
         'class' => sjaakp\donate\Module::class,
         'description' => 'Please, buy me a drink!',
         // ...
         // ... more options ...
     ],
 ],
 // ...

The options (most are optional) are:

  • mollieApiKey string One of the API keys obtained from Mollie. Not optional, must be set.
  • choices array Amounts to select from. Keys are integers representing the amounts in cents, values are textual representations. Example: [ ..., 250 => '€2,50', 500 => '€5', ... ]. Defaults: amounts of 5, 10, 25, 50, and 100.
  • header string|null Text header appearing in the donate-widget. If null (default) no header is rendered.
  • includeMessage bool Whether a 'friendly message' field is included in the widget. Default: true.
  • confetti bool Whether confetti is shown on the 'thanks' page. Default: true.
  • description string|null The textual description displayed on Mollie's payment page. If null (default), defaults to 'Donation for <site name>'.
  • locale string|null The locale sent to the payment site. If null, defaults to site's language property.
  • mailOptions array Options for the app mailer. Default: see source.
  • localTest bool|null If true, performs a dummy-payment on the local system, useful for debugging and testing. If null (default), localTest is set to true if YII_ENV === 'dev', in other words if the site is in the development environment.
  • indexAccess array The access rule for the donations overview (donate page). Default: only accessible to authenticated visitors ([ 'allow' => true, 'roles' => ['@'] ]). For most sites, you'll want to refine this.

Internationalization

All of Yii2-donate's utterances are translatable. The translations are in the 'sjaakp\donate\messages' directory.

You can override Yii2-donate's translations by setting the application's message source in the main configuration, like so:

 <?php
 // ...
 'components' => [
     // ... other components ...     
     'i18n' => [
          'translations' => [
               // ... other translations ...
              'donate' => [    // override donate's standard messages
                  'class' => yii\i18n\PhpMessageSource::class,
                  'basePath' => '@app/messages',  // this is a default
                  'sourceLanguage' => 'en-US',    // this as well
              ],
          ],
     ],
     // ... still more components ...
 ]

The translations should be in a file called 'donate.php'.

If you want a single or only a few messages translated and use Yii2-donate's translations for the main part, the trick is to set up 'i18n' like above and write your translation file something like:

  <?php
  // app/messages/nl/donate.php
  
  $donateMessages = Yii::getAlias('@sjaakp/donate/messages/nl/donate.php');
  
  return array_merge (require($donateMessages), [
     'Amount' => 'Bedrag in euro',   // your preferred translation
  ]);

At the moment, the only language implemented is Dutch. Agreed, it's only the world's 52th language, but it happens to be my native tongue. Please, feel invited to translate Yii2-donate in other languages. I'll be more than glad to include them into Yii2-donate's next release.

Module ID

By default, the Module ID is 'donate'. It is set in the module configuration. If necessary (for instance if there is a conflict with another module or application component), you may set the Module ID to something different. Important: in that case, the moduleId property of the Donate widget must be set to this new value as well.

FAQ

Can I change the layout for the Yii2-donate views?

  • Use the EVENT_BEFORE_ACTION event. One easy way is to incorporate it in the module setup, like so:

    <?php
    // ...
    'modules' => [
       'donate' => [
           'class' => sjaakp\donate\Module::class,
           'description' => 'Please, buy me a drink!',
           'on beforeAction' => function ($event) {
               $event->sender->layout = '@app/views/layouts/one_column';
           },
           // ... more options ...
       ],
    ],
    // ...
    

sjaakp/yii2-donate 适用场景与选型建议

sjaakp/yii2-donate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 sjaakp/yii2-donate 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-05