(20250102) Safaricom M-Pesa work.
This commit is contained in:
@@ -199,16 +199,30 @@ class SafaricomMPesaExpressPaymentsController(PaymentsController):
|
||||
)
|
||||
|
||||
# Initialize the third-party client:
|
||||
client_auth = MPesaExpressAuthorization(
|
||||
consumerKey = auth_token.auth["consumerKey"],
|
||||
consumerSecret = auth_token.auth["consumerSecret"],
|
||||
businessShortCode = auth_token.auth["businessShortCode"],
|
||||
appPasskey = auth_token.auth["appPasskey"]
|
||||
)
|
||||
token_refreshed = await client_auth.refresh(
|
||||
http_client = self._http_client,
|
||||
force_refresh = False
|
||||
)
|
||||
client = SafaricomMPesaExpress(
|
||||
auth = MPesaExpressAuthorization(
|
||||
consumerKey = auth_token.auth["consumerKey"],
|
||||
consumerSecret = auth_token.auth["consumerSecret"],
|
||||
businessShortCode = auth_token.auth["businessShortCode"],
|
||||
appPasskey = auth_token.auth["appPasskey"]
|
||||
),
|
||||
auth = client_auth,
|
||||
http_client = self._http_client
|
||||
)
|
||||
|
||||
# if token_refreshed:
|
||||
# auth_token.token = client_auth.model_dump()
|
||||
# await self.set_token(
|
||||
# sql_conn = sql_conn,
|
||||
# mongo_data_conn = mongo_data_conn,
|
||||
# token_key = auth_token.key,
|
||||
# auth_token = auth_token
|
||||
# )
|
||||
|
||||
# Make the payment request:
|
||||
client_response = await client.request_payment(
|
||||
amount = payment_request.amount,
|
||||
@@ -224,6 +238,7 @@ class SafaricomMPesaExpressPaymentsController(PaymentsController):
|
||||
) if isinstance(payment_request.payerNo, str) else payment_request.payerNo,
|
||||
party_b = auth_token.auth["businessShortCode"]
|
||||
)
|
||||
print(client_response.to_markdown())
|
||||
|
||||
# Add this event to the payment's document:
|
||||
event_note_success = await self.add_event_by_payment_id(
|
||||
|
||||
Reference in New Issue
Block a user