This file contains hidden or 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
{ | |
"name": "ESG Tracker", | |
"nodes": [ | |
{ | |
"parameters": { | |
"httpMethod": "POST", | |
"path": "esg-query", | |
"options": {} | |
}, | |
"type": "n8n-nodes-base.webhook", |
This file contains hidden or 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
from flask import Blueprint, request, jsonify | |
from flask_jwt_extended import jwt_required, get_jwt_identity | |
from datetime import datetime, timedelta | |
from sqlalchemy.exc import SQLAlchemyError | |
from app.extensions import db | |
from app.models import Loan, User, RepaymentSchedule, LoanProduct | |
from app.models.loan import LoanStatus | |
from app.models.loan_products import RepaymentFrequencies | |
from app.models.repaymentSchedule import RepaymentStatus |
This file contains hidden or 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
# LOANROUTE | |
from flask import Blueprint, request, jsonify | |
from flask_jwt_extended import jwt_required, get_jwt_identity | |
from datetime import datetime, timedelta | |
from sqlalchemy.exc import SQLAlchemyError | |
from app.extensions import db | |
from app.models import Loan, User, RepaymentSchedule, LoanProduct | |
from app.models.loan import LoanStatus | |
from app.models.loan_products import RepaymentFrequencies |
This file contains hidden or 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
# CLIENT.PY | |
import requests | |
from flask import current_app | |
from requests.auth import HTTPBasicAuth | |
import base64 | |
def get_access_token(): | |
""" | |
This func. helps generate an OAuth access token from Safaricom | |
M-Pesa API. The token is needed to authorize all other API requests (like STK Push). |
This file contains hidden or 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
from datetime import datetime | |
from pathlib import Path | |
import json | |
orders_path = Path(__file__).parent / "orders.json" | |
with open(orders_path, 'r',) as file: | |
orders_data = json.load(file) | |
# from order's note, extract affiliate_id and tracking product_id | |
def get_ids(note): |
This file contains hidden or 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
OBJECTIVE | |
Process order data and calculate commissions for affiliate partners based on their sales | |
- TASK1: Filters orders for a specific affiliate ID | |
- FROM orders_data -> [{order1}, {order2}, {order3}, {order4}, ....] | |
.SELECT each order, .STRIP affliate_id from order['notes'] | |
- TASK2: Matches line items with the tracked product ID | |
- .STRIP product_ID from order['notes'] | |
- .LOOP through an order line items and MATCH with product_ID | |
- .SET product_ID to filtered affliate_ID | |
- TASK3: Calculates total commission for that affiliate |