-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
170 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.utils.translation import gettext as _ | ||
|
||
from bluebottle.fsm.effects import Effect | ||
from bluebottle.funding_lipisha.utils import generate_payout_account, generate_mpesa_account | ||
|
||
|
||
class GenerateLipishaAccountsEffect(Effect): | ||
conditions = [] | ||
title = _('Generate Lipisha accounts') | ||
template = 'admin/generate_lipisha_accounts_effect.html' | ||
|
||
def post_save(self, **kwargs): | ||
account = self.instance | ||
if not self.instance.mpesa_code: | ||
self.instance.mpesa_code = generate_mpesa_account( | ||
name=account.account_name | ||
) | ||
self.instance.save() | ||
if not self.instance.payout_code: | ||
self.instance.payout_code = generate_payout_account( | ||
name=account.account_name, | ||
number=account.account_number, | ||
bank_name=account.bank_name, | ||
bank_branch=account.branch_name, | ||
bank_address=account.address, | ||
swift_code=account.swift | ||
) | ||
self.instance.save() | ||
|
||
def __str__(self): | ||
return _('Generate Lipisha accounts to receive a MPESA code.') |
47 changes: 47 additions & 0 deletions
47
bluebottle/funding_lipisha/migrations/0009_auto_20220901_1328.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 2.2.24 on 2022-09-01 11:28 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('funding_lipisha', '0008_lipishabankaccount_mpesa_code'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='lipishapayment', | ||
options={'base_manager_name': 'objects'}, | ||
), | ||
migrations.AddField( | ||
model_name='lipishabankaccount', | ||
name='payout_code', | ||
field=models.CharField(blank=True, help_text='Generated by magic', max_length=50, null=True, unique=True, verbose_name='MPESA code'), | ||
), | ||
migrations.AlterField( | ||
model_name='lipishabankaccount', | ||
name='mpesa_code', | ||
field=models.CharField(blank=True, help_text='Generated by magic', max_length=50, null=True, unique=True, verbose_name='MPESA code'), | ||
), | ||
migrations.AlterField( | ||
model_name='lipishabankaccount', | ||
name='swift', | ||
field=models.CharField(blank=True, max_length=50, null=True, verbose_name='SWIFT/Routing Code'), | ||
), | ||
migrations.AlterField( | ||
model_name='lipishapayment', | ||
name='method', | ||
field=models.CharField(default='Paybill (M-Pesa)', max_length=30), | ||
), | ||
migrations.AlterField( | ||
model_name='lipishapaymentprovider', | ||
name='paybill', | ||
field=models.CharField(help_text='Find this at https://app.lypa.io/payment under `Business Number`', max_length=10, verbose_name='Business Number'), | ||
), | ||
migrations.AlterField( | ||
model_name='lipishapaymentprovider', | ||
name='prefix', | ||
field=models.CharField(default='goodup', max_length=100), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
bluebottle/funding_lipisha/templates/admin/generate_lipisha_accounts_effect.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% load i18n %} | ||
<h3>{% trans "Generate Lipisha Accounts" %}</h3> | ||
|
||
<p> | ||
{% trans "Generate Lipisha accounts for" %} | ||
"{{effects.0.instance}}" | ||
{% if effects|length > 1 %} | ||
{% blocktrans with extra=effects|length|add:"-1" %} | ||
and {{ extra }} other campaigns | ||
{% endblocktrans %} | ||
{% endif %} | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from bluebottle.funding_lipisha.effects import GenerateLipishaAccountsEffect | ||
from bluebottle.funding_lipisha.tests.factories import LipishaBankAccountFactory | ||
from bluebottle.test.utils import TriggerTestCase | ||
|
||
|
||
class LipishaAccountTriggerTests(TriggerTestCase): | ||
|
||
factory = LipishaBankAccountFactory | ||
defaults = {} | ||
|
||
def test_verify(self): | ||
self.create() | ||
self.model.states.verify() | ||
|
||
with self.execute(): | ||
self.assertEqual(self.model.status, 'verified') | ||
self.assertEffect(GenerateLipishaAccountsEffect) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from bluebottle.activities.triggers import ActivityTriggers | ||
from bluebottle.fsm.triggers import ( | ||
TransitionTrigger, register | ||
) | ||
from bluebottle.funding_lipisha.effects import GenerateLipishaAccountsEffect | ||
from bluebottle.funding_lipisha.models import LipishaBankAccount | ||
from bluebottle.funding_lipisha.states import LipishaBankAccountStateMachine | ||
|
||
|
||
@register(LipishaBankAccount) | ||
class LipishaBankAccountTriggers(ActivityTriggers): | ||
triggers = ActivityTriggers.triggers + [ | ||
|
||
TransitionTrigger( | ||
LipishaBankAccountStateMachine.verify, | ||
effects=[ | ||
GenerateLipishaAccountsEffect | ||
] | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters