def test_charge(self): with mock.patch('paystackapi.transaction.Transaction.charge') as \ mock_charge: mock_charge.return_value = { 'status': True } response = Transaction.charge( 'getupall', 'authorization_code' 'email', 'amount') self.assertTrue(response['status'])
def test_charge(self): httpretty.register_uri( httpretty.POST, "https://api.paystack.co/transaction/charge_authorization", content_type='text/json', body='{"status": true, "contributors": true}', status=201, ) response = Transaction.charge( reference='getupall', authorization_code='authorization_code', email='email', amount='amount') self.assertTrue(response['status'])
def test_charge(self): httpretty.register_uri( httpretty.POST, "https://api.paystack.co/transaction/charge_authorization", content_type='text/json', body='{"status": true, "contributors": true}', status=201, ) response = Transaction.charge(reference='getupall', authorization_code='authorization_code', email='email', amount='amount') self.assertTrue(response['status'])
def demo_task(message): users = User.objects.all() has_subscription = False for user in users: #get active subscription try: active = Subscription.objects.get(user=user.id, is_active=True, has_expired=False) if active: start_date = active.start_date from datetime import datetime diff = datetime.now().date() - start_date date_diff = diff.days if active.package_subscribed is 4: if date_diff >= 15: active.has_expired = True is_active = False active.save() else: has_subscription = True elif active.package_subscribed is not 4: if date_diff >= 30: active.has_expired = True is_active = False active.save() else: has_subscription = True except Subscription.DoesNotExist: pass if not has_subscription: latest_plan = Subscription.objects.filter( user=user.id).order_by('-id')[:1] package = None for plan in latest_plan: package = plan.package_subscribed #Get users card users_card = Card.objects.filter(user=user.id) for card in users_card: from paystackapi.transaction import Transaction import uuid reference = get_random_string(length=20) print(reference) response = Transaction.charge( reference=reference, authorization_code=card.card_auth, email=card.card_email, amount=int(package.amount) * 100) print(response) if response['status'] == True and response['data'][ 'status'] != 'failed': subscription = Subscription(user=user, is_active=True, package_subscribed=package, has_expired=False) subscription.save() break