定制 bulletdigitalsolutions/doctrine-cashier 二次开发

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

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

bulletdigitalsolutions/doctrine-cashier

最新稳定版本:v1.0.8

Composer 安装命令:

composer require bulletdigitalsolutions/doctrine-cashier

包简介

Enables you to use cashier on doctrine

README 文档

README

This package is in early development and not yet tested for production use.

Latest Version on Packagist Total Downloads GitHub Actions

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Installation

You can install the package via composer:

composer require bulletdigitalsolutions/doctrine-cashier

Usage

Your user entity should extend the BillableEntity class

/**
 * @ORM\Table()
 * @ORM\Entity
 * @Gedmo\Loggable(logEntryClass="App\Entities\Audit")
 */
class User extends BillableEntity

Your user entity must implement getRepository, which returns a repository that implement BillableEntityContract

public function getRepository()
{
    return app(UserContract::class);
}
class UserRepository extends CoreRepository implements UserContract
{
    use TwoFactorRepository, BillableRepository;

You should then extend the Subscription and SubscriptionItem entities

<?php

namespace App\Entities;

use BulletDigitalSolutions\DoctrineCashier\Contracts\UserSubscriptionContract;
use BulletDigitalSolutions\DoctrineCashier\Entities\UserSubscription as BaseSubscription;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Table
 * @ORM\Entity
 * @Gedmo\Loggable(logEntryClass="App\Entities\Audit")
 */
class Subscription extends BaseSubscription implements UserSubscriptionContract
{
    /**
     * @ORM\Column(type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(referencedColumnName="id")
     */
    protected $user;

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param  mixed  $id
     */
    public function setId($id): void
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * @param  mixed  $user
     */
    public function setUser($user): void
    {
        $this->user = $user;
    }
}
<?php

namespace App\Entities;

use BulletDigitalSolutions\DoctrineCashier\Contracts\UserSubscriptionItemContract;
use BulletDigitalSolutions\DoctrineCashier\Entities\UserSubscriptionItem as BaseSubscriptionItem;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Table
 * @ORM\Entity
 * @Gedmo\Loggable(logEntryClass="App\Entities\Audit")
 */
class SubscriptionItem extends BaseSubscriptionItem implements UserSubscriptionItemContract
{
    /**
     * @ORM\Column(type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Subscription", inversedBy="items")
     * @ORM\JoinColumn(referencedColumnName="id")
     */
    protected $subscription;

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param  mixed  $id
     */
    public function setId($id): void
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getSubscription()
    {
        return $this->subscription;
    }

    /**
     * @param  mixed  $subscription
     */
    public function setSubscription($subscription): void
    {
        $this->subscription = $subscription;
    }
}

You then need to register your entities on the CashierServiceProvider

<?php

namespace App\Providers;

use App\Entities\Subscription;
use App\Entities\SubscriptionItem;
use App\Entities\User;
use Illuminate\Support\ServiceProvider;
use BulletDigitalSolutions\DoctrineCashier\Cashier;

class CashierServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        Cashier::ignoreMigrations();
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        Cashier::useSubscriptionModel(Subscription::class);
        Cashier::useSubscriptionItemModel(SubscriptionItem::class);
        Cashier::useCustomerModel(User::class);
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email andrew@bulletdigitalsolutions.co.uk instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-15