Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/mkurc1/walletbundle
- Owner: mkurc1
- License: mit
- Created: 2016-06-22T10:57:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-13T13:30:30.000Z (over 7 years ago)
- Last Synced: 2024-10-01T15:27:04.113Z (about 2 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 5
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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!
## LicenseThe bundle is released under the [MIT License](LICENSE).