Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mkurc1/walletbundle

The bundle added walet into Users. Bundle for Symfony.
https://github.com/mkurc1/walletbundle

Last synced: about 1 month ago
JSON representation

The bundle added walet into Users. Bundle for Symfony.

Awesome Lists containing this project

README

        

# WalletBundle

The bundle added wallet into Users and allow to managed it. This bundle is for [Symfony](http://symfony.com/) Framework.

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/2e67737a-4442-4ea7-aff5-f22140427c45/big.png)](https://insight.sensiolabs.com/projects/2e67737a-4442-4ea7-aff5-f22140427c45)

## Configure

Require the bundle with composer:

$ composer require mkurc1/wallet-bundle

Enable the bundle in the kernel:

wallet;
}

/**
* @param WalletInterface $wallet
* @return User
*/
public function setWallet($wallet)
{
$this->wallet = $wallet;
return $this;
}

public function __construct()
{
parent::__construct($type);
$this->wallet = new Wallet();
// your own logic
}
}

Configure your application:

# app/config/config.yml
wallet:
classes:
wallet: AppBundle\Entity\Wallet # your wallet class
wallet_history: AppBundle\Entity\WalletHistory # your wallet history class

Update your database schema:

$ php app/console doctrine:schema:update --force

Usages:

container->get('doctrine.orm.entity_manager');
$userRepository = $entityManager->getRepository('AppBundle:User');
$transaction = $this->container->get('wallet.transaction');

// add money to user account
$user = $userRepository->findOneByName('foo');
$amount = 199;
$transactionName = 'Bonus for your activity'
$transaction->addMoney($user, $amount, $transactionName);

// subtract money from user account
$user = $userRepository->findOneByName('foo');
$amount = 400;
$transactionName = 'Payment for subscription'
$transaction->subMoney($user, $amount, $transactionName);
// if account don't have enough money, method throw exception WalletBundle\Exception\NotEnoughMoneyException

// freeze money on user account (account don't need to have enough money to freeze it)
$user = $userRepository->findOneByName('foo');
$amount = 50;
$transactionName = 'Reclamation'
$transaction->freezeMoney($user, $amount, $transactionName);

// move freeze money to another user account
$fromUser = $userRepository->findOneByName('foo');
$toUser = $userRepository->findOneByName('bar');
$amount = 50;
$transactionName = 'Refund'
$transaction->moveFreezeMoneyToUser($fromUser, $toUser, $amount, $transactionName);
// if account don't have enough freeze money in wallet, method throw exception WalletBundle\Exception\NotEnoughMoneyException

You now can use your wallet system!

## License

The bundle is released under the [MIT License](LICENSE).