pesa-cli 1.0.1__tar.gz → 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pesa-cli
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Command-line tool for M-Pesa Daraja v3 — STK Push, B2C, balance, config management.
5
5
  Author-email: Gabriel Mahia <contact@aikungfu.dev>
6
6
  License: CC-BY-NC-ND-4.0
@@ -183,3 +183,7 @@ if scripting against pesa-cli output is needed.
183
183
 
184
184
  *Part of the [nairobi-stack](https://github.com/gabrielmahia/nairobi-stack) East Africa engineering ecosystem.*
185
185
  *Maintained by [Gabriel Mahia](https://github.com/gabrielmahia). Kenya × USA.*
186
+
187
+ ## Getting sandbox credentials
188
+
189
+ New to Daraja, or on a new machine? Follow [the sandbox setup guide](https://github.com/gabrielmahia/mpesa-python/blob/main/docs/SANDBOX_SETUP.md): it creates a free sandbox app and runs OAuth, an STK Push and a status query, with exact portal labels. Set `DARAJA_CALLBACK_URL` to a public HTTPS address you can watch (for example a webhook.site URL); without it the CLI uses a placeholder and tells you so.
@@ -156,3 +156,7 @@ if scripting against pesa-cli output is needed.
156
156
 
157
157
  *Part of the [nairobi-stack](https://github.com/gabrielmahia/nairobi-stack) East Africa engineering ecosystem.*
158
158
  *Maintained by [Gabriel Mahia](https://github.com/gabrielmahia). Kenya × USA.*
159
+
160
+ ## Getting sandbox credentials
161
+
162
+ New to Daraja, or on a new machine? Follow [the sandbox setup guide](https://github.com/gabrielmahia/mpesa-python/blob/main/docs/SANDBOX_SETUP.md): it creates a free sandbox app and runs OAuth, an STK Push and a status query, with exact portal labels. Set `DARAJA_CALLBACK_URL` to a public HTTPS address you can watch (for example a webhook.site URL); without it the CLI uses a placeholder and tells you so.
@@ -240,7 +240,8 @@ def stk_push(
240
240
  consumer_secret = require_credential("consumer_secret", "Consumer Secret")
241
241
  shortcode = require_credential("shortcode", "Shortcode")
242
242
  passkey = require_credential("passkey", "Passkey")
243
- callback_url = get_credential("callback_url") or "https://example.com/mpesa/callback"
243
+ callback_given = get_credential("callback_url")
244
+ callback_url = callback_given or "https://example.com/mpesa/callback"
244
245
  ref = ref[:12] # Daraja hard limit
245
246
 
246
247
  timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
@@ -268,6 +269,11 @@ def stk_push(
268
269
 
269
270
  if response.get("ResponseCode") == "0":
270
271
  checkout_id = response.get("CheckoutRequestID", "")
272
+ # Without a callback URL Safaricom posts the result to a placeholder you cannot see; say so instead of failing silently.
273
+ notice = "" if callback_given else (
274
+ "\n\n[yellow]No callback URL set (DARAJA_CALLBACK_URL). Safaricom will post the result to "
275
+ f"{callback_url}, which you cannot see. Use 'pesa stk query' to check the outcome.[/yellow]"
276
+ )
271
277
  rprint(Panel(
272
278
  f"[green]✓ STK Push sent[/green]\n"
273
279
  f"Phone: [cyan]+{phone}[/cyan]\n"
@@ -275,7 +281,7 @@ def stk_push(
275
281
  f"Reference: [cyan]{ref}[/cyan]\n"
276
282
  f"Checkout ID: [dim]{checkout_id}[/dim]\n\n"
277
283
  f"[dim]The customer will receive a PIN prompt on their phone.[/dim]\n"
278
- f"[dim]Run: pesa stk query {checkout_id}[/dim]",
284
+ f"[dim]Run: pesa stk query {checkout_id}[/dim]{notice}",
279
285
  title="STK Push", border_style="green",
280
286
  ))
281
287
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pesa-cli
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Command-line tool for M-Pesa Daraja v3 — STK Push, B2C, balance, config management.
5
5
  Author-email: Gabriel Mahia <contact@aikungfu.dev>
6
6
  License: CC-BY-NC-ND-4.0
@@ -183,3 +183,7 @@ if scripting against pesa-cli output is needed.
183
183
 
184
184
  *Part of the [nairobi-stack](https://github.com/gabrielmahia/nairobi-stack) East Africa engineering ecosystem.*
185
185
  *Maintained by [Gabriel Mahia](https://github.com/gabrielmahia). Kenya × USA.*
186
+
187
+ ## Getting sandbox credentials
188
+
189
+ New to Daraja, or on a new machine? Follow [the sandbox setup guide](https://github.com/gabrielmahia/mpesa-python/blob/main/docs/SANDBOX_SETUP.md): it creates a free sandbox app and runs OAuth, an STK Push and a status query, with exact portal labels. Set `DARAJA_CALLBACK_URL` to a public HTTPS address you can watch (for example a webhook.site URL); without it the CLI uses a placeholder and tells you so.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pesa-cli"
7
- version = "1.0.1"
7
+ version = "1.0.2"
8
8
  description = "Command-line tool for M-Pesa Daraja v3 — STK Push, B2C, balance, config management."
9
9
  readme = "README.md"
10
10
  license = {text = "CC-BY-NC-ND-4.0"}
@@ -112,3 +112,17 @@ def test_invalid_phone_is_rejected():
112
112
 
113
113
  with pytest.raises(typer.Exit):
114
114
  importlib.import_module("pesa_cli.cli")._normalise_phone("12345")
115
+
116
+
117
+ def test_a_missing_callback_url_is_announced_not_silent(mock, env):
118
+ """Without DARAJA_CALLBACK_URL the CLI substitutes https://example.com/mpesa/callback, so the user never sees the result and had no hint why."""
119
+ r = runner.invoke(_app(), ["stk", "push", "0712345678", "10", "--ref", "NOCB"], env=env)
120
+ assert r.exit_code == 0 and "No callback URL" in r.output
121
+ body = _posts(mock, "/mpesa/stkpush/v1/processrequest")[-1]["body"]
122
+ assert body["CallBackURL"] == "https://example.com/mpesa/callback"
123
+
124
+
125
+ def test_a_configured_callback_url_is_used_and_not_warned_about(mock, env):
126
+ r = runner.invoke(_app(), ["stk", "push", "0712345678", "10", "--ref", "WITHCB"], env={**env, "DARAJA_CALLBACK_URL": "https://webhook.site/abc"})
127
+ assert r.exit_code == 0 and "No callback URL" not in r.output
128
+ assert _posts(mock, "/mpesa/stkpush/v1/processrequest")[-1]["body"]["CallBackURL"] == "https://webhook.site/abc"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes